gsocket: Set SO_NOSIGPIPE on sockets on Darwin
[platform/upstream/glib.git] / gio / gthreadedsocketservice.c
index f5484c2..f18238c 100644 (file)
  * 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 <http://www.gnu.org/licenses/>.
  *
  * Authors: Ryan Lortie <desrt@desrt.ca>
  *          Alexander Larsson <alexl@redhat.com>
  */
 
 /**
- * SECTION: gthreadedsocketservice
+ * SECTION:gthreadedsocketservice
  * @title: GThreadedSocketService
- * @short_description: a threaded #GSocketService
+ * @short_description: A threaded GSocketService
+ * @include: gio/gio.h
  * @see_also: #GSocketService.
  *
  * A #GThreadedSocketService is a simple subclass of #GSocketService
  * that handles incoming connections by creating a worker thread and
- * dispatching the connection to it by emitting the ::run signal in
- * the new thread.
+ * dispatching the connection to it by emitting the
+ * #GThreadedSocketService::run signal in the new thread.
  *
  * The signal handler may perform blocking IO and need not return
  * until the connection is closed.
  *
  * The service is implemented using a thread pool, so there is a
- * limited amount of threads availible to serve incomming requests.
+ * limited amount of threads available to serve incoming requests.
  * The service automatically stops the #GSocketService from accepting
  * new connections when all threads are busy.
  *
- * As with #GSocketService, you may connect to ::run, or subclass and
- * override the default handler.
+ * As with #GSocketService, you may connect to #GThreadedSocketService::run,
+ * or subclass and override the default handler.
  */
 
 #include "config.h"
 #include "gthreadedsocketservice.h"
 #include "glibintl.h"
 
-#include "gio-marshal.h"
-
-#include "gioalias.h"
+struct _GThreadedSocketServicePrivate
+{
+  GThreadPool *thread_pool;
+  int max_threads;
+  gint job_count;
+};
 
 static guint g_threaded_socket_service_run_signal;
 
-G_DEFINE_TYPE (GThreadedSocketService,
-              g_threaded_socket_service,
-              G_TYPE_SOCKET_SERVICE);
+G_DEFINE_TYPE_WITH_PRIVATE (GThreadedSocketService,
+                            g_threaded_socket_service,
+                            G_TYPE_SOCKET_SERVICE)
 
 enum
 {
@@ -66,16 +68,8 @@ enum
   PROP_MAX_THREADS
 };
 
-
 G_LOCK_DEFINE_STATIC(job_count);
 
-struct _GThreadedSocketServicePrivate
-{
-  GThreadPool *thread_pool;
-  int max_threads;
-  gint job_count;
-};
-
 typedef struct
 {
   GThreadedSocketService *service;
@@ -139,9 +133,7 @@ g_threaded_socket_service_incoming (GSocketService    *service,
 static void
 g_threaded_socket_service_init (GThreadedSocketService *service)
 {
-  service->priv = G_TYPE_INSTANCE_GET_PRIVATE (service,
-                                              G_TYPE_THREADED_SOCKET_SERVICE,
-                                              GThreadedSocketServicePrivate);
+  service->priv = g_threaded_socket_service_get_instance_private (service);
   service->priv->max_threads = 10;
 }
 
@@ -164,7 +156,7 @@ g_threaded_socket_service_finalize (GObject *object)
 {
   GThreadedSocketService *service = G_THREADED_SOCKET_SERVICE (object);
 
-  g_object_unref (service->priv->thread_pool);
+  g_thread_pool_free (service->priv->thread_pool, FALSE, TRUE);
 
   G_OBJECT_CLASS (g_threaded_socket_service_parent_class)
     ->finalize (object);
@@ -215,8 +207,6 @@ g_threaded_socket_service_class_init (GThreadedSocketServiceClass *class)
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GSocketServiceClass *ss_class = &class->parent_class;
 
-  g_type_class_add_private (class, sizeof (GThreadedSocketServicePrivate));
-
   gobject_class->constructed = g_threaded_socket_service_constructed;
   gobject_class->finalize = g_threaded_socket_service_finalize;
   gobject_class->set_property = g_threaded_socket_service_set_property;
@@ -229,20 +219,19 @@ g_threaded_socket_service_class_init (GThreadedSocketServiceClass *class)
    * @service: the #GThreadedSocketService.
    * @connection: a new #GSocketConnection object.
    * @source_object: the source_object passed to g_socket_listener_add_address().
-   * @returns: %TRUE if @connection has been handled.
    *
    * The ::run signal is emitted in a worker thread in response to an
-   * incoming connection.  This thread is dedicated to handling
-   * @connection and may perform blocking IO.  The signal handler need
+   * incoming connection. This thread is dedicated to handling
+   * @connection and may perform blocking IO. The signal handler need
    * not return until the connection is closed.
    *
-   * If %TRUE is returned then no other handlers are called.
-   **/
+   * Returns: %TRUE to stop further signal handlers from being called
+   */
   g_threaded_socket_service_run_signal =
     g_signal_new ("run", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GThreadedSocketServiceClass, run),
                  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);
 
   g_object_class_install_property (gobject_class, PROP_MAX_THREADS,
@@ -257,13 +246,16 @@ g_threaded_socket_service_class_init (GThreadedSocketServiceClass *class)
 
 /**
  * g_threaded_socket_service_new:
- * @returns: a new #GSocketService.
  * @max_threads: the maximal number of threads to execute concurrently
- *   handling incomming clients, -1 means no limit
+ *   handling incoming clients, -1 means no limit
+ *
+ * Creates a new #GThreadedSocketService with no listeners. Listeners
+ * must be added with one of the #GSocketListener "add" methods.
+ *
+ * Returns: a new #GSocketService.
  *
- * Creates a new #GThreadedSocketService with no listeners.  Listeners
- * must be added with g_socket_service_add_listeners().
- **/
+ * Since: 2.22
+ */
 GSocketService *
 g_threaded_socket_service_new (int max_threads)
 {
@@ -271,6 +263,3 @@ g_threaded_socket_service_new (int max_threads)
                       "max-threads", max_threads,
                       NULL);
 }
-
-#define __G_THREADED_SOCKET_SERVICE_C__
-#include "gioaliasdef.c"