]> git.tdb.fi Git - libs/net.git/blob - source/net/socket.h
Move most platform-specific code into overlay directories
[libs/net.git] / source / net / socket.h
1 #ifndef MSP_NET_SOCKET_H_
2 #define MSP_NET_SOCKET_H_
3
4 #include <msp/io/eventobject.h>
5 #include <msp/io/handle.h>
6 #include "constants.h"
7 #include "sockaddr.h"
8
9 namespace Msp {
10 namespace Net {
11
12 class bad_socket_state: public std::logic_error
13 {
14 public:
15         bad_socket_state(const std::string &w): std::logic_error(w) { }
16         virtual ~bad_socket_state() throw() { }
17 };
18
19
20 class Socket: public IO::EventObject
21 {
22 protected:
23         enum SocketEvent
24         {
25                 S_NONE = IO::P_NONE,
26                 S_INPUT = IO::P_INPUT,
27                 S_CONNECT = 4096,
28                 S_ACCEPT = 8192
29         };
30
31         struct Private;
32
33         Private *priv;
34         SockAddr *local_addr;
35
36         Socket(const Private &);
37         Socket(Family, int, int);
38 private:
39         void platform_init();
40         void platform_cleanup();
41 public:
42         ~Socket();
43
44         virtual void set_block(bool);
45         virtual const IO::Handle &get_event_handle();
46
47         /** Associates the socket with a local address.  There must be no existing
48         users of the address. */
49         void bind(const SockAddr &);
50
51         const SockAddr &get_local_address() const;
52
53         void set_timeout(const Time::TimeDelta &);
54 protected:
55         void set_socket_events(unsigned);
56         void set_platform_events(unsigned);
57 };
58
59 } // namespace Net
60 } // namespace Msp
61
62 #endif