-#include <cerrno>
-#include <msp/core/refptr.h>
-#include <msp/core/systemerror.h>
-#include <msp/io/handle_private.h>
-#include <msp/strings/format.h>
-#include "sockaddr_private.h"
-#include "socket_private.h"
-#include "streamlistensocket.h"
-#include "streamsocket.h"
-
-using namespace std;
-
-namespace Msp {
-namespace Net {
-
-StreamListenSocket::StreamListenSocket(Family af, int proto):
- Socket(af, SOCK_STREAM, proto),
- listening(false)
-{ }
-
-int StreamListenSocket::connect(const SockAddr &)
-{
- // 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(priv->handle, backlog);
- if(err==-1)
- throw system_error("listen");
-
-#ifdef WIN32
- WSAEventSelect(priv->handle, *priv->event, FD_ACCEPT);
-#endif
- set_events(IO::P_INPUT);
-
- listening = true;
-}
-
-StreamSocket *StreamListenSocket::accept()
-{
- if(!listening)
- throw bad_socket_state("not listening");
-
- SockAddr::SysAddr sa;
- Private new_p;
- new_p.handle = ::accept(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size);
-
- RefPtr<SockAddr> paddr = SockAddr::from_sys(sa);
- return new StreamSocket(new_p, *paddr);
-}
-
-} // namespace Net
-} // namespace Msp