Jump to content
  • Advertisement
Sign in to follow this  
dave

How To Validate a Winsock Socket?

This topic is 4731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, If a function was passed a SOCKET then how would it be possible to check that this socket is actually valid. When Socket() returns teh socket on creation you can check against an error code. But there is nothing stopping the programmer creating a socket of value 2 or something. The only technique for validating the socket i could think of woulf be to attempt to send a byte of data with send() and check the return code of this method. Assuming ofcourse that send() would return an error for a borked socket being passed in. Any ideas? ace

Share this post


Link to post
Share on other sites
Advertisement
If you try and use a socket number that isn't a socket, you will get an error of 10038 (WSAENOTSOCK).

I don't lose track of my sockets, so if a socket is closed, then I remove it from the list. I use select() to see if the sockets have any new status (recv'ing or disconnection). Maybe using select() on an invalid socket will also return WSAENOTSOCK.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!