GNetworkServer

GNetworkServer — The interface for stream-based socket server objects.

Synopsis




            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);
            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);
#define     GNETWORK_SERVER_CALL_PARENT     (obj,method,args)

Object Hierarchy


  GInterface
   +----GNetworkServer

Prerequisites

GNetworkServer requires GObject.

Known Implementations

GNetworkServer is implemented by GNetworkUnixServer and GNetworkTcpServer.

Properties


  "bytes-received"       guint64               : Read
  "bytes-sent"           guint64               : Read
  "close-children"       gboolean              : Read / Write / Construct
  "connections"          GValueArray           : Read
  "max-connections"      guint                 : Read / Write / Construct
  "status"               GNetworkServerStatus  : Read

Signals


"error"     void        user_function      (GNetworkServer *gnetworkserver,
                                            GError         *arg1,
                                            gpointer        user_data)           : Run first / Has details
"new-connection"
            void        user_function      (GNetworkServer     *gnetworkserver,
                                            GNetworkConnection *arg1,
                                            gpointer            user_data)           : Run first

Description

The GNetworkServerIface interface provides a standard set of methods and signals for stream-based socket server objects.

Details

GNetworkServer

typedef struct _GNetworkServer 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_CLOSING the server is closing.
GNETWORK_SERVER_CLOSED the server is closed.
GNETWORK_SERVER_OPENING the server is currently being opened.
GNETWORK_SERVER_OPEN the 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


GNetworkServerIface

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

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

The interface structure.

new_connection ()
error () the slot for the "error" signal.
GNetworkServerFunc open; the method to open the server.
GNetworkServerFunc close; the method to close the server.
GNetworkServerSetCreateFunc set_create_func; the 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 : the server object in question.
func : the function which will create a new connection object.
data : the user data to pass func.
notify : a function which will be called to destroy data.

GNETWORK_SERVER_CALL_PARENT()

#define     GNETWORK_SERVER_CALL_PARENT(obj,method,args)

A macro to call a parent class' GNetworkServerIface implementation of method. Typically, this would be used to "chain up" after overriding a method or signal callback.

obj : the object in question.
method : the method to call.
args : the arguments to pass method.

Property Details

The "bytes-received" property

  "bytes-received"       guint64               : Read

The number of bytes received through this server.

Default value: 0


The "bytes-sent" property

  "bytes-sent"           guint64               : Read

The number of bytes sent through this server.

Default value: 0


The "close-children" property

  "close-children"       gboolean              : Read / Write / Construct

Whether or not to close currently open connections when the server is closed.

Default value: TRUE


The "connections" property

  "connections"          GValueArray           : Read

A value array of the currently open connections.


The "max-connections" property

  "max-connections"      guint                 : Read / Write / Construct

The maximum number of incoming connections to allow, or %0, if all connections should be allowed.

Default value: 0


The "status" property

  "status"               GNetworkServerStatus  : Read

The status of this server.

Default value: GNETWORK_SERVER_CLOSED

Signal Details

The "error" signal

void        user_function                  (GNetworkServer *gnetworkserver,
                                            GError         *arg1,
                                            gpointer        user_data)           : Run first / Has details

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)           : Run first

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.