Questions tagged [nonblocking]

Non-blocking mode I/O either transfers at least one byte or returns immediately with an error or end of stream. Non-blocking algorithms refer to use of concurrency without the usual mutual exclusion primitives, guaranteeing that thread operations will not block indefinitely. This is usually handled with atomic value modification (increment/decrement) and/or reading (compare-and-exchange) operations.. It isn't clear which this tag is intended for.

1597 questions
12
votes
5 answers

How to check if stdin is still opened without blocking?

I need my program written in pure C to stop execution when stdin is closed. There is indefinite work done in program main cycle, and there is no way I can use blocking checks (like getc()) there (no data is supposed to arrive on stdin - it just…
Basilevs
  • 22,440
  • 15
  • 57
  • 102
12
votes
2 answers

Ruby readpartial and read_nonblock not throwing EOFError

I'm trying to understand and recreate a simple preforking server along the lines of unicorn where the server on start forks 4 processes which all wait (to accept) on the controlling socket. The controlling socket @control_socket binds to 9799 and…
Sid
  • 6,134
  • 9
  • 34
  • 57
11
votes
3 answers

Implementing a multiple producer/consumer lockless queue in C\C++

I have finished my basic implementation on a single producer/consumer on a lockless queue and it runs nicely. However, when I try to expand it to a multiple producer/consumer I start to get conflicts. I found through SO a similar post related to…
Seb
  • 3,414
  • 10
  • 73
  • 106
11
votes
6 answers

What happens when a single request takes a long time with these non-blocking I/O servers?

With Node.js, or eventlet or any other non-blocking server, what happens when a given request takes long, does it then block all other requests? Example, a request comes in, and takes 200ms to compute, this will block other requests since e.g.…
codecompleting
  • 9,251
  • 13
  • 61
  • 102
11
votes
3 answers

Python: Non-blocking socket or Asynchronos I/O

I am new to Python and currently have to write a python socket to be run as a script that communicates with a device over TCP/IP (a weather station). The device acts as the Server Side (listening over IP:PORT, accepting connection, receiving…
Tu Hoang
  • 4,622
  • 13
  • 35
  • 48
11
votes
3 answers

In Win32, is there a way to test if a socket is non-blocking?

In Win32, is there a way to test if a socket is non-blocking? Under POSIX systems, I'd do something like the following: int is_non_blocking(int sock_fd) { flags = fcntl(sock_fd, F_GETFL, 0); return flags & O_NONBLOCK; } However, Windows…
Daniel Stutzbach
  • 74,198
  • 17
  • 88
  • 77
11
votes
5 answers

Do i need Node.js in Python like I would with PHP?

I have been using PHP for some time now. And I have been thinking about learning Node.js to go along with it to use the non blocking idea for creating an online game or app. There is quite a bit of info on using the two together. Using Node as part…
skift
  • 1,027
  • 2
  • 16
  • 27
11
votes
1 answer

How non-blocking API works?

I've been reading Play Framework documentation and found this quote confusing: Note that you may be tempted to therefore wrap your blocking code in Futures. This does not make it non-blocking, it just means the blocking will happen in a…
silent-box
  • 1,649
  • 3
  • 21
  • 40
11
votes
4 answers

CompletableFuture.exceptionally with executor

CompletableFuture.exceptionally() method takes a lambda, but there is no flavor of the method that takes a custom Executor, or even an "...Async" flavor of it. Which executor does exceptionally lambda run on? Would it be the same executor which ran…
vishr
  • 985
  • 10
  • 28
11
votes
1 answer

Jersey webservice scalable approach to download file and reply to client

I need to build a webservice with Jersey that downloads a big file from another service and returns to the client. I would like jersey to read some bytes into a buffer and write those bytes to client socket. I would like it to use non blocking I/O…
fredcrs
  • 3,558
  • 7
  • 33
  • 55
11
votes
1 answer

Why cpu bound is better with blocking I/O and I/O bound is better with non blocking I/O

I have been told that for I/O bound applications, non blocking I/O would be better. For CPU bound applications, blocking I/O is much better. I could not find the reason for such a statement. Tried google, but few articles just touches the topic with…
piyushGoyal
  • 1,079
  • 1
  • 11
  • 26
11
votes
4 answers

Why does NodeJS NOT use Promise for the readFile API?

In the book https://pragprog.com/book/tbajs/async-javascript, I found this: Node’s early iterations used Promises in its nonblocking API. However, in February 2010, Ryan Dahl made the decision to switch to the now-familiar callback(err,…
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
11
votes
3 answers

recv with MSG_NONBLOCK and MSG_WAITALL

I want to use recv syscall with nonblocking flags MSG_NONBLOCK. But with this flag syscall can return before full request is satisfied. So, can I add MSG_WAITALL flag? Will it be nonblocking? or how should I rewrite blocking recv into the loop…
osgx
  • 90,338
  • 53
  • 357
  • 513
11
votes
3 answers

non-blocking udp socket programming in C: what do I get?

I have a problem in understanding what recv()/recvfrom() return from an non-blockig UDP socket. A bit more specific and compared to TCP (please correct me if I'm wrong): A blocking socket (either TCP or UDP) won't return from a recv() until there…
Uwe
  • 113
  • 1
  • 1
  • 5
11
votes
2 answers

java Non-blocking HTTP client

I have a high volume java application in which I have to send http posts to another server. Currently I'm using org.apache.commons.httpclient library: private static void sendData(String data) { HttpClient httpclient = new…
forhas
  • 11,551
  • 21
  • 77
  • 111