Component index
Section index | Component TCPSERVER |
Search |
Type | Object |
Summary | Multi-client TCP server |
Description | Works standalone and with inetd. This is useful for line oriented protocol. It manages several clients at once using a single process. It can also server unix domain socket. See the prototype. |
void closeclient (int handle) | ![]() ![]() | void endclient (int no, bool &endserver, TCPSERVER_INFO &info) |
int getnbclients () | ![]() ![]() | void idle (int since, bool &endserver, TCPSERVER_INFO &info) |
void inject (int handle, ARRAY_OBJ *data) | ![]() ![]() | void newclient (int no, unsigned long from, bool &endclient, bool &endserver, TCPSERVER_INFO &info) |
void inject (int handle) | ![]() ![]() | void receive (int no, const char *line, bool &endclient, bool &endserver, int &state, TCPSERVER_INFO &info) |
void inject_output () | ![]() ![]() | void time_out (int no, bool &endserver, TCPSERVER_INFO &info) |
bool islistening (int handle) | ![]() ![]() | |
int listen (const char *port) | ![]() ![]() | |
int listen (const char *bindaddr, const char *port) | ![]() ![]() | |
int listen (int port) | ![]() ![]() | |
void loop () | ![]() ![]() | |
int sendall (const void *buf, int len) | ![]() ![]() | |
int sendall (const char *buf) | ![]() ![]() | |
int sendallf (const char *ctl, ...) | ![]() ![]() | |
int sendto (int cli, const char *data) | ![]() ![]() | |
int sendto (int cli, const void *data, int len) | ![]() ![]() | |
int sendtof (int cli, const void *ctl, ...) | ![]() ![]() | |
bool setlisten (int handle, bool on) | ![]() ![]() | |
void setmaxclients (int maxclient) | ![]() ![]() | |
bool setnonblock (bool mode, int bufsize) | ![]() ![]() | |
bool setrawmode (bool mode) | ![]() ![]() |
This version takes no argument. Initially the component does nothing. It just waits for listen() or inject() calls to learn which handle to monitor.
It can serve either TCP socket, or unix domain socket (use the unix: prefix)
The socket was created/accepted using other means, but we want the TCPSERVER to handle it from now on.
The socket was created/accepted using other means, but we want the TCPSERVER to handle it from now on.
setlisten lets you turn a socket on and off (input wise).
Return -1 if the port can't be opened. If the port starts with "unix:", the rest is taken as the path of a unix domain socket. TCPSERVER may listen on several socket, including TCP and Unix all at once.
Return -1 if the port can't be opened. If the port starts with "unix:", the rest is taken as the path of a unix domain socket. TCPSERVER may listen on several socket, including TCP and Unix all at once. For Unix domain socket, bindaddr is not used.
Return -1 if the port can't be opened. If the port starts with "unix:", the rest is taken as the path of a unix domain socket. TCPSERVER may listen on several socket, including TCP and Unix all at once.
The same buffer will be sent to all client. The function return -1 if any "write" fail.
The same string will be sent to all client. The function return -1 if any "write" fail.
The same string will be sent to all client. The function return -1 if any "write" fail.
The client must be handled by this TCPSERVER
The client must be handled by this TCPSERVER
The client must be handled by this TCPSERVER
You generally use this to prevent more request to be queued while you know the output might be stopped (blocked).
If more clients connects, they are rejected. This is the size of the handle table, so this is not exactly the maximum number of client, but the largest file handle.
When you turn non-blocking, the various send* fhelper won't block. They will always return the total amount of bytes. Extra bytes not wrtten to the socket are buffered.
When mode is true, inputs from clients are processed as binary raw data. When mode is false, inputs is processed as text lines.
endclient is also called, after time_out.
endclient won't be called.
The connection is still alive, but TCPSERVER will forget about it. Useful when you pass the connection to a thread for example.
The socket will be managed exactly like it was accepted by the TCPSERVER. In general, application will establish a new connection and pass control over to the TCPSERVER.
This is useful in non-blocking mode. This allows the usage of the sendto() helper on socket not accepted by the TCPSERVER.
setlisten lets you turn a socket on and off (input wise).
Starts the iteration over all connected client, returning the handle of each client and optionally the application stored data (info.data). iter_init() returns the first connection and iter_next() returns the rest. Both function returns -1 if there is no more connections.
Starts the iteration over all connected client, returning the handle of each client and optionally the application stored data (info.data). iter_init() returns the first connection and iter_next() returns the rest. Both function returns -1 if there is no more connections.
This is called in a loop after iter_init.
This is called in a loop after iter_init.
Return the number of byte sent or -1 if any error.
Return the number of bytes sent or -1 if any error.
The same buffer is sent to all connected client and -1 is returned whenever one write fails.
The same string is sent to all connected client and -1 is returned whenever one write fails.
The same string is sent to all connected client and -1 is returned whenever one write fails.
Return the number of bytes sent or -1 if any error.
This handle is (must be) managed by TCPSERVER.
This handle is (must be) managed by TCPSERVER.
Return the number of bytes sent or -1 if any error.
Each client may have a different timeout. If the timeout is reached the time_out functag will be called. The time_out will then decide what to do.
You generally use this to prevent more request to be queued while you know the output might be stopped (blocked).
In raw mode, bytes read are passed to the receive functag as is. The info.linelen variable is used to obtain the lenght of the data in line. In rawmode==false (default), data is processed as ASCII lines