]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/clientsocket.h
Prepare for assimilating msphttp
[libs/net.git] / source / net / clientsocket.h
diff --git a/source/net/clientsocket.h b/source/net/clientsocket.h
new file mode 100644 (file)
index 0000000..db684f4
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef MSP_NET_CLIENTSOCKET_H_
+#define MSP_NET_CLIENTSOCKET_H_
+
+#include "socket.h"
+
+namespace Msp {
+namespace Net {
+
+/**
+ClientSockets are used for sending and receiving data over the network.
+*/
+class ClientSocket: public Socket
+{
+public:
+       /** Emitted when the socket finishes connecting. */
+       sigc::signal<void, const std::exception *> signal_connect_finished;
+
+protected:
+       bool connecting;
+       bool connected;
+       SockAddr *peer_addr;
+
+       ClientSocket(const Private &, const SockAddr &);
+       ClientSocket(Family, int, int);
+public:
+       virtual ~ClientSocket();
+
+       /** Connects to a remote address.  Exact semantics depend on the socket
+       type.  Returns true if the connection was established, false if it's in
+       progress. */
+       virtual bool connect(const SockAddr &) = 0;
+
+       /** Checks the status of a connection being established.  Returns true if
+       the connection was established successfully, false if it's still in
+       progress.  If an error occurred, an exception is thrown. */
+       virtual bool poll_connect(const Time::TimeDelta &) = 0;
+
+       bool is_connecting() const { return connecting; }
+       bool is_connected() const { return connected; }
+
+       const SockAddr &get_peer_address() const;
+protected:
+       virtual unsigned do_write(const char *, unsigned);
+       virtual unsigned do_read(char *, unsigned);
+};
+
+} // namespace Net
+} // namespace Msp
+
+#endif