closing sockets on linux and windows

Posted by robUK on Stack Overflow See other posts from Stack Overflow or by robUK
Published on 2010-05-24T15:59:46Z Indexed on 2010/05/24 16:11 UTC
Read the original article Hit count: 156

Filed under:
|

Hello,

gcc 4.4.4 c89
Visual Studio VC++ 2008

I am writing a cross platform client server application. It will run on both linux and windows.

However, I am just wondering what I have done for closing the sockets is correct. I close the file descriptor. However, if there is a problem with closing it. What is the best way to handle this. Maybe some data is still being sent or received?

Many thanks for any advice,

    if(close(sockfd) == -1)
    {
#if defined ( _WIN32 )
        fprintf(stderr, "[ %d ] [ %s ] [ %s ] [ %d ]\n",
            WSAGetLastError(), strerror(errno), __func__, __LINE__);
#elif( __linux__ )
    fprintf(stderr, "[ %s ] [ %s ] [ %d ]\n", strerror(errno), __func__, __LINE__);
#endif  
    return CS_FAILURE;
    }

© Stack Overflow or respective owner

Related posts about c

    Related posts about sockets