1 #ifndef MSP_NET_SOCKET_H_
2 #define MSP_NET_SOCKET_H_
4 #include <msp/io/base.h>
12 class Socket: public IO::Base
23 Socket(SocketHandle, const SockAddr &);
24 Socket(Family, int, int);
29 IO::Handle get_event_handle();
31 bool is_connected() const { return connected; }
33 /** Associates the socket with a local address. There must be no existing
34 users of the address. */
35 void bind(const SockAddr &);
37 /** Connects to a remote address. Exact semantics depend on the socket
39 virtual int connect(const SockAddr &) = 0;
41 /// Closes the socket. Most operations will throw an exception after this.
44 void set_timeout(const Time::TimeDelta &);
45 const SockAddr &get_local_address() const;
46 const SockAddr &get_peer_address() const;
48 void check_state(bool) const;
49 int set_option(int, int, const void *, socklen_t);
50 int get_option(int, int, void *, socklen_t *) const;
51 unsigned do_write(const char *, unsigned);
52 unsigned do_read(char *, unsigned);