From e211a2903e7648d75af7e7c5e488fec5f04ba52b Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 2 Oct 2009 07:49:47 +0000 Subject: [PATCH] Web: void AttachSocket(Socket& socket, SOCKET s, bool blocking) git-svn-id: svn://ultimatepp.org/upp/trunk@1599 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Web/socket.cpp | 16 ++++++++++++++-- uppsrc/Web/socket.h | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/uppsrc/Web/socket.cpp b/uppsrc/Web/socket.cpp index 12b74221e..f203e011f 100644 --- a/uppsrc/Web/socket.cpp +++ b/uppsrc/Web/socket.cpp @@ -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 data = new Socket::Data; + data->AttachRaw(s, blocking); + socket.Attach(data); +} + #ifdef PLATFORM_WIN32 void SocketEvent::Read(Socket& socket) diff --git a/uppsrc/Web/socket.h b/uppsrc/Web/socket.h index 1aceecbcf..334b8dc62 100644 --- a/uppsrc/Web/socket.h +++ b/uppsrc/Web/socket.h @@ -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);