]> git.tdb.fi Git - libs/net.git/blob - source/net/socket.h
Remove unnecessary destructors from exception classes
[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 };
17
18
19 class Socket: public IO::EventObject
20 {
21 protected:
22         enum SocketEvent
23         {
24                 S_NONE = IO::P_NONE,
25                 S_INPUT = IO::P_INPUT,
26                 S_CONNECT = 4096,
27                 S_ACCEPT = 8192
28         };
29
30         struct Private;
31
32         Private *priv;
33         SockAddr *local_addr;
34
35         Socket(const Private &);
36         Socket(Family, int, int);
37 private:
38         void platform_init();
39         void platform_cleanup();
40 public:
41         ~Socket();
42
43         virtual void set_block(bool);
44         virtual void set_inherit(bool);
45         const IO::Handle &get_handle(IO::Mode);
46         virtual const IO::Handle &get_event_handle();
47
48         /** Associates the socket with a local address.  There must be no existing
49         users of the address. */
50         void bind(const SockAddr &);
51
52         bool is_bound() const { return local_addr; }
53         const SockAddr &get_local_address() const;
54
55         void set_timeout(const Time::TimeDelta &);
56 protected:
57         void set_socket_events(unsigned);
58         void set_platform_events(unsigned);
59 };
60
61 } // namespace Net
62 } // namespace Msp
63
64 #endif