]> git.tdb.fi Git - libs/net.git/blob - source/net/clientsocket.h
Prepare for assimilating msphttp
[libs/net.git] / source / net / clientsocket.h
1 #ifndef MSP_NET_CLIENTSOCKET_H_
2 #define MSP_NET_CLIENTSOCKET_H_
3
4 #include "socket.h"
5
6 namespace Msp {
7 namespace Net {
8
9 /**
10 ClientSockets are used for sending and receiving data over the network.
11 */
12 class ClientSocket: public Socket
13 {
14 public:
15         /** Emitted when the socket finishes connecting. */
16         sigc::signal<void, const std::exception *> signal_connect_finished;
17
18 protected:
19         bool connecting;
20         bool connected;
21         SockAddr *peer_addr;
22
23         ClientSocket(const Private &, const SockAddr &);
24         ClientSocket(Family, int, int);
25 public:
26         virtual ~ClientSocket();
27
28         /** Connects to a remote address.  Exact semantics depend on the socket
29         type.  Returns true if the connection was established, false if it's in
30         progress. */
31         virtual bool connect(const SockAddr &) = 0;
32
33         /** Checks the status of a connection being established.  Returns true if
34         the connection was established successfully, false if it's still in
35         progress.  If an error occurred, an exception is thrown. */
36         virtual bool poll_connect(const Time::TimeDelta &) = 0;
37
38         bool is_connecting() const { return connecting; }
39         bool is_connected() const { return connected; }
40
41         const SockAddr &get_peer_address() const;
42 protected:
43         virtual unsigned do_write(const char *, unsigned);
44         virtual unsigned do_read(char *, unsigned);
45 };
46
47 } // namespace Net
48 } // namespace Msp
49
50 #endif