1 #ifndef MSP_NET_SOCKET_H_
2 #define MSP_NET_SOCKET_H_
4 #include <msp/io/eventobject.h>
5 #include <msp/io/handle.h>
13 class Socket: public IO::EventObject
22 Socket(SocketHandle, const SockAddr &);
23 Socket(Family, int, int);
28 const IO::Handle &get_event_handle();
30 bool is_connected() const { return connected; }
32 /** Associates the socket with a local address. There must be no existing
33 users of the address. */
34 void bind(const SockAddr &);
36 /** Connects to a remote address. Exact semantics depend on the socket
38 virtual int connect(const SockAddr &) = 0;
40 /// Closes the socket. Most operations will throw an exception after this.
43 void set_timeout(const Time::TimeDelta &);
44 const SockAddr &get_local_address() const;
45 const SockAddr &get_peer_address() const;
47 void check_state(bool) const;
48 int set_option(int, int, const void *, socklen_t);
49 int get_option(int, int, void *, socklen_t *) const;
50 unsigned do_write(const char *, unsigned);
51 unsigned do_read(char *, unsigned);