non-blocking writes to sockets

non-blocking writes to sockets

Post by Chandr » Fri, 18 Jul 1997 04:00:00

write will return how many bytes it has written to the socket.
Keep track of it.

Feel free to ask further.


non-blocking writes to sockets

Post by Andrew Giert » Sat, 19 Jul 1997 04:00:00

 Chialin> The problem that I have now is that with a stream socket
 Chialin> (SOCK_STREAM), if the client does not drain the socket fast
 Chialin> enough, a non-blocking write on the server side could just
 Chialin> write a portion of the message, return -1 and set errno to
 Chialin> EAGAIN.

No. This can't happen (barring serious kernel bugs).

A write() to a non-blocking socket can return:

  - the number of bytes successfully written, which may be less than
    the number requested

  - -1 with EAGAIN or EWOULDBLOCK, which indicates that *no* data has
    been written.


comp.unix.programmer FAQ: see <URL:>


1. Problem with non-blocking writing using sockets

I try to build up a program structure consisting of a couple of client
processes, which
communicate to each other using sockets. The communication is managed by
a server
process. The programs are written in C based on a LINUX-platform. (I
hope You UNIX
programmers are also able to give me a hint.)

My problem:
When sending a long message to another program (should be up to 1 MByte)
I first
check weather the connection line is able to receive data (SELECT).
Then the WRITE statement transmits the first portion to the socket
buffer and
waits until the target program reads the data from the buffer.
If the target program is busy that moment, the sending program is

so my question:
Is it possible to find out the size of the socket buffer (which differs
from one WRITE
to the other) and the remaining space in the buffer ?
(so I can write only the exact number of bytes without WRITE-blocking)

thanx a lot

2. Data searching problems

3. TCP Socket Non-Blocking write ?

4. Permission error

5. One more question please

6. Wanted: non-blocking socket write...


8. Does non-blocking (sockets) apply to write?

9. [2.5] Non-blocking write can block

10. Blocking and Non-Blocking socket

11. Non-blocking socket reads block! (Bug?)

12. Difference between blocking and non-blocking socket ?