[glibmm] Wrap ThreadedSocketService



commit f71905d3dc4098b3a71451b4b1886e8169ee2969
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Sat Jan 2 22:39:09 2010 -0600

    Wrap ThreadedSocketService

 gio/src/filelist.am                       |    1 +
 gio/src/gio_signals.defs                  |   30 +++++++++++++
 gio/src/threadedsocketservice.ccg         |   24 ++++++++++
 gio/src/threadedsocketservice.hg          |   67 +++++++++++++++++++++++++++++
 tools/extra_defs_gen/generate_defs_gio.cc |    1 +
 5 files changed, 123 insertions(+), 0 deletions(-)
---
diff --git a/gio/src/filelist.am b/gio/src/filelist.am
index 9ceb12b..544c223 100644
--- a/gio/src/filelist.am
+++ b/gio/src/filelist.am
@@ -62,6 +62,7 @@ giomm_files_any_hg =			\
 	socketservice.hg		\
 	srvtarget.hg			\
 	tcpconnection.hg			\
+	threadedsocketservice.hg	\
 	themedicon.hg			\
 	volume.hg			\
 	volumemonitor.hg
diff --git a/gio/src/gio_signals.defs b/gio/src/gio_signals.defs
index b516305..c9d23a2 100644
--- a/gio/src/gio_signals.defs
+++ b/gio/src/gio_signals.defs
@@ -1108,4 +1108,34 @@
   (construct-only #f)
 )
 
+;; From GThreadedSocketService
+
+(define-signal run
+  (of-object "GThreadedSocketService")
+  (return-type "gboolean")
+  (when "last")
+  (parameters
+    '("GSocketConnection*" "p0")
+    '("GObject*" "p1")
+  )
+)
+
+(define-property listen-backlog
+  (of-object "GThreadedSocketService")
+  (prop-type "GParamInt")
+  (docs "outstanding connections in the listen queue")
+  (readable #t)
+  (writable #t)
+  (construct-only #f)
+)
+
+(define-property max-threads
+  (of-object "GThreadedSocketService")
+  (prop-type "GParamInt")
+  (docs "The max number of threads handling clients for this service")
+  (readable #t)
+  (writable #t)
+  (construct-only #t)
+)
+
 
diff --git a/gio/src/threadedsocketservice.ccg b/gio/src/threadedsocketservice.ccg
new file mode 100644
index 0000000..6e07769
--- /dev/null
+++ b/gio/src/threadedsocketservice.ccg
@@ -0,0 +1,24 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+} // namespace Gio
diff --git a/gio/src/threadedsocketservice.hg b/gio/src/threadedsocketservice.hg
new file mode 100644
index 0000000..234b65f
--- /dev/null
+++ b/gio/src/threadedsocketservice.hg
@@ -0,0 +1,67 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <giomm/socketservice.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(giomm/private/socketservice_p.h)
+
+namespace Gio
+{
+
+/** @defgroup NetworkIO Portable Network I/O Functionality
+ */
+
+/**
+ * A threaded GSocketService
+ *
+ * A ThreadedSocketService is a simple subclass of SocketService
+ * that handles incoming connections by creating a worker thread and
+ * dispatching the connection to it by emitting the ::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.
+ * The service automatically stops the SocketService from accepting
+ * new connections when all threads are busy.
+ *
+ * As with SocketService, you may connect to ThreadedSocketService:run,
+ * or subclass and override the default handler.
+ *
+ * @newin{2,24}
+ * @ingroup NetworkIO
+ */
+class ThreadedSocketService : public Gio::SocketService
+{
+    _CLASS_GOBJECT(ThreadedSocketService, GThreadedSocketService, G_THREADED_SOCKET_SERVICE, Gio::SocketService, GSocketService)
+
+protected:
+    _WRAP_CTOR(ThreadedSocketService(int max_threads), g_threaded_socket_service_new)
+
+public:
+    _WRAP_CREATE(int max_threads)
+
+    _WRAP_SIGNAL(bool run(const Glib::RefPtr<SocketConnection>& connection, const Glib::RefPtr<Glib::Object>& source_object), "run")
+    _WRAP_PROPERTY("max-threads", int)
+};
+
+} // namespace Gio
diff --git a/tools/extra_defs_gen/generate_defs_gio.cc b/tools/extra_defs_gen/generate_defs_gio.cc
index e873c4f..6ae378b 100644
--- a/tools/extra_defs_gen/generate_defs_gio.cc
+++ b/tools/extra_defs_gen/generate_defs_gio.cc
@@ -89,6 +89,7 @@ int main(int, char**)
             << get_defs(G_TYPE_UNIX_CONNECTION)
             << get_defs(G_TYPE_SOCKET_LISTENER)
             << get_defs(G_TYPE_SOCKET_SERVICE)
+            << get_defs(G_TYPE_THREADED_SOCKET_SERVICE)
 
             << std::endl;
   



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]