X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstreamlistensocket.cpp;h=681adeddb8ab95957b5eab200b718f8f3298e9a3;hb=5d91f9edad6e8a11e21979a6aacb4ec6f2dc63ce;hp=2a8bc3d216e89c85a4a69e1dd17017601c7e4ee7;hpb=3970ee9cf7978c462390d49e083deb740d71c6fe;p=libs%2Fnet.git diff --git a/source/streamlistensocket.cpp b/source/streamlistensocket.cpp index 2a8bc3d..681aded 100644 --- a/source/streamlistensocket.cpp +++ b/source/streamlistensocket.cpp @@ -1,16 +1,15 @@ -/* $Id$ - -This file is part of libmspnet -Copyright © 2008 Mikkosoft Productions, Mikko Rasa -Distributed under the LGPL -*/ - #include #include -#include +#include +#include +#include +#include "sockaddr_private.h" +#include "socket_private.h" #include "streamlistensocket.h" #include "streamsocket.h" +using namespace std; + namespace Msp { namespace Net { @@ -21,36 +20,37 @@ StreamListenSocket::StreamListenSocket(Family af, int proto): 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(priv->handle, backlog); if(err==-1) - throw SystemError("Unable to listen", errno); + throw system_error("listen"); #ifdef WIN32 - WSAEventSelect(handle, event, FD_ACCEPT); + WSAEventSelect(priv->handle, *priv->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::SysAddr sa; + Private new_p; + new_p.handle = ::accept(priv->handle, reinterpret_cast(&sa.addr), &sa.size); - RefPtr paddr=SockAddr::create(sa); - return new StreamSocket(new_h, *paddr); + RefPtr paddr = SockAddr::from_sys(sa); + return new StreamSocket(new_p, *paddr); } } // namespace Net