#ifndef WIN32
#include <sys/socket.h>
#endif
-#include <errno.h>
+#include <cerrno>
#include <msp/io/poll.h>
#include <msp/strings/formatter.h>
#include "streamsocket.h"
namespace Msp {
namespace Net {
+/**
+Used by StreamListenSocket to construct a new socket from accept.
+*/
+StreamSocket::StreamSocket(SocketHandle h, const SockAddr &paddr):
+ Socket(h, paddr),
+ connecting(false)
+{
+#ifdef WIN32
+ WSAEventSelect(handle, event, FD_READ|FD_CLOSE);
+#endif
+ set_events(IO::P_INPUT);
+}
+
/**
Constructs a new StreamSocket.
*/
#ifdef WIN32
throw Exception(format("Connection polling failed: %d", WSAGetLastError()));
#else
- throw Exception(format("Connection polling failed: %s", strerror(errno)));
+ throw SystemError("Connection polling failed", errno);
#endif
else if(res>0)
{
#ifdef WIN32
throw Exception(format("Connection failed: %d", err));
#else
- throw Exception(format("Connection failed: %s", strerror(err)));
+ throw SystemError("Connection failed", err);
#endif
}
set_events(IO::P_OUTPUT);
}
else
- throw Exception(format("Unable to connect: %s", strerror(errno)));
+ throw SystemError("Unable to connect", errno);
}
#endif
return (err==0)?0:1;
}
-/**
-Used by StreamListenSocket to construct a new socket from accept.
-*/
-StreamSocket::StreamSocket(SocketHandle h, const SockAddr &paddr):
- Socket(h, paddr),
- connecting(false)
-{
-#ifdef WIN32
- WSAEventSelect(handle, event, FD_READ|FD_CLOSE);
-#endif
- set_events(IO::P_INPUT);
-}
-
void StreamSocket::on_event(IO::PollEvent ev)
{
//cout<<"StreamSocket::on_event "<<ev<<'\n';