#include <sys/socket.h>
#endif
#include <cerrno>
+#include <msp/core/systemerror.h>
#include <msp/io/poll.h>
#include <msp/strings/format.h>
#include "streamsocket.h"
{
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)
{
{
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
}
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);
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<sockaddr *>(&sa), size);
set_events(IO::P_OUTPUT);
}
else
- throw SystemError("Unable to connect", errno);
+ throw system_error("connect");
}
#endif