|
|
| TcpSocket () |
| | Creates a closed socket.
|
|
| TcpSocket (System::EventLoop &loop) |
| | Creates a socket and attaches it to loop.
|
|
| TcpSocket (TcpServer &server) |
| | Creates a socket and accepts a connection from server.
|
| | TcpSocket (const Endpoint &ep) |
| | Creates a socket and connects to ep.
|
|
| ~TcpSocket () |
| | Destroys the socket.
|
|
void | accept (TcpServer &server) |
| | Accepts a connection from server.
|
|
void | accept (TcpServer &server, const TcpSocketOptions &o) |
| | Accepts a connection from server with o.
|
| void | connect (const Endpoint &ep) |
| | Connects to ep.
|
| void | connect (const Endpoint &ep, const TcpSocketOptions &o) |
| | Connects to ep with o.
|
| void | beginConnect (const Endpoint &ep) |
| | Begins connecting to ep.
|
| void | beginConnect (const Endpoint &ep, const TcpSocketOptions &o) |
| | Begins connecting to ep with o.
|
| void | endConnect () |
| | Ends connecting to a host.
|
|
Signal< TcpSocket & > & | connected () |
| | Returns the signal that the socket was connected.
|
|
bool | isConnected () const |
| | Returns true if the socket is connected.
|
|
void | localEndpoint (Endpoint &ep) const |
| | Writes the local endpoint into ep.
|
|
void | remoteEndpoint (Endpoint &ep) const |
| | Writes the remote endpoint into ep.
|
|
void | close () |
| | Closes the device.
|
|
void | setTimeout (std::size_t timeout) |
| | Sets the timeout for blocking I/O in milliseconds.
|
|
void | beginRead (char *buffer, std::size_t n) |
| | Begins to read data.
|
|
std::size_t | endRead () |
| | Ends reading data.
|
| std::size_t | read (char *buffer, std::size_t n) |
| | Read data from I/O device.
|
|
void | beginWrite (const char *buffer, std::size_t n) |
| | Begins to write data.
|
|
std::size_t | endWrite () |
| | Ends writing data.
|
| std::size_t | write (const char *buffer, std::size_t n) |
| | Write data to I/O device.
|
|
bool | seekable () const |
| | Returns true if device is seekable.
|
| pos_type | seek (off_type offset, seekdir sd) |
| | Moves the read position to the given offset.
|
| std::size_t | peek (char *buffer, std::size_t n) |
| | Peek data from I/O device without consuming them.
|
| void | sync () |
| | Synchronize device.
|
| pos_type | position () |
| | Returns the current I/O position.
|
|
bool | isEof () const |
| | Returns if the device has reached EOF.
|
| Signal< IODevice & > & | inputReady () |
| | Notifies about available data.
|
| Signal< IODevice & > & | outputReady () |
| | Notifies when data can be written.
|
|
bool | isReading () const |
| | Returns true if the device is reading.
|
|
bool | isWriting () const |
| | Returns true if the device is writing.
|
|
EventLoop * | loop () const |
| | Returns the used event loop.
|
|
void | setActive (EventLoop &parent) |
| | Sets the parent loop, so that operations can be run.
|
|
void | detach () |
| | Remove from event loop and cancels outstanding operations.
|
|
void | cancel () |
| | Cancels all operations.
|
|
bool | run () |
| | Run operation if it is ready.
|
|
EventLoop * | parent () const |
| | Returns the used event loop.
|
TcpSocket is the connected TCP IODevice, and the same type is the client side of a connect() and the accepted side of a pending TcpServer connection. After the stream is up, read() and write() are the inherited device operations, blocking or asynchronous.
connect() reaches a remote endpoint and makes this socket the client stream, throwing AccessFailed if the host is not reachable, while accept() takes a pending connection from a listening server and makes this socket the accepted stream. A socket is one side or the other, not both at once, because connect() and accept() close any previous connection first.
- Asynchronous connect
beginConnect() starts an asynchronous connect, which requires the socket to be attached to an event loop. connected() is emitted when the attempt finishes, and endConnect() completes it, throwing AccessFailed if the host is not reachable. isConnected() reports whether the stream is up, and localEndpoint() and remoteEndpoint() write the two sides of the connection.
TcpSocketOptions configure the connection but do not open a socket. Keep-alive, when set to a non-negative interval in seconds, enables periodic probes on the stream, and a negative value leaves keep-alive unset.
The example is an asynchronous client connect, in which the slot calls endConnect() and then writes through the inherited device operation. The accept path is the TcpServer pending-connection slot.
{
}
Host and service address.
Definition Endpoint.h:77
Connected TCP byte stream.
Definition TcpSocket.h:141
void endConnect()
Ends connecting to a host.
Signal< TcpSocket & > & connected()
Returns the signal that the socket was connected.
Definition TcpSocket.h:209
void beginConnect(const Endpoint &ep)
Begins connecting to ep.
ConstMethodSlot< R, ClassT, As... > slot(ClassT &object, R(BaseT::*method)(As...) const)
Returns a slot object for the given object/member pair.
Definition ConstMethod.h:172
void run()
Starts the loop.
void beginWrite(const char *buffer, std::size_t n)
Begins to write data.
EventLoop * loop() const
Returns the used event loop.
Definition IODevice.h:240
Platform event loop.
Definition MainLoop.h:51
void setActive(EventLoop &parent)
Sets the parent loop, so that operations can be run.