Non-blocking socket still blocking!

Smith, Gene Gene.Smith at sea.siemens.com
Fri Sep 1 19:42:13 UTC 2000


I noticed that my read() on a supposedly non-blocking socket still blocked
after
I had read all data from the socket and called read() again.  I then checked

the socket flags more closely to make sure I was really setting it
non-blocking
(O_NONBLOCK is 0x4000) with the following code:

/* set new_sock non-blocking */
flags = 0;
flags = fcntl( new_sock, F_GETFL, 0);
DTRACE(("\nOrig flags = 0x%x", flags));
flags = flags | O_NONBLOCK;
DTRACE(("\nflags|O_NON_BLOCK=0x%x", flags));
if ( fcntl( new_sock, F_SETFL, flags ) < 0)
	RTEMS_PANIC(("\nCan't set new_sock non-blocking"));
DTRACE(("\nflags set to 0x%x", flags));

/* verify non-blocking flag set */
flags = 0;
flags = fcntl( new_sock, F_GETFL, 0);
if ( (flags & O_NONBLOCK) == 0 ) 
	DTRACE(("\nBad flags = 0x%x", flags));
else
	DTRACE(("\nGood flags = 0x%x", flags));

The following output trace indicates that my attempt to set the socket
non-blocking does not "stick."  (The value "new_sock" is the return value
from
accept().) Any ideas why the socket seems to remain blocking?             

Orig flags = 0x2
flags|O_NON_BLOCK=0x4002
flags set to 0x4002
Bad flags = 0x2

--Gene



More information about the users mailing list