X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fstreamsocket.cpp;h=b06cf69ca9314cb6c750c1147513f9b4dc9c3a0a;hp=3fa6b9a13daafda29f3cd47f8ee1ef7d01cc3953;hb=6489612c788dd57721fc181ff26a981b35668d1e;hpb=e6f09239fae7ff675e1068365a06803dcc8f8d1f diff --git a/source/streamsocket.cpp b/source/streamsocket.cpp index 3fa6b9a..b06cf69 100644 --- a/source/streamsocket.cpp +++ b/source/streamsocket.cpp @@ -26,47 +26,6 @@ StreamSocket::StreamSocket(Family af, int proto): ClientSocket(af, SOCK_STREAM, proto) { } -bool StreamSocket::poll_connect(const Time::TimeDelta &timeout) -{ - if(!connecting) - throw bad_socket_state("not connecting"); - - int res = poll(*this, IO::P_OUTPUT, timeout); - if(res==-1) -#ifdef WIN32 - throw system_error("poll", WSAGetLastError()); -#else - throw system_error("poll"); -#endif - else if(res>0) - { - connecting = false; - - int err; - socklen_t len = sizeof(int); - get_option(SOL_SOCKET, SO_ERROR, &err, &len); - - if(err!=0) - { - set_events(IO::P_NONE); -#ifdef WIN32 - throw system_error("connect", WSAGetLastError()); -#else - throw system_error("connect"); -#endif - } - -#ifdef WIN32 - WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); -#endif - set_events(IO::P_INPUT); - - connected = true; - } - - return connected; -} - bool StreamSocket::connect(const SockAddr &addr) { if(connected) @@ -120,6 +79,47 @@ bool StreamSocket::connect(const SockAddr &addr) return connected; } +bool StreamSocket::poll_connect(const Time::TimeDelta &timeout) +{ + if(!connecting) + throw bad_socket_state("not connecting"); + + int res = poll(*this, IO::P_OUTPUT, timeout); + if(res==-1) +#ifdef WIN32 + throw system_error("poll", WSAGetLastError()); +#else + throw system_error("poll"); +#endif + else if(res>0) + { + connecting = false; + + int err; + socklen_t len = sizeof(int); + get_option(SOL_SOCKET, SO_ERROR, &err, &len); + + if(err!=0) + { + set_events(IO::P_NONE); +#ifdef WIN32 + throw system_error("connect", WSAGetLastError()); +#else + throw system_error("connect"); +#endif + } + +#ifdef WIN32 + WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); +#endif + set_events(IO::P_INPUT); + + connected = true; + } + + return connected; +} + void StreamSocket::on_event(IO::PollEvent ev) { if((ev&(IO::P_OUTPUT|IO::P_ERROR)) && connecting)