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 bad_socket_state: public std::logic_error
16 bad_socket_state(const std::string &w): std::logic_error(w) { }
17 virtual ~bad_socket_state() throw() { }
21 class Socket: public IO::EventObject
30 Socket(SocketHandle, const SockAddr &);
31 Socket(Family, int, int);
36 const IO::Handle &get_event_handle();
38 bool is_connected() const { return connected; }
40 /** Associates the socket with a local address. There must be no existing
41 users of the address. */
42 void bind(const SockAddr &);
44 /** Connects to a remote address. Exact semantics depend on the socket
46 virtual int connect(const SockAddr &) = 0;
48 /// Closes the socket. Most operations will throw an exception after this.
51 void set_timeout(const Time::TimeDelta &);
52 const SockAddr &get_local_address() const;
53 const SockAddr &get_peer_address() const;
55 void check_state(bool) const;
56 int set_option(int, int, const void *, socklen_t);
57 int get_option(int, int, void *, socklen_t *) const;
58 unsigned do_write(const char *, unsigned);
59 unsigned do_read(char *, unsigned);