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