Web: void AttachSocket(Socket& socket, SOCKET s, bool blocking)

git-svn-id: svn://ultimatepp.org/upp/trunk@1599 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-10-02 07:49:47 +00:00
parent d32a97b2d6
commit e211a2903e
2 changed files with 18 additions and 2 deletions

View file

@ -341,13 +341,18 @@ SOCKET Socket::Data::AcceptRaw(dword *ipaddr, int timeout_msec)
return connection;
}
void Socket::Data::Attach(SOCKET s, bool nodelay, bool blocking)
void Socket::Data::AttachRaw(SOCKET s, bool blocking)
{
CloseRaw(0);
socket = s;
is_blocking = blocking;
}
void Socket::Data::Attach(SOCKET s, bool nodelay, bool blocking)
{
AttachRaw(s, blocking);
if(nodelay)
NoDelay();
is_blocking = blocking;
if(!is_blocking)
Block(false);
}
@ -837,6 +842,13 @@ bool ClientSocket(Socket& socket, const char *host, int port, bool nodelay, dwor
return true;
}
void AttachSocket(Socket& socket, SOCKET s, bool blocking)
{
One<Socket::Data> data = new Socket::Data;
data->AttachRaw(s, blocking);
socket.Attach(data);
}
#ifdef PLATFORM_WIN32
void SocketEvent::Read(Socket& socket)

View file

@ -56,6 +56,9 @@ public:
SOCKET AcceptRaw(dword *ipaddr, int timeout_msec);
void Attach(SOCKET socket, bool nodelay, bool is_blocking);
void SetSockResError(String context);
void AttachRaw(SOCKET s, bool blocking);
friend void AttachSocket(Socket& socket, SOCKET hsocket, bool blocking);
};
Socket() {}
@ -150,3 +153,4 @@ public:
bool ServerSocket(Socket& socket, int port, bool nodelay = true, int listen_count = 5, bool is_blocking = true, bool reuse = true);
bool ClientSocket(Socket& socket, const char *host, int port, bool nodelay = true, dword *my_addr = NULL, int timeout = DEFAULT_CONNECT_TIMEOUT, bool is_blocking = true);
void AttachSocket(Socket& socket, SOCKET s, bool blocking);