File: classWt_1_1WSocketNotifier.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (221 lines) | stat: -rw-r--r-- 15,958 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt: Wt::WSocketNotifier Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceWt.html">Wt</a>::<a class="el" href="classWt_1_1WSocketNotifier.html">WSocketNotifier</a>
  </div>
</div>
<div class="contents">
<h1>Wt::WSocketNotifier Class Reference</h1><!-- doxytag: class="Wt::WSocketNotifier" --><!-- doxytag: inherits="Wt::WObject" -->A utility class for asynchronous notification of socket activity.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WSocketNotifier&gt;</code>
<p>
<div class="dynheader">
Inheritance diagram for Wt::WSocketNotifier:</div>
<div class="dynsection">
<p><center><img src="classWt_1_1WSocketNotifier__inherit__graph.png" border="0" usemap="#Wt_1_1WSocketNotifier__inherit__map" alt="Inheritance graph"></center>
<map name="Wt_1_1WSocketNotifier__inherit__map">
<area shape="rect" href="classWt_1_1WObject.html" title="A base class for objects that participate in the signal/slot system." alt="" coords="27,5,123,32"></map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="classWt_1_1WSocketNotifier-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Types</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">enum &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">Type</a> { <a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c057d53943ca8e7e9381526747c689d1c">Read</a>, 
<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c85abb8bd7445d145faa84c8545b1d5f4">Write</a>, 
<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c17c50ed02a1f9aa67ece3d5e71b66141">Exception</a>
 }</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Enumeration that event type.  <a href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">More...</a><br></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#e60a2f36b909f50404bfb15864562347">WSocketNotifier</a> (int socket, <a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">Type</a> type, <a class="el" href="classWt_1_1WObject.html">WObject</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates a new socket notifier.  <a href="#e60a2f36b909f50404bfb15864562347"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ff88999b1c55254f8b129193a53ee485"></a><!-- doxytag: member="Wt::WSocketNotifier::~WSocketNotifier" ref="ff88999b1c55254f8b129193a53ee485" args="()" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#ff88999b1c55254f8b129193a53ee485">~WSocketNotifier</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructor. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="3a1bde7ddf5a3bdde74906343027e355"></a><!-- doxytag: member="Wt::WSocketNotifier::socket" ref="3a1bde7ddf5a3bdde74906343027e355" args="() const " -->
int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#3a1bde7ddf5a3bdde74906343027e355">socket</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the socket. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="42d21d0c22cdf3b3ed7ee10dbdc82aed"></a><!-- doxytag: member="Wt::WSocketNotifier::type" ref="42d21d0c22cdf3b3ed7ee10dbdc82aed" args="() const " -->
<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">Type</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#42d21d0c22cdf3b3ed7ee10dbdc82aed">type</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the event type. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#9cb21fa4b5827a205b21f9b656baca6d">setEnabled</a> (bool enabled)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Enables or disable the notifier.  <a href="#9cb21fa4b5827a205b21f9b656baca6d"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="893c8fcee0191bb2ae56df27697f8f7c"></a><!-- doxytag: member="Wt::WSocketNotifier::isEnabled" ref="893c8fcee0191bb2ae56df27697f8f7c" args="() const " -->
bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#893c8fcee0191bb2ae56df27697f8f7c">isEnabled</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns if the notifier is enabled. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="classWt_1_1Signal.html">Signal</a>&lt; int &gt; &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WSocketNotifier.html#cf78fc846ca6f915111533575dcc9401">activated</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Signal indicating an event.  <a href="#cf78fc846ca6f915111533575dcc9401"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
A utility class for asynchronous notification of socket activity. 
<p>
Use a aocket notifier to integrate listening for socket events into the Wt event loop. In this way, you do not need a separate thread to listen for socket activity. Socket activity is either the availability of data to be read (<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c057d53943ca8e7e9381526747c689d1c">Read event</a>), possibility to write data (<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c85abb8bd7445d145faa84c8545b1d5f4">Write event</a>), or an exception that occurred (<a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c17c50ed02a1f9aa67ece3d5e71b66141">Exception event</a>).<p>
When an event on a socket is available, the notifier emits the <a class="el" href="classWt_1_1WSocketNotifier.html#cf78fc846ca6f915111533575dcc9401" title="Signal indicating an event.">activated()</a> signal. As in the case of a user interface event (like for example <a class="el" href="classWt_1_1WInteractWidget.html#e11e050cce0d4a8f742afa3ef92bfe8c" title="Event signal emitted when a mouse key was clicked on this widget.">WInteractWidget::clicked()</a>), you will typically modify the widget tree in response to the event. But, unless you use a timer (<a class="el" href="classWt_1_1WTimer.html" title="A utility class which provides timer signals and single-shot timers.">WTimer</a>) or use server-initiated updates (see WApplication::triggerUpdates()), these changes are not propagated to the user interface, until the next user interface event.<p>
Like other events, socket notification events are serial (not simultaneous), and there are no thread safety issues (you don't need to call <a class="el" href="classWt_1_1WApplication.html#c7582c37defc49b5e8d6ccbda3b68d45" title="Grabs and returns the lock for manipulating widgets outside the event loop.">WApplication::getUpdateLock()</a> to get an update lock).<p>
<div class="fragment"><pre class="fragment"> <a class="code" href="classWt_1_1WSocketNotifier.html" title="A utility class for asynchronous notification of socket activity.">Wt::WSocketNotifier</a> *notifier_;

 <span class="keywordtype">void</span> init() {
   ...
   <span class="keywordtype">int</span> sock = ...
   notifier_ = <span class="keyword">new</span> <a class="code" href="classWt_1_1WSocketNotifier.html" title="A utility class for asynchronous notification of socket activity.">Wt::WSocketNotifier</a>(sock, <a class="code" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c057d53943ca8e7e9381526747c689d1c" title="Ready to read.">Wt::WSocketNotifier::Read</a>, <span class="keyword">this</span>);
   notifier_-&gt;<a class="code" href="classWt_1_1WSocketNotifier.html#cf78fc846ca6f915111533575dcc9401" title="Signal indicating an event.">activated</a>().connect(SLOT(<span class="keyword">this</span>, HelloApplication::readData));
 }

 <span class="keywordtype">void</span> readData() {
   <span class="comment">// data is available on socket, or socket was closed by peer</span>
   <span class="keywordtype">char</span> buf[100];
   <span class="keywordtype">int</span> s = read(notifier_-&gt;<a class="code" href="classWt_1_1WSocketNotifier.html#3a1bde7ddf5a3bdde74906343027e355" title="Returns the socket.">socket</a>(), buf, 99);

   <span class="keywordflow">if</span> (s &gt; 0) {
     ...
   } <span class="keywordflow">else</span> {
     <span class="comment">// closed by peer</span>
     notifier_-&gt;<a class="code" href="classWt_1_1WSocketNotifier.html#9cb21fa4b5827a205b21f9b656baca6d" title="Enables or disable the notifier.">setEnabled</a>(<span class="keyword">false</span>);
     close(notifier_-&gt;<a class="code" href="classWt_1_1WSocketNotifier.html#3a1bde7ddf5a3bdde74906343027e355" title="Returns the socket.">socket</a>());
   }
 }
</pre></div><p>
<em>Note: At present, <a class="el" href="classWt_1_1WSocketNotifier.html" title="A utility class for asynchronous notification of socket activity.">WSocketNotifier</a> works only in conjunction with the wthttpd connector, and not when using the FastCGI connector.</em> <hr><h2>Member Enumeration Documentation</h2>
<a class="anchor" name="5be2fe0fe94d449a0d6b1ac77f7b548c"></a><!-- doxytag: member="Wt::WSocketNotifier::Type" ref="5be2fe0fe94d449a0d6b1ac77f7b548c" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">Wt::WSocketNotifier::Type</a>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Enumeration that event type. 
<p>
<dl compact><dt><b>Enumerator: </b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><em><a class="anchor" name="5be2fe0fe94d449a0d6b1ac77f7b548c057d53943ca8e7e9381526747c689d1c"></a><!-- doxytag: member="Read" ref="5be2fe0fe94d449a0d6b1ac77f7b548c057d53943ca8e7e9381526747c689d1c" args="" -->Read</em>&nbsp;</td><td>
Ready to read. </td></tr>
<tr><td valign="top"><em><a class="anchor" name="5be2fe0fe94d449a0d6b1ac77f7b548c85abb8bd7445d145faa84c8545b1d5f4"></a><!-- doxytag: member="Write" ref="5be2fe0fe94d449a0d6b1ac77f7b548c85abb8bd7445d145faa84c8545b1d5f4" args="" -->Write</em>&nbsp;</td><td>
Ready to write. </td></tr>
<tr><td valign="top"><em><a class="anchor" name="5be2fe0fe94d449a0d6b1ac77f7b548c17c50ed02a1f9aa67ece3d5e71b66141"></a><!-- doxytag: member="Exception" ref="5be2fe0fe94d449a0d6b1ac77f7b548c17c50ed02a1f9aa67ece3d5e71b66141" args="" -->Exception</em>&nbsp;</td><td>
Exception. </td></tr>
</table>
</dl>

</div>
</div><p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="e60a2f36b909f50404bfb15864562347"></a><!-- doxytag: member="Wt::WSocketNotifier::WSocketNotifier" ref="e60a2f36b909f50404bfb15864562347" args="(int socket, Type type, WObject *parent=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::WSocketNotifier::WSocketNotifier           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>socket</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classWt_1_1WSocketNotifier.html#5be2fe0fe94d449a0d6b1ac77f7b548c">Type</a>&nbsp;</td>
          <td class="paramname"> <em>type</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classWt_1_1WObject.html">WObject</a> *&nbsp;</td>
          <td class="paramname"> <em>parent</em> = <code>0</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Creates a new socket notifier. 
<p>
Create a new socket listener to listen for events of given <code>type</code> on a socket with file descriptor <code>socket</code>. 
</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="9cb21fa4b5827a205b21f9b656baca6d"></a><!-- doxytag: member="Wt::WSocketNotifier::setEnabled" ref="9cb21fa4b5827a205b21f9b656baca6d" args="(bool enabled)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WSocketNotifier::setEnabled           </td>
          <td>(</td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>enabled</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Enables or disable the notifier. 
<p>
By default, the socket notifier is enabled to receive events. When disabled, no events will be notified (as if the socket notifier didn't exist). 
</div>
</div><p>
<a class="anchor" name="cf78fc846ca6f915111533575dcc9401"></a><!-- doxytag: member="Wt::WSocketNotifier::activated" ref="cf78fc846ca6f915111533575dcc9401" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Signal.html">Signal</a>&lt;int&gt;&amp; Wt::WSocketNotifier::activated           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Signal indicating an event. 
<p>
The signal is emitted when an event that was waited for is available. The signal argument is <a class="el" href="classWt_1_1WSocketNotifier.html#3a1bde7ddf5a3bdde74906343027e355" title="Returns the socket.">socket()</a>. 
</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:07 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>