PDA

View Full Version : send in non_block


emihaly
04-30-2003, 09:41 AM
hi, i want swich from block send to non_block send. Have somebody skill with this?


1. nonblock send all data buffer when send buffer is smaller? in other words, have management for it?

2. how i know all data was sent or was closed on other end?

3. i read some materials, nonblock send is little faster. Is this right?

shiva
05-05-2003, 01:27 PM
If you want to make the socket as non_blocking for read/write, just set the
sockopt as O_NONBLOCK in the setsockopts(fd,..,O_NONBLOCK..).

If the other end is broken /closed you'll get EPIPE error on sending to the
destination.

Just try this....

Shiva

andreto
05-05-2003, 07:32 PM
You can use the fcntl(2) call with the flags(cmd) F_GETFL and F_SETFL for this.

First get the current flags of the socket
flags = fnctl(socket, F_GETFL, 0)

then set these flags ORed with the O_NONBLOCK flag using fnctl(2)

fcntl(socket, F_SETFL, flags | O_NONBLOCK)

obviousley you shold also check the returnvalues for the calls.

Atleast thats the way I've always done it ;-)

Andreas