![]() |
![]() |
![]() |
GNetwork Library Manual | ![]() |
---|---|---|---|---|
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)
"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
"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
The GNetworkServerIface interface provides a standard set of methods and signals for stream-based socket server objects.
typedef struct _GNetworkServer GNetworkServer;
And empty typedef for implementations of the GNetworkServerIface interface.
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.
void gnetwork_server_open (GNetworkServer *server);
Starts the server process for server
.
server : |
the server to open. |
Since 1.0
void gnetwork_server_close (GNetworkServer *server);
Closes the server
in question.
server : |
the server to close. |
Since 1.0
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. |
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
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. |
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
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
void (*GNetworkServerFunc) (GNetworkServer *server);
An implementation function type for methods of the GNetworkServerIface interface.
server : |
the server object to use. |
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 .
|
#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 .
|
bytes-received
" property"bytes-received" guint64 : Read
The number of bytes received through this server.
Default value: 0
bytes-sent
" property"bytes-sent" guint64 : Read
The number of bytes sent through this server.
Default value: 0
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
connections
" property"connections" GValueArray : Read
A value array of the currently open connections.
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
status
" property"status" GNetworkServerStatus : Read
The status of this server.
Default value: GNETWORK_SERVER_CLOSED
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. |
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. |