non-blocking

How to read available input without blocking on Windows

Hello. On Linux, I can read available input without blocking the process: fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK ) char buf[n]; int r = fread(buf, 1, n, stdin); if (r == 0){ printf("nothing\n"); } else { printf("read: "); fwrite(buf, 1, r, stdout); printf("\n"); } The input origin ca...

Convert several Java methods to run as non-blocking threads?

Is it possible to convert a number of methods (defined in an interface and implemented in a class) to run as non-blocking threads? Certainly, i can wrap each single method in the run() method of a thread class. But perhaps there exists a more sophisticated way to warp several different methods in one step, i.e. by a single thread class...

how to do non blocking accept() in Python?

Hello I cannot use threads thus I want to write a server program that can be interrupted after a while: d = show_non_modal_dialog("serving clients") s = socket(...) s.bind(...) s.listen() while (!user_pressed_cancel()) { s.accept() # timed accept for like 1 second if timed_out: continue serve_client close_client_sock } hid...

IO#read blocks on non-blocking socket?

Ruby 1.8.7. I'm calling read on a socket which has been opened and connected with: socket = Socket.new(AF_INET, SOCK_STREAM, 0) sockaddr = Socket.sockaddr_in(mp.port, mp.ip_address.ip) begin socket.connect_nonblock(sockaddr) [...] The connection is confirmed by calling select() and then connecting a second time looking for Errno::E...

Ruby TCPSocket: Find out how much data is available

Is there a way to find out how many bytes of data is available on an TCPSocket in Ruby? I.e. how many bytes can be ready without blocking? ...