2 #include <msp/core/refptr.h>
3 #include <msp/strings/format.h>
4 #include "streamlistensocket.h"
5 #include "streamsocket.h"
10 StreamListenSocket::StreamListenSocket(Family af, int proto):
11 Socket(af, SOCK_STREAM, proto),
15 int StreamListenSocket::connect(const SockAddr &)
17 throw Exception("Can't connect a listen socket");
20 void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
24 int err = ::listen(handle, backlog);
26 throw SystemError("Unable to listen", errno);
29 WSAEventSelect(handle, event, FD_ACCEPT);
31 set_events(IO::P_INPUT);
36 StreamSocket *StreamListenSocket::accept()
39 throw InvalidState("Socket is not listening");
42 socklen_t size = sizeof(sockaddr_storage);
43 SocketHandle new_h = ::accept(handle, reinterpret_cast<sockaddr *>(&sa), &size);
45 RefPtr<SockAddr> paddr = SockAddr::create(sa);
46 return new StreamSocket(new_h, *paddr);