1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = GThreadedSocketService.html 27 * outPack = gio 28 * outFile = ThreadedSocketService 29 * strct = GThreadedSocketService 30 * realStrct= 31 * ctorStrct=GSocketService 32 * clss = ThreadedSocketService 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_threaded_socket_service_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * structWrap: 47 * module aliases: 48 * local aliases: 49 * overrides: 50 */ 51 52 module gio.ThreadedSocketService; 53 54 public import gtkc.giotypes; 55 56 private import gtkc.gio; 57 private import glib.ConstructionException; 58 private import gobject.ObjectG; 59 60 private import gobject.Signals; 61 public import gtkc.gdktypes; 62 63 64 65 66 private import gio.SocketService; 67 68 /** 69 * Description 70 * A GThreadedSocketService is a simple subclass of GSocketService 71 * that handles incoming connections by creating a worker thread and 72 * dispatching the connection to it by emitting the ::run signal in 73 * the new thread. 74 * The signal handler may perform blocking IO and need not return 75 * until the connection is closed. 76 * The service is implemented using a thread pool, so there is a 77 * limited amount of threads availible to serve incomming requests. 78 * The service automatically stops the GSocketService from accepting 79 * new connections when all threads are busy. 80 * As with GSocketService, you may connect to "run", 81 * or subclass and override the default handler. 82 */ 83 public class ThreadedSocketService : SocketService 84 { 85 86 /** the main Gtk struct */ 87 protected GThreadedSocketService* gThreadedSocketService; 88 89 90 public GThreadedSocketService* getThreadedSocketServiceStruct() 91 { 92 return gThreadedSocketService; 93 } 94 95 96 /** the main Gtk struct as a void* */ 97 protected override void* getStruct() 98 { 99 return cast(void*)gThreadedSocketService; 100 } 101 102 /** 103 * Sets our main struct and passes it to the parent class 104 */ 105 public this (GThreadedSocketService* gThreadedSocketService) 106 { 107 super(cast(GSocketService*)gThreadedSocketService); 108 this.gThreadedSocketService = gThreadedSocketService; 109 } 110 111 protected override void setStruct(GObject* obj) 112 { 113 super.setStruct(obj); 114 gThreadedSocketService = cast(GThreadedSocketService*)obj; 115 } 116 117 /** 118 */ 119 int[string] connectedSignals; 120 121 bool delegate(GSocketConnection*, GObject*, ThreadedSocketService)[] onRunListeners; 122 /** 123 * The ::run signal is emitted in a worker thread in response to an 124 * incoming connection. This thread is dedicated to handling 125 * connection and may perform blocking IO. The signal handler need 126 * not return until the connection is closed. 127 * TRUE to stope further signal handlers from being called 128 * See Also 129 * GSocketService. 130 */ 131 void addOnRun(bool delegate(GSocketConnection*, GObject*, ThreadedSocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 132 { 133 if ( !("run" in connectedSignals) ) 134 { 135 Signals.connectData( 136 getStruct(), 137 "run", 138 cast(GCallback)&callBackRun, 139 cast(void*)this, 140 null, 141 connectFlags); 142 connectedSignals["run"] = 1; 143 } 144 onRunListeners ~= dlg; 145 } 146 extern(C) static gboolean callBackRun(GThreadedSocketService* serviceStruct, GSocketConnection* connection, GObject* sourceObject, ThreadedSocketService _threadedSocketService) 147 { 148 foreach ( bool delegate(GSocketConnection*, GObject*, ThreadedSocketService) dlg ; _threadedSocketService.onRunListeners ) 149 { 150 if ( dlg(connection, sourceObject, _threadedSocketService) ) 151 { 152 return 1; 153 } 154 } 155 156 return 0; 157 } 158 159 160 /** 161 * Creates a new GThreadedSocketService with no listeners. Listeners 162 * must be added with g_socket_service_add_listeners(). 163 * Since 2.22 164 * Params: 165 * maxThreads = the maximal number of threads to execute concurrently 166 * handling incoming clients, -1 means no limit 167 * Throws: ConstructionException GTK+ fails to create the object. 168 */ 169 public this (int maxThreads) 170 { 171 // GSocketService * g_threaded_socket_service_new (int max_threads); 172 auto p = g_threaded_socket_service_new(maxThreads); 173 if(p is null) 174 { 175 throw new ConstructionException("null returned by g_threaded_socket_service_new(maxThreads)"); 176 } 177 this(cast(GThreadedSocketService*) p); 178 } 179 }