]> git.tdb.fi Git - libs/net.git/blob - source/clientsocket.h
Correct poll usage
[libs/net.git] / source / 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 protected:
15         bool connecting;
16         bool connected;
17         SockAddr *peer_addr;
18
19         ClientSocket(const Private &, const SockAddr &);
20         ClientSocket(Family, int, int);
21 public:
22         virtual ~ClientSocket();
23
24         /** Connects to a remote address.  Exact semantics depend on the socket
25         type.  Returns true if the connection was established, false if it's in
26         progress. */
27         virtual bool connect(const SockAddr &) = 0;
28
29         /** Checks the status of a connection being established.  Returns true if
30         the connection was established successfully, false if it's still in
31         progress.  If an error occurred, an exception is thrown. */
32         virtual bool poll_connect(const Time::TimeDelta &) = 0;
33
34         bool is_connecting() const { return connecting; }
35         bool is_connected() const { return connected; }
36
37         const SockAddr &get_peer_address() const;
38 protected:
39         virtual unsigned do_write(const char *, unsigned);
40         virtual unsigned do_read(char *, unsigned);
41 };
42
43 } // namespace Net
44 } // namespace Msp
45
46 #endif