Description
Server represents a TCP server. A callback is called when there's
a new connection.
Details
struct GServer
struct GServer
{
GInetAddr* iface;
gint port;
GTcpSocket* socket;
GServerFunc func;
gpointer user_data;
}; |
enum GServerStatus
typedef enum
{
GNET_SERVER_STATUS_CONNECT,
GNET_SERVER_STATUS_ERROR
} GServerStatus; |
Status of GServer, passed by GServerFunc.
GServerFunc ()
Callback for gnet_server_new(). When a new client connects the
function is called with status CONNECT and conn is the new
connection. The conn is owned by the callee. If an error
occurs, the function is called with status ERROR and conn is
NULL.
gnet_server_new ()
GServer* gnet_server_new (const GInetAddr *iface,
gboolean force_port,
GServerFunc func,
gpointer user_data); |
Create a new GServer object representing a server. The interface
is specified as in gnet_tcp_socket_server_new_interface().
Usually, iface is NULL or the iface is created by
gnet_inetaddr_new_any() and the port is set to a specific port.
The callback is called whenever a new connection arrives or if the
socket fails.
FIX: Remove force_port. It's easier for someone to call
gnet_server_new again than for me to explain how force port works.
(If force_port is TRUE, and the socket with the specified port
cannot be created, this function fails. If force_port is FALSE,
the function reattempts to create a socket but lets the OS choose
the port.
gnet_server_delete ()
void gnet_server_delete (GServer *server); |
Close and delete a GServer.