GNet Network Library Reference Manual
<<< Previous Page | Home | Up |

# server

## Name

server --

## Synopsis

    struct      GServer;
    enum        GServerStatus;
    void        (*GServerFunc)                  (GServer *server,
                                                 GServerStatus status,
                                                 GConn *conn,
                                                 gpointer user_data);
    GServer*    gnet_server_new                 (const GInetAddr *iface,
                                                 gboolean force_port,
                                                 GServerFunc func,
                                                 gpointer user_data);
    void        gnet_server_delete              (GServer *server);

## Description

## 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 ()

    void        (*GServerFunc)                  (GServer *server,
                                                 GServerStatus status,
                                                 GConn *conn,
                                                 gpointer user_data);

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.

`server` : |
`status` : |
`conn` : |
`user_data` : |

### 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.

`iface` : |
`force_port` : |
`func` : |
`user_data` : |
Returns : |

### gnet_server_delete ()

    void        gnet_server_delete              (GServer *server);

Close and delete a GServer.

`server` : |

<<< Previous Page | Home | Up |
conn |