1 #include "platform_api.h"
2 #include <msp/core/systemerror.h>
3 #include <msp/io/handle_private.h>
4 #include "sockaddr_private.h"
6 #include "socket_private.h"
11 Socket::Socket(const Private &p):
17 priv->handle = p.handle;
20 getsockname(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size);
21 local_addr = SockAddr::new_from_sys(sa);
26 Socket::Socket(Family af, int type, int proto):
32 priv->handle = socket(family_to_sys(af), type, proto);
45 void Socket::set_block(bool b)
47 mode = (mode&~IO::M_NONBLOCK);
49 mode = (mode|IO::M_NONBLOCK);
54 const IO::Handle &Socket::get_event_handle()
59 void Socket::bind(const SockAddr &addr)
61 SockAddr::SysAddr sa = addr.to_sys();
63 int err = ::bind(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), sa.size);
65 throw system_error("bind");
68 local_addr = addr.copy();
71 const SockAddr &Socket::get_local_address() const
74 throw bad_socket_state("not bound");
78 void Socket::set_socket_events(unsigned e)
80 IO::PollEvent pe = static_cast<IO::PollEvent>(e&4095);
86 set_platform_events(e);