~ubuntu-branches/ubuntu/saucy/glib2.0/saucy-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GIO Reference Manual: GSocketService</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GIO Reference Manual">
<link rel="up" href="highlevel-socket.html" title="High-level network functionallity">
<link rel="prev" href="GSocketListener.html" title="GSocketListener">
<link rel="next" href="GThreadedSocketService.html" title="GThreadedSocketService">
<meta name="generator" content="GTK-Doc V1.19.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="10"><tr valign="middle">
<td width="100%" align="left">
<a href="#" class="shortcut">Top</a>
                   | 
                  <a href="#GSocketService.description" class="shortcut">Description</a>
                   | 
                  <a href="#GSocketService.object-hierarchy" class="shortcut">Object Hierarchy</a>
                   | 
                  <a href="#GSocketService.signals" class="shortcut">Signals</a>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="highlevel-socket.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="GSocketListener.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="GThreadedSocketService.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="GSocketService"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="GSocketService.top_of_page"></a>GSocketService</span></h2>
<p>GSocketService — Make it easy to implement a network service</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="GSocketService.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">                    <a class="link" href="GSocketService.html#GSocketService-struct" title="GSocketService">GSocketService</a>;
<a class="link" href="GSocketService.html" title="GSocketService"><span class="returnvalue">GSocketService</span></a> *    <a class="link" href="GSocketService.html#g-socket-service-new" title="g_socket_service_new ()">g_socket_service_new</a>                (<em class="parameter"><code><span class="type">void</span></code></em>);
<span class="returnvalue">void</span>                <a class="link" href="GSocketService.html#g-socket-service-start" title="g_socket_service_start ()">g_socket_service_start</a>              (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="GSocketService.html#g-socket-service-stop" title="g_socket_service_stop ()">g_socket_service_stop</a>               (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);
<a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="GSocketService.html#g-socket-service-is-active" title="g_socket_service_is_active ()">g_socket_service_is_active</a>          (<em class="parameter"><code><a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> *service</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="GSocketService.object-hierarchy"></a><h2>Object Hierarchy</h2>
<pre class="synopsis">
  <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject">GObject</a>
   +----<a class="link" href="GSocketListener.html" title="GSocketListener">GSocketListener</a>
         +----GSocketService
               +----<a class="link" href="GThreadedSocketService.html" title="GThreadedSocketService">GThreadedSocketService</a>
</pre>
</div>
<div class="refsect1">
<a name="GSocketService.signals"></a><h2>Signals</h2>
<pre class="synopsis">
  "<a class="link" href="GSocketService.html#GSocketService-incoming" title='The "incoming" signal'>incoming</a>"                                       : <a href="http://library.gnome.org/devel/gobject/unstable/gobject-Signals.html#G-SIGNAL-RUN-LAST:CAPS"><code class="literal">Run Last</code></a>
</pre>
</div>
<div class="refsect1">
<a name="GSocketService.description"></a><h2>Description</h2>
<p>
A <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> 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 <a class="link" href="GSocketService.html#GSocketService-incoming" title='The "incoming" signal'><span class="type">"incoming"</span></a>
signal is emitted.
</p>
<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
to add the addresses you want to accept connections on with the
<a class="link" href="GSocketListener.html" title="GSocketListener"><span class="type">GSocketListener</span></a> APIs.
</p>
<p>
There are two options for implementing a network service based on
<a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>. The first is to create the service using
<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>
signal. The second is to subclass <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> and override the
default signal handler implementation.
</p>
<p>
In either case, the handler must immediately return, or else it
will block additional incoming connections from being serviced.
If you are interested in writing connection handlers that contain
blocking code then see <a class="link" href="GThreadedSocketService.html" title="GThreadedSocketService"><span class="type">GThreadedSocketService</span></a>.
</p>
<p>
The socket service runs on the main loop of the <GTKDOCLINK HREF="g-main-context-push-thread-default-context">thread-default
context</GTKDOCLINK> 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.
</p>
</div>
<div class="refsect1">
<a name="GSocketService.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GSocketService-struct"></a><h3>GSocketService</h3>
<pre class="programlisting">typedef struct _GSocketService GSocketService;</pre>
<p>
A helper class for handling accepting incomming connections in the
glib mainloop.
</p>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-service-new"></a><h3>g_socket_service_new ()</h3>
<pre class="programlisting"><a class="link" href="GSocketService.html" title="GSocketService"><span class="returnvalue">GSocketService</span></a> *    g_socket_service_new                (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> with no sockets to listen for.
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>
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>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a new <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>.</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-service-start"></a><h3>g_socket_service_start ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                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>
<p>
Starts the service, i.e. start accepting connections
from the added sockets when the mainloop runs.
</p>
<p>
This call is thread-safe, so it may be called from a thread
handling an incoming client request.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>service</code></em> :</span></p></td>
<td>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>
</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-service-stop"></a><h3>g_socket_service_stop ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                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>
<p>
Stops the service, i.e. stops accepting connections
from the added sockets when the mainloop runs.
</p>
<p>
This call is thread-safe, so it may be called from a thread
handling an incoming client request.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>service</code></em> :</span></p></td>
<td>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>
</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-service-is-active"></a><h3>g_socket_service_is_active ()</h3>
<pre class="programlisting"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            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>
<p>
Check whether the service is active or not. An active
service will accept new clients that connect, while
a non-active service will let connecting clients queue
up until the service is started.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>service</code></em> :</span></p></td>
<td>a <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the service is active, <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> otherwise</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
</div>
<div class="refsect1">
<a name="GSocketService.signal-details"></a><h2>Signal Details</h2>
<div class="refsect2">
<a name="GSocketService-incoming"></a><h3>The <code class="literal">"incoming"</code> signal</h3>
<pre class="programlisting"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            user_function                      (<a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>    *service,
                                                        <a class="link" href="GSocketConnection.html" title="GSocketConnection"><span class="type">GSocketConnection</span></a> *connection,
                                                        <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a>           *source_object,
                                                        <a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a>           user_data)          : <a href="http://library.gnome.org/devel/gobject/unstable/gobject-Signals.html#G-SIGNAL-RUN-LAST:CAPS"><code class="literal">Run Last</code></a></pre>
<p>
The ::incoming signal is emitted when a new incoming connection
to <em class="parameter"><code>service</code></em> needs to be handled. The handler must initiate the
handling of <em class="parameter"><code>connection</code></em>, but may not block; in essence,
asynchronous operations must be used.
</p>
<p>
<em class="parameter"><code>connection</code></em> will be unreffed once the signal handler returns,
so you need to ref it yourself if you are planning to use it.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>service</code></em> :</span></p></td>
<td>the <a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>connection</code></em> :</span></p></td>
<td>a new <a class="link" href="GSocketConnection.html" title="GSocketConnection"><span class="type">GSocketConnection</span></a> object</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>source_object</code></em> :</span></p></td>
<td>the source_object passed to
<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>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>user data set when the signal handler was connected.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> to stop other handlers from being called</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
</div>
<div class="refsect1">
<a name="GSocketService.see-also"></a><h2>See Also</h2>
<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>.
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.19.1</div>
</body>
</html>