Advertisement

Checking whether a listensocket has a pending conn

Started by June 18, 2004 11:48 AM
2 comments, last by zyron 20 years, 8 months ago
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.
Well, R2D22U2..
Advertisement
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 };
Hi Krylloan

http://www.gamedev.net/reference/articles/article1494.asp

check it out.. it explains how to make an non-blocking server.

This topic is closed to new replies.

Advertisement