5 #include <msp/core/refptr.h>
6 #include <msp/core/systemerror.h>
7 #include <msp/io/handle_private.h>
8 #include <msp/strings/format.h>
9 #include "sockaddr_private.h"
10 #include "socket_private.h"
11 #include "streamserversocket.h"
12 #include "streamsocket.h"
19 StreamServerSocket::StreamServerSocket(Family af, int proto):
20 ServerSocket(af, SOCK_STREAM, proto),
24 void StreamServerSocket::listen(const SockAddr &addr, unsigned backlog)
28 int err = ::listen(priv->handle, backlog);
30 throw system_error("listen");
33 WSAEventSelect(priv->handle, *priv->event, FD_ACCEPT);
35 set_events(IO::P_INPUT);
40 StreamSocket *StreamServerSocket::accept()
43 throw bad_socket_state("not listening");
47 new_p.handle = ::accept(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size);
49 RefPtr<SockAddr> paddr = SockAddr::new_from_sys(sa);
50 return new StreamSocket(new_p, *paddr);