#include <serversocket.h>
Public Member Functions | |
| ServerSocket (int port=0, int backlog=10) throw (ServerSocketError) | |
| Start a server on port. | |
| ~ServerSocket () | |
| Destructor; also closes the socket. | |
| int | port () |
| unsigned long | address () |
| Dv::Util::ref< InetAddress > | inetaddress () |
| Dv::Util::ref< Socket > | accept (time_t delay=0, size_t bufsize=1024, bool non_blocking=false, std::ostream *dbg=0) |
| Accept a new connection from a client. | |
| bool | connection (time_t timeout, int *syserr=0) |
| Check whether connections are waiting to be accepted. | |
| int | fd () const |
| void | close () |
| Closes underlying socket, makes ServerSocket unusable by performing shut_down(2) en close(2) on it and setting the underlying file descriptor to -1. | |
Protected Member Functions | |
| int | fd_accept () |
| Auxiliary function for accept(). | |
Private Member Functions | |
| ServerSocket (const ServerSocket &) | |
| ServerSocket & | operator= (const ServerSocket &) |
Private Attributes | |
| int | socket_fd_ |
| void * | server_address_ |
| bool | closed_ |
Example usage:
try { Dv::Net::ServerSocket server(server-port); Dv::Util::ref<Socket> client(server.accept()); std::cerr << "Connection from " << client.host() << ":" << client.port() << std::endl; std::string request; std::string reply; while (*client>>request) *client << reply; } catch (Dv::Net::ServerSocketError& e) { std::cerr << e.what() << std::endl; return 1; }
Definition at line 47 of file serversocket.h.
|
||||||||||||
|
Start a server on port.
|
|
|
Destructor; also closes the socket.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||
|
Accept a new connection from a client.
|
|
||||||||||||
|
Check whether connections are waiting to be accepted.
Dv::Net::ServerSocket ss(port); .. if ( ss.connection(2000) ) { // only if a connection is waiting within 2 sec Dv::Util::ref<Dv::Net::Socket> so(ss.accept()); *so << "+OK" << std::endl; } else { // do something else }
|
|
|
References socket_fd_. |
|
|
Closes underlying socket, makes ServerSocket unusable by performing shut_down(2) en close(2) on it and setting the underlying file descriptor to -1.
|
|
|
Auxiliary function for accept().
|
|
|
|
|
|
Definition at line 118 of file serversocket.h. Referenced by fd(). |
|
|
Definition at line 119 of file serversocket.h. |
|
|
Definition at line 121 of file serversocket.h. |
| dvnet-0.9.11 | [27 December, 2004] |