Advertisement

Winsock and custom wrapper class.

Started by April 17, 2002 02:10 PM
1 comment, last by ANSI2000 22 years, 9 months ago
Lets say I have a class which wraps the Winsock API...

class cSocket
{
private:
   SOCKET sock;
public:
   // A few methods here...

   void closeSocket()
   {
      shutdown(sock);
      closesocket(sock);
   }
};
 
Now in my app some where...

cSocket sock1;
cSocket sock2;

// Initialize sock1 here and connect

sock2 = sock1; // <-- Make a copy...

// Do stuff here...

sock2.closeSocket();
 
Will sock2.closeSocket close the socket and free the resources correctly?
Yes....but, remember that sock2 and sock1 are using the same socket/file descriptor, so if you copy sock1 to sock2, and then closesocket() on sock2, it will also invalidate sock1''s socket....I think that may have been what you were getting at anyway.
Advertisement
Thats what I wanted to know

This topic is closed to new replies.

Advertisement