<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I have tried this code to have non blocking io on
sockets (this is an echo server):</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>procMsg()<BR>{<BR> char
buf[64];<BR> char *cbuf;<BR> unsigned r;<BR>
struct timeval tv;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> fd_set active_fd_set,
read_fd_set;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if (fcntl(fd, F_SETFL, O_NONBLOCK)
< 0) { /* set nonblockin mode */<BR>
perror("fcntl F_SETFL, O_NONBLOCK");<BR>
exit(1);<BR> }<BR> /* Initialize the set of active
sockets. */<BR> FD_ZERO (&active_fd_set); /*
*/<BR> FD_SET (fd, &active_fd_set); </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> cbuf=buf; r = 0;<BR> do
{ /* Reading loop */<BR> read_fd_set =
active_fd_set;<BR> tv.tv_sec =
0;<BR> tv.tv_usec =
100000;<BR> r = select(fd+1, &read_fd_set,
NULL, NULL, &tv); /* Wait 100ms for activity
*/<BR> if (r &&
FD_ISSET(fd,&read_fd_set)) { /* if socket is readable
*/<BR> cbuf++;
<BR> if ( (r = read(fd,cbuf,1))
<= 0) { /* read 1 byte
*/<BR>
break;<BR>
}<BR> } else {
<BR> break; /* Break if no more
bytes */<BR> };<BR> } while
(1);<BR> write(fd,buf,r); /* return message to client
*/<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>If I understand how select works, select should
return 0 if client does not send any byte after 100ms (it woks that way in
linux)., but rtems select doen't.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>In the other hand the line:</FONT></DIV>
<DIV><FONT face=Arial size=2>fcntl(fd, F_SETFL, O_NONBLOCK) </FONT></DIV>
<DIV><FONT face=Arial size=2>should make socket nonblocking, but I am still
having a blocking IO!</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Some ideas?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Camilo Alejandro Arboleda.</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV></BODY></HTML>