Set FIONBIO flag for sockets

Make m_FD member variable private.
This commit is contained in:
Gunnar Beutner 2012-03-29 13:15:54 +02:00
parent c7f8ec38fd
commit 89ddfdd7e7
5 changed files with 17 additions and 4 deletions

View File

@ -30,6 +30,11 @@ void Socket::Stop(void)
void Socket::SetFD(SOCKET fd)
{
unsigned long lTrue = 1;
if (fd != INVALID_SOCKET)
ioctlsocket(fd, FIONBIO, &lTrue);
m_FD = fd;
}

View File

@ -5,9 +5,10 @@ namespace icinga {
class Socket : public Object
{
protected:
private:
SOCKET m_FD;
protected:
Socket(void);
void Close(bool from_dtor);

View File

@ -27,7 +27,7 @@ void TCPServer::Start(void)
void TCPServer::Listen(void)
{
listen(m_FD, SOMAXCONN);
listen(GetFD(), SOMAXCONN);
Start();
}

View File

@ -4,9 +4,14 @@ using namespace icinga;
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)

View File

@ -22,4 +22,6 @@ inline void closesocket(int fd)
close(fd);
}
#define ioctlsocket ioctl
#endif /* I2_UNIX_H */