X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgsocketservice.c;h=81053f0ab6030832ce53f692a93553b2e1f56440;hb=c8d10470939847069b1a346d4c44f2adde3469f6;hp=830267313d5e6d2848b8622ef5098efc4077f207;hpb=0e352fdb182e63ff163b0feda198cb3b6b20aa3a;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gsocketservice.c b/gio/gsocketservice.c index 8302673..81053f0 100644 --- a/gio/gsocketservice.c +++ b/gio/gsocketservice.c @@ -14,9 +14,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Authors: Ryan Lortie * Alexander Larsson @@ -26,11 +24,12 @@ * SECTION:gsocketservice * @title: GSocketService * @short_description: Make it easy to implement a network service + * @include: gio/gio.h * @see_also: #GThreadedSocketService, #GSocketListener. * - * A #GSocketService is an object that represents a service that is - * provided to the network or over local sockets. When a new - * connection is made to the service the #GSocketService:incoming + * A #GSocketService is an object that represents a service that + * is provided to the network or over local sockets. When a new + * connection is made to the service the #GSocketService::incoming * signal is emitted. * * A #GSocketService is a subclass of #GSocketListener and you need @@ -39,7 +38,7 @@ * * There are two options for implementing a network service based on * #GSocketService. The first is to create the service using - * g_socket_service_new() and to connect to the #GSocketService:incoming + * g_socket_service_new() and to connect to the #GSocketService::incoming * signal. The second is to subclass #GSocketService and override the * default signal handler implementation. * @@ -48,9 +47,11 @@ * If you are interested in writing connection handlers that contain * blocking code then see #GThreadedSocketService. * - * The socket service runs on the main loop in the main thread, and is - * not threadsafe in general. However, the calls to start and stop - * the service are threadsafe so these can be used from threads that + * The socket service runs on the main loop of the + * [thread-default context][g-main-context-push-thread-default-context] + * of the thread it is created in, and is not + * threadsafe in general. However, the calls to start and stop the + * service are thread-safe so these can be used from threads that * handle incoming clients. * * Since: 2.22 @@ -59,18 +60,10 @@ #include "config.h" #include "gsocketservice.h" -#include "gio-marshal.h" #include #include "gsocketlistener.h" #include "gsocketconnection.h" - -static guint g_socket_service_incoming_signal; - -G_DEFINE_TYPE (GSocketService, g_socket_service, G_TYPE_SOCKET_LISTENER); - -G_LOCK_DEFINE_STATIC(active); - struct _GSocketServicePrivate { GCancellable *cancellable; @@ -78,6 +71,12 @@ struct _GSocketServicePrivate guint outstanding_accept : 1; }; +static guint g_socket_service_incoming_signal; + +G_LOCK_DEFINE_STATIC(active); + +G_DEFINE_TYPE_WITH_PRIVATE (GSocketService, g_socket_service, G_TYPE_SOCKET_LISTENER) + static void g_socket_service_ready (GObject *object, GAsyncResult *result, gpointer user_data); @@ -93,9 +92,7 @@ g_socket_service_real_incoming (GSocketService *service, static void g_socket_service_init (GSocketService *service) { - service->priv = G_TYPE_INSTANCE_GET_PRIVATE (service, - G_TYPE_SOCKET_SERVICE, - GSocketServicePrivate); + service->priv = g_socket_service_get_instance_private (service); service->priv->cancellable = g_cancellable_new (); service->priv->active = TRUE; } @@ -132,11 +129,7 @@ g_socket_service_changed (GSocketListener *listener) if (service->priv->outstanding_accept) g_cancellable_cancel (service->priv->cancellable); else - { - g_socket_listener_accept_async (listener, service->priv->cancellable, - g_socket_service_ready, NULL); - service->priv->outstanding_accept = TRUE; - } + do_accept (service); } G_UNLOCK (active); @@ -173,8 +166,8 @@ g_socket_service_is_active (GSocketService *service) * Starts the service, i.e. start accepting connections * from the added sockets when the mainloop runs. * - * This call is threadsafe, so it may be called from a thread - * handling an incomming client request. + * This call is thread-safe, so it may be called from a thread + * handling an incoming client request. * * Since: 2.22 */ @@ -203,8 +196,14 @@ g_socket_service_start (GSocketService *service) * Stops the service, i.e. stops accepting connections * from the added sockets when the mainloop runs. * - * This call is threadsafe, so it may be called from a thread - * handling an incomming client request. + * This call is thread-safe, so it may be called from a thread + * handling an incoming client request. + * + * Note that this only stops accepting new connections; it does not + * close the listening sockets, and you can call + * g_socket_service_start() again later to begin listening again. To + * close the listening sockets, call g_socket_listener_close(). (This + * will happen automatically when the #GSocketService is finalized.) * * Since: 2.22 */ @@ -243,25 +242,24 @@ g_socket_service_class_init (GSocketServiceClass *class) GObjectClass *gobject_class = G_OBJECT_CLASS (class); GSocketListenerClass *listener_class = G_SOCKET_LISTENER_CLASS (class); - g_type_class_add_private (class, sizeof (GSocketServicePrivate)); - gobject_class->finalize = g_socket_service_finalize; listener_class->changed = g_socket_service_changed; class->incoming = g_socket_service_real_incoming; /** * GSocketService::incoming: - * @service: the #GSocketService. - * @connection: a new #GSocketConnection object. - * @source_object: the source_object passed to g_socket_listener_add_address(). + * @service: the #GSocketService + * @connection: a new #GSocketConnection object + * @source_object: (allow-none): the source_object passed to + * g_socket_listener_add_address() * * The ::incoming signal is emitted when a new incoming connection * to @service needs to be handled. The handler must initiate the * handling of @connection, but may not block; in essence, * asynchronous operations must be used. * - * @connection will be unreffed once the signal handler returns, so - * you need to ref it yourself if you are planning to use it. + * @connection will be unreffed once the signal handler returns, + * so you need to ref it yourself if you are planning to use it. * * Returns: %TRUE to stop other handlers from being called * @@ -271,7 +269,7 @@ g_socket_service_class_init (GSocketServiceClass *class) g_signal_new ("incoming", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GSocketServiceClass, incoming), g_signal_accumulator_true_handled, NULL, - _gio_marshal_BOOLEAN__OBJECT_OBJECT, G_TYPE_BOOLEAN, + NULL, G_TYPE_BOOLEAN, 2, G_TYPE_SOCKET_CONNECTION, G_TYPE_OBJECT); }