Make m_FD member variable private.
void Socket::SetFD(SOCKET fd)
{
+ unsigned long lTrue = 1;
+
+ if (fd != INVALID_SOCKET)
+ ioctlsocket(fd, FIONBIO, &lTrue);
+
m_FD = fd;
}
class Socket : public Object
{
-protected:
+private:
SOCKET m_FD;
+protected:
Socket(void);
void Close(bool from_dtor);
void TCPServer::Listen(void)
{
- listen(m_FD, SOMAXCONN);
+ listen(GetFD(), SOMAXCONN);
Start();
}
void TCPSocket::MakeSocket(void)
{
- assert(m_FD == INVALID_SOCKET);
+ assert(GetFD() == INVALID_SOCKET);
- m_FD = socket(AF_INET, SOCK_STREAM, 0);
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (fd == INVALID_SOCKET)
+ throw exception(/*"socket() failed."*/);
+
+ SetFD(fd);
}
void TCPSocket::Bind(unsigned short port)
close(fd);
}
+#define ioctlsocket ioctl
+
#endif /* I2_UNIX_H */
\ No newline at end of file