]> git.tdb.fi Git - libs/net.git/blob - source/socket.h
Add function to check if handshake is done
[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 protected:
22         SocketHandle handle;
23 #ifdef WIN32
24         IO::Handle event;
25 #endif
26         bool       connected;
27         SockAddr   *local_addr;
28         SockAddr   *peer_addr;
29
30         Socket(SocketHandle, const SockAddr &);
31         Socket(Family, int, int);
32 public:
33         ~Socket();
34
35         void set_block(bool);
36         IO::Handle get_event_handle();
37
38         bool is_connected() const { return connected; }
39         void bind(const SockAddr &);
40         virtual int connect(const SockAddr &) =0;
41         void close();
42         void set_timeout(const Time::TimeDelta &);
43         const SockAddr &get_local_address() const;
44         const SockAddr &get_peer_address() const;
45 protected:
46         void check_state(bool) const;
47         int set_option(int, int, const void *, socklen_t);
48         int get_option(int, int, void *, socklen_t *) const;
49         unsigned do_write(const char *, unsigned);
50         unsigned do_read(char *, unsigned);
51 };
52
53 } // namespace Net
54 } // namespace Msp
55
56 #endif