]> git.tdb.fi Git - libs/net.git/blob - source/streamsocket.h
Comment changes
[libs/net.git] / source / streamsocket.h
1 #ifndef MSP_NET_STREAMSOCKET_H_
2 #define MSP_NET_STREAMSOCKET_H_
3
4 #include "socket.h"
5
6 namespace Msp {
7 namespace Net {
8
9 class StreamSocket: public Socket
10 {
11         friend class StreamListenSocket;
12 private:
13         bool connecting;
14
15 public:
16         /** Emitted when the socket finishes connecting.  The argument is a
17         platform-dependent error code. */
18         sigc::signal<void, int> signal_connect_finished;
19
20 private:
21         /// Used by StreamListenSocket to construct a new socket from accept.
22         StreamSocket(SocketHandle, const SockAddr &);
23 public:
24         StreamSocket(Family, int = 0);
25
26         /** Connects to a remote address.  StreamSockets must be connected before
27         data can be sent and received.  Returns 0 if the connection was successfully
28         established, 1 if it's in progress.
29         
30         If the socket is non-blocking, this function may return before the
31         connection is fully established.  The caller must then use either the
32         poll_connect function or an EventDispatcher to finish the process. */
33         virtual int connect(const SockAddr &);
34
35         bool is_connecting() const { return connecting; }
36
37         /** Checks the status of a connection being established.  Returns 0 if the
38         connection was established successfully, 1 if it's still in progress.  If
39         the attempt finished due to an error, an exception is thrown. */
40         int poll_connect(const Time::TimeDelta &);
41
42 private:
43         void on_event(IO::PollEvent);
44 };
45
46 } // namespace Net
47 } // namespace Msp
48
49 #endif