]> git.tdb.fi Git - libs/net.git/blob - source/socket.h
f275a7e2b35a0712fd97f78fe6774e226fdce8fe
[libs/net.git] / source / socket.h
1 /* $Id$
2
3 This file is part of libmspnet
4 Copyright © 2008  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_NET_SOCKET_H_
9 #define MSP_NET_SOCKET_H_
10
11 #include <msp/io/base.h>
12 #include "constants.h"
13 #include "sockaddr.h"
14 #include "types.h"
15
16 namespace Msp {
17 namespace Net {
18
19 class Socket: public IO::Base
20 {
21 public:
22         void set_block(bool);
23         IO::Handle get_event_handle();
24
25         bool get_connected() const { return connected; }
26         void bind(const SockAddr &);
27         virtual int connect(const SockAddr &) =0;
28         void close();
29         const SockAddr &get_local_address() const;
30         const SockAddr &get_peer_address() const;
31         ~Socket();
32 protected:
33         SocketHandle handle;
34 #ifdef WIN32
35         IO::Handle event;
36 #endif
37         bool       connected;
38         SockAddr   *local_addr;
39         SockAddr   *peer_addr;
40
41         Socket(SocketHandle, const SockAddr &);
42         Socket(Family, int, int);
43         void check_state(bool) const;
44         int get_option(int, int, void *, socklen_t *);
45         unsigned do_write(const char *, unsigned);
46         unsigned do_read(char *, unsigned);
47 };
48
49 } // namespace Net
50 } // namespace Msp
51
52 #endif