source: trunk/doc/html/qsocketnotifier.html@ 203

Last change on this file since 203 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.4 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qsocketnotifier.cpp:49 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSocketNotifier Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSocketNotifier Class Reference</h1>
33
34<p>The QSocketNotifier class provides support for socket callbacks.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qsocketnotifier-h.html">qsocketnotifier.h</a>&gt;</tt>
37<p>Inherits <a href="qobject.html">QObject</a>.
38<p><a href="qsocketnotifier-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn>enum <a href="#Type-enum"><b>Type</b></a> { Read, Write, Exception }</li>
42<li class=fn><a href="#QSocketNotifier"><b>QSocketNotifier</b></a> ( int&nbsp;socket, Type&nbsp;type, QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
43<li class=fn><a href="#~QSocketNotifier"><b>~QSocketNotifier</b></a> ()</li>
44<li class=fn>int <a href="#socket"><b>socket</b></a> () const</li>
45<li class=fn>Type <a href="#type"><b>type</b></a> () const</li>
46<li class=fn>bool <a href="#isEnabled"><b>isEnabled</b></a> () const</li>
47<li class=fn>virtual void <a href="#setEnabled"><b>setEnabled</b></a> ( bool&nbsp;enable )</li>
48</ul>
49<h2>Signals</h2>
50<ul>
51<li class=fn>void <a href="#activated"><b>activated</b></a> ( int&nbsp;socket )</li>
52</ul>
53<hr><a name="details"></a><h2>Detailed Description</h2>
54
55
56The QSocketNotifier class provides support for socket callbacks.
57<p>
58<p> This class makes it possible to write asynchronous socket-based
59code in Qt. Using synchronous socket operations blocks the
60program, which is clearly not acceptable for an event-driven GUI
61program.
62<p> Once you have opened a non-blocking socket (whether for TCP, UDP,
63a UNIX-domain socket, or any other protocol family your operating
64system supports), you can create a socket notifier to monitor the
65socket. Then you connect the <a href="#activated">activated</a>() signal to the slot you
66want to be called when a socket event occurs.
67<p> Note for Windows users: the socket passed to QSocketNotifier will
68become non-blocking, even if it was created as a blocking socket.
69<p> There are three types of socket notifiers (read, write and
70exception); you must specify one of these in the constructor.
71<p> The type specifies when the activated() signal is to be emitted:
72<ol type=1>
73<li> QSocketNotifier::Read - There is data to be read (socket read event).
74<li> QSocketNotifier::Write - Data can be written (socket write event).
75<li> QSocketNofifier::Exception - An exception has occurred (socket
76exception event). We recommend against using this.
77</ol>
78<p> For example, if you need to monitor both reads and writes for the
79same socket you must create two socket notifiers.
80<p> For read notifiers it makes little sense to connect the
81activated() signal to more than one slot because the data can be
82read from the socket only once.
83<p> Also observe that if you do not read all the available data when
84the read notifier fires, it fires again and again.
85<p> For write notifiers, immediately disable the notifier after the
86<a href="#activated">activated</a>() signal has been received and you have sent the data to
87be written on the socket. When you have more data to be written,
88enable it again to get a new activated() signal. The exception is
89if the socket data writing operation (send() or equivalent) fails
90with a "would block" error, which means that some buffer is full
91and you must wait before sending more data. In that case you do
92not need to disable and re-enable the write notifier; it will fire
93again as soon as the system allows more data to be sent.
94<p> The behavior of a write notifier that is left in enabled state
95after having emitting the first activated() signal (and no "would
96block" error has occurred) is undefined. Depending on the
97operating system, it may fire on every pass of the event loop or
98not at all.
99<p> If you need a time-out for your sockets you can use either <a href="qobject.html#startTimer">timer events</a> or the <a href="qtimer.html">QTimer</a> class.
100<p> Socket action is detected in the <a href="qapplication.html#exec">main
101 event loop</a> of Qt. The X11 version of Qt has a single UNIX
102select() call that incorporates all socket notifiers and the X
103socket.
104<p> Note that on XFree86 for OS/2, select() works only in the thread
105in which main() is running; you should therefore use that thread
106for GUI operations.
107<p> <p>See also <a href="qsocket.html">QSocket</a>, <a href="qserversocket.html">QServerSocket</a>, <a href="qsocketdevice.html">QSocketDevice</a>, <a href="qfile.html#handle">QFile::handle</a>(), and <a href="io.html">Input/Output and Networking</a>.
108
109<hr><h2>Member Type Documentation</h2>
110<h3 class=fn><a name="Type-enum"></a>QSocketNotifier::Type</h3>
111
112<ul>
113<li><tt>QSocketNotifier::Read</tt>
114<li><tt>QSocketNotifier::Write</tt>
115<li><tt>QSocketNotifier::Exception</tt>
116</ul>
117<hr><h2>Member Function Documentation</h2>
118<h3 class=fn><a name="QSocketNotifier"></a>QSocketNotifier::QSocketNotifier ( int&nbsp;socket, <a href="qsocketnotifier.html#Type-enum">Type</a>&nbsp;type, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
119</h3>
120Constructs a socket notifier called <em>name</em>, with the parent, <em>parent</em>. It watches <em>socket</em> for <em>type</em> events, and enables it.
121<p> It is generally advisable to explicitly enable or disable the
122socket notifier, especially for write notifiers.
123<p> <p>See also <a href="#setEnabled">setEnabled</a>() and <a href="#isEnabled">isEnabled</a>().
124
125<h3 class=fn><a name="~QSocketNotifier"></a>QSocketNotifier::~QSocketNotifier ()
126</h3>
127Destroys the socket notifier.
128
129<h3 class=fn>void <a name="activated"></a>QSocketNotifier::activated ( int&nbsp;socket )<tt> [signal]</tt>
130</h3>
131
132<p> This signal is emitted under certain conditions specified by the
133notifier <a href="#type">type</a>():
134<ol type=1>
135<li> QSocketNotifier::Read - There is data to be read (socket read event).
136<li> QSocketNotifier::Write - Data can be written (socket write event).
137<li> QSocketNofifier::Exception - An exception has occurred (socket
138exception event).
139</ol>
140<p> The <em>socket</em> argument is the <a href="#socket">socket</a> identifier.
141<p> <p>See also <a href="#type">type</a>() and <a href="#socket">socket</a>().
142
143<h3 class=fn>bool <a name="isEnabled"></a>QSocketNotifier::isEnabled () const
144</h3>
145
146<p> Returns TRUE if the notifier is enabled; otherwise returns FALSE.
147<p> <p>See also <a href="#setEnabled">setEnabled</a>().
148
149<h3 class=fn>void <a name="setEnabled"></a>QSocketNotifier::setEnabled ( bool&nbsp;enable )<tt> [virtual]</tt>
150</h3>
151Enables the notifier if <em>enable</em> is TRUE or disables it if <em>enable</em> is FALSE.
152<p> The notifier is enabled by default.
153<p> If the notifier is enabled, it emits the <a href="#activated">activated</a>() signal
154whenever a socket event corresponding to its <a href="#type">type</a> occurs. If it is disabled, it ignores socket events
155(the same effect as not creating the socket notifier).
156<p> Write notifiers should normally be disabled immediately after the
157activated() signal has been emitted; see discussion of write
158notifiers in the <a href="#details">class description</a> above.
159<p> <p>See also <a href="#isEnabled">isEnabled</a>() and <a href="#activated">activated</a>().
160
161<h3 class=fn>int <a name="socket"></a>QSocketNotifier::socket () const
162</h3>
163
164<p> Returns the socket identifier specified to the constructor.
165<p> <p>See also <a href="#type">type</a>().
166
167<h3 class=fn><a href="qsocketnotifier.html#Type-enum">Type</a> <a name="type"></a>QSocketNotifier::type () const
168</h3>
169
170<p> Returns the socket event type specified to the constructor: <a href="#Type-enum">QSocketNotifier::Read</a>, <a href="#Type-enum">QSocketNotifier::Write</a>, or <a href="#Type-enum">QSocketNotifier::Exception</a>.
171<p> <p>See also <a href="#socket">socket</a>().
172
173<!-- eof -->
174<hr><p>
175This file is part of the <a href="index.html">Qt toolkit</a>.
176Copyright &copy; 1995-2007
177<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
178<table width=100% cellspacing=0 border=0><tr>
179<td>Copyright &copy; 2007
180<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
181<td align=right><div align=right>Qt 3.3.8</div>
182</table></div></address></body>
183</html>
Note: See TracBrowser for help on using the repository browser.