]> git.tdb.fi Git - libs/net.git/blob - source/socket.h
Add an overload for resolve that takes host and service separately
[libs/net.git] / source / 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 #ifdef WIN32
13 typedef int socklen_t;
14 #endif
15
16
17 class bad_socket_state: public std::logic_error
18 {
19 public:
20         bad_socket_state(const std::string &w): std::logic_error(w) { }
21         virtual ~bad_socket_state() throw() { }
22 };
23
24
25 class Socket: public IO::EventObject
26 {
27 protected:
28         struct Private;
29
30         Private *priv;
31         SockAddr *local_addr;
32
33         Socket(const Private &);
34         Socket(Family, int, int);
35 public:
36         ~Socket();
37
38         virtual void set_block(bool);
39         virtual const IO::Handle &get_event_handle();
40
41         /** Associates the socket with a local address.  There must be no existing
42         users of the address. */
43         void bind(const SockAddr &);
44
45         const SockAddr &get_local_address() const;
46
47         void set_timeout(const Time::TimeDelta &);
48 protected:
49         int set_option(int, int, const void *, socklen_t);
50         int get_option(int, int, void *, socklen_t *) const;
51 };
52
53 } // namespace Net
54 } // namespace Msp
55
56 #endif