![]() | ![]() | ![]() | GNetwork Library Manual | ![]() |
---|
GNetworkServer — An abstract interface for servers.
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);
GInterface +----GNetworkServer
GNetworkServer requires GObject.
GNetworkServer is implemented by GNetworkTcpServer.
"error" void user_function (GNetworkServer *gnetworkserver, GError *arg1, gpointer user_data); "new-connection" void user_function (GNetworkServer *gnetworkserver, GNetworkConnection *arg1, gpointer user_data);
The GNetworkServerIface interface provides a standard set of methods and signals for server objects.
struct 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.
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. |
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
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 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 : | |
func : | |
data : | |
notify : |
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. |
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. |
<< GNetworkTcpConnection | GNetworkTcpServer >> |