c - Avoid send to block when not using O_NONBLOCK -


i have write chat client-server class using unix sockets (without o_nonblock) , select asynchronous i/o on them. @ moment, on server, read 1024 bytes client, , directly handle it.

for example, in case of message, receive command formatted msg <msg> (representing client sending message), go through sockets of connected clients , write message on them.

this approach works found reading man of send can blocks if socket buffer full , flag o_nonblock not set on socket.

i think problem happen when client not read reasons (crash, bugged etc.) , critical server since blocks until client read again.

so here question:

what correct approach on potentially blocking socket avoid send block if socket buffer full?

i'm using select check if there read on sockets maybe should use see if can write on particular socket too? , also, can know how many bytes can read/write when select returns? example, if select "tells" can write on socket, how can know how many bytes can write @ before writing on socket becomes blocking?

thanks.

you use setsockopt() so_sndtimeo set maximum amount of time send() try work.

see man setsockoptand man 7 socket details.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -