Hi, does anybody know how check whether the socket (ie file descriptor) is valid in C? I know it is probably possible to do it using either a read or a write command, however, what other ways are there? Thanks.

Hi, does anybody know how check whether the socket (ie file descriptor) is valid in C? I know it is probably possible to do it using either a read or a write command, however, what other ways are there? Thanks.

Depends on the socket that you are using. If you are using the berkely sockets, they have (I think) -1 as the value for the invalid socket. Look up the documentation for this. The Winsock API uses the INVALID_SOCKET value to determine an invalid socket. (Look up the Winsock API Documentation)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.