I made a server that uses select() to check witch of the socket descriptors have data in them, but apparently select marks a socket to be ready to read from even after the client disconnects, and I get garbage values.
I have found this post on stack overflow:
select (with the read mask set) will return with the handle signalled, but when you use ioctl* to check the number of bytes pending to be read, it will be zero. `
My question is what is ioctl* and how to use it? And an example would be very good.
If a call to
read()on a socket (file) descriptor returns0, that simply means the other side of the connection had shutdown and closed the connection.Note: A
select()waiting for possible “events” on set(s) of socket (file) descriptors will also return when a connection represented by one of thefd_set‘s passed toselect()had been shutdown.