-/* $Id$
-
-This file is part of libmspnet
-Copyright © 2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the LGPL
-*/
-
-#include <errno.h>
+#include <cerrno>
#include <msp/core/refptr.h>
-#include <msp/strings/formatter.h>
+#include <msp/core/systemerror.h>
+#include <msp/strings/format.h>
#include "streamlistensocket.h"
#include "streamsocket.h"
+using namespace std;
+
namespace Msp {
namespace Net {
int StreamListenSocket::connect(const SockAddr &)
{
- throw Exception("Can't connect a listen socket");
+ // XXX This function needs to go away
+ throw logic_error("Can't connect a listen socket");
}
void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
{
bind(addr);
- int err=::listen(handle, backlog);
+ int err = ::listen(handle, backlog);
if(err==-1)
- throw Exception(format("Unable to listen: %s", strerror(errno)));
+ throw system_error("listen");
#ifdef WIN32
WSAEventSelect(handle, event, FD_ACCEPT);
#endif
set_events(IO::P_INPUT);
- listening=true;
+ listening = true;
}
StreamSocket *StreamListenSocket::accept()
{
if(!listening)
- throw InvalidState("Socket is not listening");
+ throw bad_socket_state("not listening");
- sockaddr sa;
- socklen_t size=sizeof(sockaddr);
- SocketHandle new_h=::accept(handle, &sa, &size);
+ sockaddr_storage sa;
+ socklen_t size = sizeof(sockaddr_storage);
+ SocketHandle new_h = ::accept(handle, reinterpret_cast<sockaddr *>(&sa), &size);
- RefPtr<SockAddr> paddr=SockAddr::create(sa);
+ RefPtr<SockAddr> paddr = SockAddr::create(sa);
return new StreamSocket(new_h, *paddr);
}