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 typedef int socklen_t;
17 class bad_socket_state: public std::logic_error
20 bad_socket_state(const std::string &w): std::logic_error(w) { }
21 virtual ~bad_socket_state() throw() { }
25 class Socket: public IO::EventObject
35 Socket(const Private &, const SockAddr &);
36 Socket(Family, int, int);
41 const IO::Handle &get_event_handle();
43 bool is_connected() const { return connected; }
45 /** Associates the socket with a local address. There must be no existing
46 users of the address. */
47 void bind(const SockAddr &);
49 /** Connects to a remote address. Exact semantics depend on the socket
51 virtual int connect(const SockAddr &) = 0;
53 void set_timeout(const Time::TimeDelta &);
54 const SockAddr &get_local_address() const;
55 const SockAddr &get_peer_address() const;
57 int set_option(int, int, const void *, socklen_t);
58 int get_option(int, int, void *, socklen_t *) const;
59 unsigned do_write(const char *, unsigned);
60 unsigned do_read(char *, unsigned);