Imported Upstream version 2.50.2
[platform/upstream/glib.git] / docs / reference / gio / html / GSocketService.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GSocketService: GIO Reference Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="highlevel-socket.html" title="High-level network functionallity">
9 <link rel="prev" href="GSocketListener.html" title="GSocketListener">
10 <link rel="next" href="GThreadedSocketService.html" title="GThreadedSocketService">
11 <meta name="generator" content="GTK-Doc V1.25.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
16 <td width="100%" align="left" class="shortcuts">
17 <a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
18                   <a href="#GSocketService.description" class="shortcut">Description</a></span><span id="nav_hierarchy">  <span class="dim">|</span> 
19                   <a href="#GSocketService.object-hierarchy" class="shortcut">Object Hierarchy</a></span><span id="nav_properties">  <span class="dim">|</span> 
20                   <a href="#GSocketService.properties" class="shortcut">Properties</a></span><span id="nav_signals">  <span class="dim">|</span> 
21                   <a href="#GSocketService.signals" class="shortcut">Signals</a></span>
22 </td>
23 <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
24 <td><a accesskey="u" href="highlevel-socket.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
25 <td><a accesskey="p" href="GSocketListener.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
26 <td><a accesskey="n" href="GThreadedSocketService.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
27 </tr></table>
28 <div class="refentry">
29 <a name="GSocketService"></a><div class="titlepage"></div>
30 <div class="refnamediv"><table width="100%"><tr>
31 <td valign="top">
32 <h2><span class="refentrytitle"><a name="GSocketService.top_of_page"></a>GSocketService</span></h2>
33 <p>GSocketService — Make it easy to implement a network service</p>
34 </td>
35 <td class="gallery_image" valign="top" align="right"></td>
36 </tr></table></div>
37 <div class="refsect1">
38 <a name="GSocketService.functions"></a><h2>Functions</h2>
39 <div class="informaltable"><table class="informaltable" width="100%" border="0">
40 <colgroup>
41 <col width="150px" class="functions_return">
42 <col class="functions_name">
43 </colgroup>
44 <tbody>
45 <tr>
46 <td class="function_type">
47 <a class="link" href="GSocketService.html" title="GSocketService"><span class="returnvalue">GSocketService</span></a> *
48 </td>
49 <td class="function_name">
50 <a class="link" href="GSocketService.html#g-socket-service-new" title="g_socket_service_new ()">g_socket_service_new</a> <span class="c_punctuation">()</span>
51 </td>
52 </tr>
53 <tr>
54 <td class="function_type">
55 <span class="returnvalue">void</span>
56 </td>
57 <td class="function_name">
58 <a class="link" href="GSocketService.html#g-socket-service-start" title="g_socket_service_start ()">g_socket_service_start</a> <span class="c_punctuation">()</span>
59 </td>
60 </tr>
61 <tr>
62 <td class="function_type">
63 <span class="returnvalue">void</span>
64 </td>
65 <td class="function_name">
66 <a class="link" href="GSocketService.html#g-socket-service-stop" title="g_socket_service_stop ()">g_socket_service_stop</a> <span class="c_punctuation">()</span>
67 </td>
68 </tr>
69 <tr>
70 <td class="function_type">
71 <a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
72 </td>
73 <td class="function_name">
74 <a class="link" href="GSocketService.html#g-socket-service-is-active" title="g_socket_service_is_active ()">g_socket_service_is_active</a> <span class="c_punctuation">()</span>
75 </td>
76 </tr>
77 </tbody>
78 </table></div>
79 </div>
80 <div class="refsect1">
81 <a name="GSocketService.properties"></a><h2>Properties</h2>
82 <div class="informaltable"><table class="informaltable" border="0">
83 <colgroup>
84 <col width="150px" class="properties_type">
85 <col width="300px" class="properties_name">
86 <col width="200px" class="properties_flags">
87 </colgroup>
88 <tbody><tr>
89 <td class="property_type"><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></td>
90 <td class="property_name"><a class="link" href="GSocketService.html#GSocketService--active" title="The “active” property">active</a></td>
91 <td class="property_flags">Read / Write / Construct</td>
92 </tr></tbody>
93 </table></div>
94 </div>
95 <div class="refsect1">
96 <a name="GSocketService.signals"></a><h2>Signals</h2>
97 <div class="informaltable"><table class="informaltable" border="0">
98 <colgroup>
99 <col width="150px" class="signals_return">
100 <col width="300px" class="signals_name">
101 <col width="200px" class="signals_flags">
102 </colgroup>
103 <tbody><tr>
104 <td class="signal_type"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a></td>
105 <td class="signal_name"><a class="link" href="GSocketService.html#GSocketService-incoming" title="The “incoming” signal">incoming</a></td>
106 <td class="signal_flags"><a href="../gobject-Signals.html#G-SIGNAL-RUN-LAST:CAPS">Run Last</a></td>
107 </tr></tbody>
108 </table></div>
109 </div>
110 <div class="refsect1">
111 <a name="GSocketService.other"></a><h2>Types and Values</h2>
112 <div class="informaltable"><table class="informaltable" width="100%" border="0">
113 <colgroup>
114 <col width="150px" class="name">
115 <col class="description">
116 </colgroup>
117 <tbody><tr>
118 <td class="datatype_keyword"> </td>
119 <td class="function_name"><a class="link" href="GSocketService.html#GSocketService-struct" title="GSocketService">GSocketService</a></td>
120 </tr></tbody>
121 </table></div>
122 </div>
123 <div class="refsect1">
124 <a name="GSocketService.object-hierarchy"></a><h2>Object Hierarchy</h2>
125 <pre class="screen">    <a href="../gobject-The-Base-Object-Type.html#GObject-struct">GObject</a>
126     <span class="lineart">╰──</span> <a class="link" href="GSocketListener.html" title="GSocketListener">GSocketListener</a>
127         <span class="lineart">╰──</span> GSocketService
128             <span class="lineart">╰──</span> <a class="link" href="GThreadedSocketService.html" title="GThreadedSocketService">GThreadedSocketService</a>
129 </pre>
130 </div>
131 <div class="refsect1">
132 <a name="GSocketService.includes"></a><h2>Includes</h2>
133 <pre class="synopsis">#include &lt;gio/gio.h&gt;
134 </pre>
135 </div>
136 <div class="refsect1">
137 <a name="GSocketService.description"></a><h2>Description</h2>
138 <p>A <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> is an object that represents a service that
139 is provided to the network or over local sockets.  When a new
140 connection is made to the service the <a class="link" href="GSocketService.html#GSocketService-incoming" title="The “incoming” signal"><span class="type">“incoming”</span></a>
141 signal is emitted.</p>
142 <p>A <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> is a subclass of <a class="link" href="GSocketListener.html" title="GSocketListener"><span class="type">GSocketListener</span></a> and you need
143 to add the addresses you want to accept connections on with the
144 <a class="link" href="GSocketListener.html" title="GSocketListener"><span class="type">GSocketListener</span></a> APIs.</p>
145 <p>There are two options for implementing a network service based on
146 <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>. The first is to create the service using
147 <a class="link" href="GSocketService.html#g-socket-service-new" title="g_socket_service_new ()"><code class="function">g_socket_service_new()</code></a> and to connect to the <a class="link" href="GSocketService.html#GSocketService-incoming" title="The “incoming” signal"><span class="type">“incoming”</span></a>
148 signal. The second is to subclass <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> and override the
149 default signal handler implementation.</p>
150 <p>In either case, the handler must immediately return, or else it
151 will block additional incoming connections from being serviced.
152 If you are interested in writing connection handlers that contain
153 blocking code then see <a class="link" href="GThreadedSocketService.html" title="GThreadedSocketService"><span class="type">GThreadedSocketService</span></a>.</p>
154 <p>The socket service runs on the main loop of the 
155 thread-default context
156 of the thread it is created in, and is not
157 threadsafe in general. However, the calls to start and stop the
158 service are thread-safe so these can be used from threads that
159 handle incoming clients.</p>
160 </div>
161 <div class="refsect1">
162 <a name="GSocketService.functions_details"></a><h2>Functions</h2>
163 <div class="refsect2">
164 <a name="g-socket-service-new"></a><h3>g_socket_service_new ()</h3>
165 <pre class="programlisting"><a class="link" href="GSocketService.html" title="GSocketService"><span class="returnvalue">GSocketService</span></a> *
166 g_socket_service_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
167 <p>Creates a new <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> with no sockets to listen for.
168 New listeners can be added with e.g. <a class="link" href="GSocketListener.html#g-socket-listener-add-address" title="g_socket_listener_add_address ()"><code class="function">g_socket_listener_add_address()</code></a>
169 or <a class="link" href="GSocketListener.html#g-socket-listener-add-inet-port" title="g_socket_listener_add_inet_port ()"><code class="function">g_socket_listener_add_inet_port()</code></a>.</p>
170 <p>New services are created active, there is no need to call
171 <a class="link" href="GSocketService.html#g-socket-service-start" title="g_socket_service_start ()"><code class="function">g_socket_service_start()</code></a>, unless <a class="link" href="GSocketService.html#g-socket-service-stop" title="g_socket_service_stop ()"><code class="function">g_socket_service_stop()</code></a> has been
172 called before.</p>
173 <div class="refsect3">
174 <a name="g-socket-service-new.returns"></a><h4>Returns</h4>
175 <p> a new <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>.</p>
176 </div>
177 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
178 </div>
179 <hr>
180 <div class="refsect2">
181 <a name="g-socket-service-start"></a><h3>g_socket_service_start ()</h3>
182 <pre class="programlisting"><span class="returnvalue">void</span>
183 g_socket_service_start (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);</pre>
184 <p>Restarts the service, i.e. start accepting connections
185 from the added sockets when the mainloop runs. This only needs
186 to be called after the service has been stopped from
187 <a class="link" href="GSocketService.html#g-socket-service-stop" title="g_socket_service_stop ()"><code class="function">g_socket_service_stop()</code></a>.</p>
188 <p>This call is thread-safe, so it may be called from a thread
189 handling an incoming client request.</p>
190 <div class="refsect3">
191 <a name="g-socket-service-start.parameters"></a><h4>Parameters</h4>
192 <div class="informaltable"><table class="informaltable" width="100%" border="0">
193 <colgroup>
194 <col width="150px" class="parameters_name">
195 <col class="parameters_description">
196 <col width="200px" class="parameters_annotations">
197 </colgroup>
198 <tbody><tr>
199 <td class="parameter_name"><p>service</p></td>
200 <td class="parameter_description"><p>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a></p></td>
201 <td class="parameter_annotations"> </td>
202 </tr></tbody>
203 </table></div>
204 </div>
205 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
206 </div>
207 <hr>
208 <div class="refsect2">
209 <a name="g-socket-service-stop"></a><h3>g_socket_service_stop ()</h3>
210 <pre class="programlisting"><span class="returnvalue">void</span>
211 g_socket_service_stop (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);</pre>
212 <p>Stops the service, i.e. stops accepting connections
213 from the added sockets when the mainloop runs.</p>
214 <p>This call is thread-safe, so it may be called from a thread
215 handling an incoming client request.</p>
216 <p>Note that this only stops accepting new connections; it does not
217 close the listening sockets, and you can call
218 <a class="link" href="GSocketService.html#g-socket-service-start" title="g_socket_service_start ()"><code class="function">g_socket_service_start()</code></a> again later to begin listening again. To
219 close the listening sockets, call <a class="link" href="GSocketListener.html#g-socket-listener-close" title="g_socket_listener_close ()"><code class="function">g_socket_listener_close()</code></a>. (This
220 will happen automatically when the <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> is finalized.)</p>
221 <p>This must be called before calling <a class="link" href="GSocketListener.html#g-socket-listener-close" title="g_socket_listener_close ()"><code class="function">g_socket_listener_close()</code></a> as
222 the socket service will start accepting connections immediately
223 when a new socket is added.</p>
224 <div class="refsect3">
225 <a name="g-socket-service-stop.parameters"></a><h4>Parameters</h4>
226 <div class="informaltable"><table class="informaltable" width="100%" border="0">
227 <colgroup>
228 <col width="150px" class="parameters_name">
229 <col class="parameters_description">
230 <col width="200px" class="parameters_annotations">
231 </colgroup>
232 <tbody><tr>
233 <td class="parameter_name"><p>service</p></td>
234 <td class="parameter_description"><p>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a></p></td>
235 <td class="parameter_annotations"> </td>
236 </tr></tbody>
237 </table></div>
238 </div>
239 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
240 </div>
241 <hr>
242 <div class="refsect2">
243 <a name="g-socket-service-is-active"></a><h3>g_socket_service_is_active ()</h3>
244 <pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
245 g_socket_service_is_active (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);</pre>
246 <p>Check whether the service is active or not. An active
247 service will accept new clients that connect, while
248 a non-active service will let connecting clients queue
249 up until the service is started.</p>
250 <div class="refsect3">
251 <a name="g-socket-service-is-active.parameters"></a><h4>Parameters</h4>
252 <div class="informaltable"><table class="informaltable" width="100%" border="0">
253 <colgroup>
254 <col width="150px" class="parameters_name">
255 <col class="parameters_description">
256 <col width="200px" class="parameters_annotations">
257 </colgroup>
258 <tbody><tr>
259 <td class="parameter_name"><p>service</p></td>
260 <td class="parameter_description"><p>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a></p></td>
261 <td class="parameter_annotations"> </td>
262 </tr></tbody>
263 </table></div>
264 </div>
265 <div class="refsect3">
266 <a name="g-socket-service-is-active.returns"></a><h4>Returns</h4>
267 <p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the service is active, <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> otherwise</p>
268 </div>
269 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
270 </div>
271 </div>
272 <div class="refsect1">
273 <a name="GSocketService.other_details"></a><h2>Types and Values</h2>
274 <div class="refsect2">
275 <a name="GSocketService-struct"></a><h3>GSocketService</h3>
276 <pre class="programlisting">typedef struct _GSocketService GSocketService;</pre>
277 <p>A helper class for handling accepting incomming connections in the
278 glib mainloop.</p>
279 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
280 </div>
281 </div>
282 <div class="refsect1">
283 <a name="GSocketService.property-details"></a><h2>Property Details</h2>
284 <div class="refsect2">
285 <a name="GSocketService--active"></a><h3>The <code class="literal">“active”</code> property</h3>
286 <pre class="programlisting">  “active”                   <a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></pre>
287 <p>Whether the service is currently accepting connections.</p>
288 <p>Flags: Read / Write / Construct</p>
289 <p>Default value: TRUE</p>
290 <p class="since">Since: <a class="link" href="api-index-2-46.html#api-index-2.46">2.46</a></p>
291 </div>
292 </div>
293 <div class="refsect1">
294 <a name="GSocketService.signal-details"></a><h2>Signal Details</h2>
295 <div class="refsect2">
296 <a name="GSocketService-incoming"></a><h3>The <code class="literal">“incoming”</code> signal</h3>
297 <pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
298 user_function (<a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>    *service,
299                <a class="link" href="GSocketConnection.html" title="GSocketConnection"><span class="type">GSocketConnection</span></a> *connection,
300                <a href="../gobject-The-Base-Object-Type.html#GObject-struct"><span class="type">GObject</span></a>           *source_object,
301                <a href="../glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a>           user_data)</pre>
302 <p>The ::incoming signal is emitted when a new incoming connection
303 to <em class="parameter"><code>service</code></em>
304  needs to be handled. The handler must initiate the
305 handling of <em class="parameter"><code>connection</code></em>
306 , but may not block; in essence,
307 asynchronous operations must be used.</p>
308 <p><em class="parameter"><code>connection</code></em>
309  will be unreffed once the signal handler returns,
310 so you need to ref it yourself if you are planning to use it.</p>
311 <div class="refsect3">
312 <a name="GSocketService-incoming.parameters"></a><h4>Parameters</h4>
313 <div class="informaltable"><table class="informaltable" width="100%" border="0">
314 <colgroup>
315 <col width="150px" class="parameters_name">
316 <col class="parameters_description">
317 <col width="200px" class="parameters_annotations">
318 </colgroup>
319 <tbody>
320 <tr>
321 <td class="parameter_name"><p>service</p></td>
322 <td class="parameter_description"><p>the <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a></p></td>
323 <td class="parameter_annotations"> </td>
324 </tr>
325 <tr>
326 <td class="parameter_name"><p>connection</p></td>
327 <td class="parameter_description"><p>a new <a class="link" href="GSocketConnection.html" title="GSocketConnection"><span class="type">GSocketConnection</span></a> object</p></td>
328 <td class="parameter_annotations"> </td>
329 </tr>
330 <tr>
331 <td class="parameter_name"><p>source_object</p></td>
332 <td class="parameter_description"><p> the source_object passed to
333 <a class="link" href="GSocketListener.html#g-socket-listener-add-address" title="g_socket_listener_add_address ()"><code class="function">g_socket_listener_add_address()</code></a>. </p></td>
334 <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
335 </tr>
336 <tr>
337 <td class="parameter_name"><p>user_data</p></td>
338 <td class="parameter_description"><p>user data set when the signal handler was connected.</p></td>
339 <td class="parameter_annotations"> </td>
340 </tr>
341 </tbody>
342 </table></div>
343 </div>
344 <div class="refsect3">
345 <a name="GSocketService-incoming.returns"></a><h4>Returns</h4>
346 <p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> to stop other handlers from being called</p>
347 </div>
348 <p>Flags: <a href="../gobject-Signals.html#G-SIGNAL-RUN-LAST:CAPS">Run Last</a></p>
349 <p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
350 </div>
351 </div>
352 <div class="refsect1">
353 <a name="GSocketService.see-also"></a><h2>See Also</h2>
354 <p><a class="link" href="GThreadedSocketService.html" title="GThreadedSocketService"><span class="type">GThreadedSocketService</span></a>, <a class="link" href="GSocketListener.html" title="GSocketListener"><span class="type">GSocketListener</span></a>.</p>
355 </div>
356 </div>
357 <div class="footer">
358 <hr>Generated by GTK-Doc V1.25.1</div>
359 </body>
360 </html>