Thread: How to find out if a socket is closed or not

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    How to find out if a socket is closed or not

    How can i find out if a socket is closed/unused or if it needs to be closed?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Hmm... one way of doing it is to call setsockopt() on the socket. If you get the error EBADF, then you know the socket descriptor is no longer valid (ie it's been closed, or it was never opened in the first place).

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is select().

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  3. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 09:55 AM
  4. Socket class OOD
    By lord mazdak in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2005, 01:11 AM
  5. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 02:51 AM