GNetworkServer

GNetworkServer — An abstract interface for servers.

Synopsis




struct      GNetworkServer;
enum        GNetworkServerStatus;
void        gnetwork_server_open            (GNetworkServer *server);
void        gnetwork_server_close           (GNetworkServer *server);
GNetworkConnection* (*GNetworkServerCreateFunc)
                                            (GNetworkServer *server,
                                             const GValue *server_data,
                                             gpointer user_data,
                                             GError **error);
void        gnetwork_server_set_create_func (GNetworkServer *server,
                                             GNetworkServerCreateFunc func,
                                             gpointer data,
                                             GDestroyNotify notify);
struct      GNetworkServerIface;
void        gnetwork_server_new_connection  (GNetworkServer *server,
                                             GNetworkConnection *connection);
void        gnetwork_server_error           (GNetworkServer *server,
                                             const GError *error);
void        (*GNetworkServerFunc)           (GNetworkServer *server);
void        (*GNetworkServerSetCreateFunc)  (GNetworkServer *server,
                                             GNetworkServerCreateFunc func,
                                             gpointer data,
                                             GDestroyNotify notify);

Object Hierarchy


  GInterface
   +----GNetworkServer

Prerequisites

GNetworkServer requires GObject.

Known Implementations

GNetworkServer is implemented by GNetworkTcpServer.

Signal Prototypes


"error"     void        user_function      (GNetworkServer *gnetworkserver,
                                            GError *arg1,
                                            gpointer user_data);
"new-connection"
            void        user_function      (GNetworkServer *gnetworkserver,
                                            GNetworkConnection *arg1,
                                            gpointer user_data);

Description

The GNetworkServerIface interface provides a standard set of methods and signals for server objects.

Details

struct GNetworkServer

struct GNetworkServer;

And empty typedef for implementations of the GNetworkServerIface interface.


enum GNetworkServerStatus

typedef enum /* <prefix=GNETWORK_SERVER_STATUS> */
{
  GNETWORK_SERVER_CLOSING,
  GNETWORK_SERVER_CLOSED,
  GNETWORK_SERVER_OPENING,
  GNETWORK_SERVER_OPEN
}
GNetworkServerStatus;

An enumeration of the states a server object can be in.

GNETWORK_SERVER_CLOSINGthe server is closing.
GNETWORK_SERVER_CLOSEDthe server is closed.
GNETWORK_SERVER_OPENINGthe server is currently being opened.
GNETWORK_SERVER_OPENthe server is open and ready.

gnetwork_server_open ()

void        gnetwork_server_open            (GNetworkServer *server);

Starts the server process for server.

server : the server to open.

Since 1.0


gnetwork_server_close ()

void        gnetwork_server_close           (GNetworkServer *server);

Closes the server in question.

server : the server to close.

Since 1.0


GNetworkServerCreateFunc ()

GNetworkConnection* (*GNetworkServerCreateFunc)
                                            (GNetworkServer *server,
                                             const GValue *server_data,
                                             gpointer user_data,
                                             GError **error);

A prototype of a user function which can create a new connection object when called. server_data is implementation-specific, which means it may contain any type of of data, depending on what server uses. If the connection could/should not be created, this function should return NULL and set error if it is non-NULL.

server :the server the new connection is for.
server_data :encapsulated implementation-specific data.
user_data :the data passed to gnetwork_server_set_create_func().
error :a location to store any errors that may have occurred while creating the connection.
Returns :a new GNetworkConnection-implementing object.

gnetwork_server_set_create_func ()

void        gnetwork_server_set_create_func (GNetworkServer *server,
                                             GNetworkServerCreateFunc func,
                                             gpointer data,
                                             GDestroyNotify notify);

Sets the function which will be used by server to create new connections as needed to func. The notify function will be called with data as it's argument when this function is called again, or when server is destroyed.

Implementations should provide a default create function, so if func is NULL, the object should reset itself to call the default creation function.

server : the server to modify.
func : the function which will create new connections in response to client requests.
data : the user data to pass to func, or NULL.
notify : a function which will be called when data is no longer needed, or NULL.

Since 1.0


struct GNetworkServerIface

struct GNetworkServerIface {

  /* Signals */
  void (*new_connection)       (GNetworkServer * server,
				GNetworkConnection * connection);
  void (*error)		       (GNetworkServer * server,
				GError * error);

  /* Methods */
  GNetworkServerFunc		open;
  GNetworkServerFunc		close;
  GNetworkServerSetCreateFunc	set_create_func;

};

The interface structure.

void (*new_connection) (GNetworkServer * server, GNetworkConnection * connection)
void (*error) (GNetworkServer * server, GError * error)the slot for the "error" signal.
GNetworkServerFunc openthe method to open the server.
GNetworkServerFunc closethe method to close the server.
GNetworkServerSetCreateFunc set_create_functhe method to set the creation function.

gnetwork_server_new_connection ()

void        gnetwork_server_new_connection  (GNetworkServer *server,
                                             GNetworkConnection *connection);

Emits the "new-connection" signal for server, using connection.

server : the server to use.
connection : the new connection object.

Since 1.0


gnetwork_server_error ()

void        gnetwork_server_error           (GNetworkServer *server,
                                             const GError *error);

Emits the "error" signal for server, using error.

server : the server to use.
error : the error structure.

Since 1.0


GNetworkServerFunc ()

void        (*GNetworkServerFunc)           (GNetworkServer *server);

An implementation function type for methods of the GNetworkServerIface interface.

server :the server object to use.

GNetworkServerSetCreateFunc ()

void        (*GNetworkServerSetCreateFunc)  (GNetworkServer *server,
                                             GNetworkServerCreateFunc func,
                                             gpointer data,
                                             GDestroyNotify notify);

An implementation function type for the method which sets the new-connection creation function.

server :
func :
data :
notify :

Signals

The "error" signal

void        user_function                  (GNetworkServer *gnetworkserver,
                                            GError *arg1,
                                            gpointer user_data);

This signal is emitted when an error occurred.

gnetworkserver :the object which received the signal.
arg1 :the error.
user_data :user data set when the signal handler was connected.

The "new-connection" signal

void        user_function                  (GNetworkServer *gnetworkserver,
                                            GNetworkConnection *arg1,
                                            gpointer user_data);

This signal is emitted when a new incoming connection has been created.

gnetworkserver :the object which received the signal.
arg1 :the new (possibly opened) object.
user_data :user data set when the signal handler was connected.