6/22 I have a select() and read() question. I'm using select() in order to
figure out whether or not a given socket fd has anything to read within
the timeout. If the socket doesn't have anything to read, then I close
the connection, as I'm trying to prevent a dos connection attack.
Now my problem is this: if select() returns a given socket fd I try to
read from it, read() will block if there are less than the specified
number of bytes available on the socket, which is bad because someone
can still do a connection based dos. What's the standard way of dealing
with this problem? Threads? Alarm timers?
\_ the solution is to make the fd O_NONBLOCK using ioctl() after you
open the fd. subsequent reads will not block if there isn't
enough data. instead, they read as much as is available and
return it. -ali
\_ Thanks. I'll try it out. |