3 This file is part of libmspnet
4 Copyright © 2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
9 #include <msp/core/refptr.h>
10 #include <msp/strings/formatter.h>
11 #include "streamlistensocket.h"
12 #include "streamsocket.h"
17 StreamListenSocket::StreamListenSocket(Family af, int proto):
18 Socket(af, SOCK_STREAM, proto),
22 int StreamListenSocket::connect(const SockAddr &)
24 throw Exception("Can't connect a listen socket");
27 void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
31 int err=::listen(handle, backlog);
33 throw SystemError("Unable to listen", errno);
36 WSAEventSelect(handle, event, FD_ACCEPT);
38 set_events(IO::P_INPUT);
43 StreamSocket *StreamListenSocket::accept()
46 throw InvalidState("Socket is not listening");
49 socklen_t size=sizeof(sockaddr);
50 SocketHandle new_h=::accept(handle, &sa, &size);
52 RefPtr<SockAddr> paddr=SockAddr::create(sa);
53 return new StreamSocket(new_h, *paddr);