nonblocking

Making a Nonblocking socket for WinSocks and *nix

In C/C++, how would I turn a blocking socket into a non blocking socket in both WinSocks and *nix; so that select() would work correctly. You can use the pre-processor for the platform specific code. ...

Polling the keyboard in python

How can I poll the keyboard from a console python app? Specifically, I would like to do something akin to this in the midst of a lot of other I/O activities (socket selects, serial port access, etc.): while 1: # doing amazing pythonic embedded stuff # ... # periodically do a non-blocking check to see if # we...

Cross-platform (linux/Win32) nonblocking C++ IO on stdin/stdout/stderr

I'm trying to find the best solution for nonblocking IO via stdin/stdout with the following characteristics: As long as there is enough data, read in n-sized chunks. If there's not enough data, read in a partial chunk. If there is no data available, block until there is some (even though it may be smaller than n). The goal is to allo...

Non-blocking read on a stream in python.

Hi, I'm using the subprocess module to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-bloking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Window...

C non-blocking keyboard input

I'm trying to write a program in C (on linux) that loops until the user presses a key, but shouldn't require a keypress to continue each loop. Is there a simple way to do this? I figure I could possibly do it with select() but that seems like a lot of work. Alternatively, is there a way to catch a control-c keypress to do cleanup befor...

Nonblocking algorithm to generate unique negative numbers

I recently refactored a piece of code used to generate unique negative numbers. edit: Multiple threads obtain these ids and add as keys to a DB; numbers need to be negative to be easily identifiable -at the end of a test session they're removed from the DB. My Java algorithm looks like this: private final Set<Integer> seen = Collec...

C nonblocking IO on Linux

How do you do nonblocking console IO on Linux/OS X in C? ...

If a nonblocking recv with MSG_PEEK succeeds, will a subsequent recv without MSG_PEEK also succeed?

Here's a simplified version of some code I'm working on: void stuff(int fd) { int ret1, ret2; char buffer[32]; ret1 = recv(fd, buffer, 32, MSG_PEEK | MSG_DONTWAIT); /* Error handling -- and EAGAIN handling -- would go here. Bail if necessary. Otherwise, keep going. */ /* Can this call to recv fail, setti...

Non-blocking connect() with WinSocks

According to MSDN you have to create a non-blocking socket like this: unsigned nonblocking = 1; ioctlsocket(s, FIONBIO, and use it in the write-fdset for select() after that. To check if the connection was successful, you have to see if the socket is writeable. However, the MSDN-article does not describe how to check for errors. How ...

Is there a simple method for checking whether a Ruby IO instance will block on read()?

I'm looking for a method in Ruby which is basically this: io.ready_for_read? I just want to check whether a given IO object (in my case, the result of a popen call) has output available, i.e. a follow up call io.read(1) will not block. These are the two options I see, neither of which I like: io.read_nonblock - too thin an abstract...

Detect key press (non-blocking) w/o getc/gets in Ruby

I have a simple task that needs to wait for something to change on the filesystem (it's essentially a compiler for prototypes). So I've a simple infinite loop with a 5 second sleep after the check for changed files. loop do # if files changed # process files # and puts result sleep 5 end Instead of the Ctrl+C salute, I'd ...

Is the select() wrapper in IO::Select thread-safe? How to work around?

Let's say I have a thread: sub new { my $class = shift; my $self = ref $class || $class; bless { 'read_set' => IO::Select->new, 'write_set' => IO::Select->new, 'error_set' => IO::Select->new }, $self; } sub start { my $self = shift; $self...

Simplest way to do a fire and forget method in C#?

I saw in WCF they have the [OperationContract(IsOneWay = true)] attribute. But WCF seems kind of slow and heavy just to do create a nonblocking function. Ideally there would be something like static void nonblocking MethodFoo(){}, but I don't think that exists. What is the quickest way to create a nonblocking method call in c#? E.g....

Java Linux Nonblocking Socket Timeout Behavior

I have a Java nonblocking server that keeps track of all the socket channels in a selector. I then establish 500 connections to the server and send data regularly. Every piece of data the server receives is echoed back to the client. The problem comes where the test works wonderfully for a couple of hours and then all of the sudden gra...

Is there a Push-based/Non-blocking XML Parser for Java?

I'm looking for an XML parser that instead of parsing from an InputStream or InputSource will instead allow blocks of text to be pushed into the parser. E.g. I would like to have something like the following: public class DataReceiver { private SAXParser parser = //... private DefaultHandler handler = //... /** * Calle...

Speeding up non-blocking Unix Sockets (C++)

I've implemented a simple socket wrapper class. It includes a non-blocking function: void Socket::set_non_blocking(const bool b) { mNonBlocking = b; // class member for reference elsewhere int opts = fcntl(m_sock, F_GETFL); if(opts < 0) return; if(b) opts |= O_NONBLOCK; else opts &= ~O_NONBLOCK; ...

Problem with non blocking fifo in bash

Hi! I'm running a few Team Fortress 2 servers and I want to write a little management script. Basically the TF2 servers are a fg process which provides a server console, so I can start the server, type status and get an answer from it: ***@purple:~/tf2$ ./start_server_testing Auto detecting CPU Using AMD Optimised binary. Server will ...

Are nonblocking I/O operations in Perl limited to one thread? Good design?

I am attempting to develop a service that contains numerous client and server sockets (a server service as well as clients that connect out to managed components and persist) that are synchronously polled through IO::Select. The idea was to handle the I/O and/or request processing needs that arise through pools of worker threads. The sh...

Simple thread-safe non-blocking file logger class in c#

I have a web application, that will log some information to a file. I am looking for a simple thread-safe non-blocking file logger class in c#. I have little experience with threading. I known there are great logging components out there like log4Net, Enterprise Library Logging Block, ELMAH, but I do not want an external dependence for m...

What is the difference between lockless and non-blocking?

Hi, In the context of data-structures synchronization, can someone clarify the difference between "lockless" and "non-blocking"? These terms seem to be used interchangeably by a lot of people but I'm not yet sure if there isn't some subtle difference hidden somewhere. I mean lockless is "without locks" and non-blocking is more like gua...