1 #ifndef MSP_NET_CLIENTSOCKET_H_
2 #define MSP_NET_CLIENTSOCKET_H_
4 #include "mspnet_api.h"
11 ClientSockets are used for sending and receiving data over the network.
13 class MSPNET_API ClientSocket: public Socket
16 /** Emitted when the socket finishes connecting. */
17 sigc::signal<void, const std::exception *> signal_connect_finished;
20 bool connecting = false;
21 bool connected = false;
22 std::unique_ptr<SockAddr> peer_addr;
24 ClientSocket(const Private &, const SockAddr &);
25 ClientSocket(Family, int, int);
27 virtual ~ClientSocket();
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
32 virtual bool connect(const SockAddr &) = 0;
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;
39 bool is_connecting() const { return connecting; }
40 bool is_connected() const { return connected; }
42 void shutdown(IO::Mode);
44 const SockAddr &get_peer_address() const;
46 std::size_t do_write(const char *, std::size_t) override;
47 std::size_t do_read(char *, std::size_t) override;