X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fstreamsocket.cpp;h=cd810d5253e14e2990d204c4af12096f5be7278b;hp=2576009452bddcb9df8ee22898c42ce612fcc171;hb=4696a776e2875697ea0d6a733609dd9c37918971;hpb=65b029e8334d4dfc9a6161fc04740b03d56a8e2f diff --git a/source/streamsocket.cpp b/source/streamsocket.cpp index 2576009..cd810d5 100644 --- a/source/streamsocket.cpp +++ b/source/streamsocket.cpp @@ -2,6 +2,7 @@ #include #endif #include +#include #include #include #include "streamsocket.h" @@ -28,14 +29,14 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout) { check_state(false); if(!connecting) - throw InvalidState("No connection attempt going on"); + throw bad_socket_state("not connecting"); int res = poll(*this, IO::P_OUTPUT, timeout); if(res==-1) #ifdef WIN32 - throw Exception(format("Connection polling failed: %d", WSAGetLastError())); + throw system_error("poll", WSAGetLastError()); #else - throw SystemError("Connection polling failed", errno); + throw system_error("poll"); #endif else if(res>0) { @@ -49,9 +50,9 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout) { set_events(IO::P_NONE); #ifdef WIN32 - throw Exception(format("Connection failed: %d", err)); + throw system_error("connect", WSAGetLastError()); #else - throw SystemError("Connection failed", err); + throw system_error("connect"); #endif } @@ -73,7 +74,7 @@ int StreamSocket::connect(const SockAddr &addr) check_state(false); if(connected) - throw InvalidState("Socket is already connected"); + throw bad_socket_state("already connected"); sockaddr_storage sa; socklen_t size = addr.fill_sockaddr(sa); @@ -90,7 +91,7 @@ int StreamSocket::connect(const SockAddr &addr) set_events(IO::P_OUTPUT); } else - throw Exception(format("Unable to connect: %d", err_code)); + throw system_error("connect", err_code); } #else int err = ::connect(handle, reinterpret_cast(&sa), size); @@ -102,7 +103,7 @@ int StreamSocket::connect(const SockAddr &addr) set_events(IO::P_OUTPUT); } else - throw SystemError("Unable to connect", errno); + throw system_error("connect"); } #endif