Checking whether a listensocket has a pending conn
I am currently writing a single-threaded network application that uses ioctlsocket(sock, FIONREAD, etc) to check whether I should call recv(). I tried using it to check whether to call accept(), but it still reports 0 even when attempts at connection are made. If I leave out the call to ioctlsocket the app works properly, except it blocks on accept(). (I'm at the beginning of a 48-hour game-coding competition, forums are allowed but only 3rd party code and what is written on the days can be used) Is there any way to check whether my listensocket has a pending connection without blocking? Thanks for all assistance.
Hi.
Try this out:
SOCKET sock;
ioctlsocket(sock, FIONBIO, 1);
That should place your socket in a non-blocking mode. You can check the return values from the function if it returns anything other than 0 with WSAGetLastError();
Hope it helps.
Try this out:
SOCKET sock;
ioctlsocket(sock, FIONBIO, 1);
That should place your socket in a non-blocking mode. You can check the return values from the function if it returns anything other than 0 with WSAGetLastError();
Hope it helps.
Well, R2D22U2..
Use select(), and pass a 0-time timeout. That will just poll whether anything's available. If you pass NULL (as opposed to a timeval with value 0) then select() will block.
enum Bool { True, False, FileNotFound };
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement