]> git.tdb.fi Git - libs/net.git/blob - source/net/streamsocket.h
Add a dynamic receiver class for more flexible packet handling
[libs/net.git] / source / net / streamsocket.h
1 #ifndef MSP_NET_STREAMSOCKET_H_
2 #define MSP_NET_STREAMSOCKET_H_
3
4 #include "clientsocket.h"
5 #include "mspnet_api.h"
6
7 namespace Msp {
8 namespace Net {
9
10 class MSPNET_API StreamSocket: public ClientSocket
11 {
12         friend class StreamServerSocket;
13
14 private:
15         /// Used by StreamListenSocket to construct a new socket from accept.
16         StreamSocket(const Private &, const SockAddr &);
17 public:
18         StreamSocket(Family, int = 0);
19
20         /** Connects to a remote address.  StreamSockets must be connected before
21         data can be sent and received.  Returns 0 if the connection was successfully
22         established, 1 if it's in progress.
23         
24         If the socket is non-blocking, this function may return before the
25         connection is fully established.  The caller must then use either the
26         poll_connect function or an EventDispatcher to finish the process. */
27         bool connect(const SockAddr &) override;
28
29         bool poll_connect(const Time::TimeDelta &) override;
30
31 private:
32         void on_event(IO::PollEvent) override;
33 };
34
35 } // namespace Net
36 } // namespace Msp
37
38 #endif