You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/tqsocketnotifier.html

184 lines
9.2 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/tqsocketnotifier.cpp:49 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQSocketNotifier Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQSocketNotifier Class Reference</h1>
<p>The TQSocketNotifier class provides support for socket callbacks.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="tqsocketnotifier-h.html">tqsocketnotifier.h</a>&gt;</tt>
<p>Inherits <a href="tqobject.html">TQObject</a>.
<p><a href="tqsocketnotifier-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>enum <a href="#Type-enum"><b>Type</b></a> { Read, Write, Exception }</li>
<li class=fn><a href="#TQSocketNotifier"><b>TQSocketNotifier</b></a> ( int&nbsp;socket, Type&nbsp;type, TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#~TQSocketNotifier"><b>~TQSocketNotifier</b></a> ()</li>
<li class=fn>int <a href="#socket"><b>socket</b></a> () const</li>
<li class=fn>Type <a href="#type"><b>type</b></a> () const</li>
<li class=fn>bool <a href="#isEnabled"><b>isEnabled</b></a> () const</li>
<li class=fn>virtual void <a href="#setEnabled"><b>setEnabled</b></a> ( bool&nbsp;enable )</li>
</ul>
<h2>Signals</h2>
<ul>
<li class=fn>void <a href="#activated"><b>activated</b></a> ( int&nbsp;socket )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The TQSocketNotifier class provides support for socket callbacks.
<p>
<p> This class makes it possible to write asynchronous socket-based
code in TQt. Using synchronous socket operations blocks the
program, which is clearly not acceptable for an event-driven GUI
program.
<p> Once you have opened a non-blocking socket (whether for TCP, UDP,
a UNIX-domain socket, or any other protocol family your operating
system supports), you can create a socket notifier to monitor the
socket. Then you connect the <a href="#activated">activated</a>() signal to the slot you
want to be called when a socket event occurs.
<p> Note for Windows users: the socket passed to TQSocketNotifier will
become non-blocking, even if it was created as a blocking socket.
<p> There are three types of socket notifiers (read, write and
exception); you must specify one of these in the constructor.
<p> The type specifies when the activated() signal is to be emitted:
<ol type=1>
<li> TQSocketNotifier::Read - There is data to be read (socket read event).
<li> TQSocketNotifier::Write - Data can be written (socket write event).
<li> TQSocketNofifier::Exception - An exception has occurred (socket
exception event). We recommend against using this.
</ol>
<p> For example, if you need to monitor both reads and writes for the
same socket you must create two socket notifiers.
<p> For read notifiers it makes little sense to connect the
activated() signal to more than one slot because the data can be
read from the socket only once.
<p> Also observe that if you do not read all the available data when
the read notifier fires, it fires again and again.
<p> For write notifiers, immediately disable the notifier after the
<a href="#activated">activated</a>() signal has been received and you have sent the data to
be written on the socket. When you have more data to be written,
enable it again to get a new activated() signal. The exception is
if the socket data writing operation (send() or equivalent) fails
with a "would block" error, which means that some buffer is full
and you must wait before sending more data. In that case you do
not need to disable and re-enable the write notifier; it will fire
again as soon as the system allows more data to be sent.
<p> The behavior of a write notifier that is left in enabled state
after having emitting the first activated() signal (and no "would
block" error has occurred) is undefined. Depending on the
operating system, it may fire on every pass of the event loop or
not at all.
<p> If you need a time-out for your sockets you can use either <a href="tqobject.html#startTimer">timer events</a> or the <a href="tqtimer.html">TQTimer</a> class.
<p> Socket action is detected in the <a href="ntqapplication.html#exec">main
event loop</a> of TQt. The X11 version of TQt has a single UNIX
select() call that incorporates all socket notifiers and the X
socket.
<p> Note that on XFree86 for OS/2, select() works only in the thread
in which main() is running; you should therefore use that thread
for GUI operations.
<p> <p>See also <a href="tqsocket.html">TQSocket</a>, <a href="tqserversocket.html">TQServerSocket</a>, <a href="tqsocketdevice.html">TQSocketDevice</a>, <a href="tqfile.html#handle">TQFile::handle</a>(), and <a href="io.html">Input/Output and Networking</a>.
<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="Type-enum"></a>TQSocketNotifier::Type</h3>
<ul>
<li><tt>TQSocketNotifier::Read</tt>
<li><tt>TQSocketNotifier::Write</tt>
<li><tt>TQSocketNotifier::Exception</tt>
</ul>
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQSocketNotifier"></a>TQSocketNotifier::TQSocketNotifier ( int&nbsp;socket, <a href="tqsocketnotifier.html#Type-enum">Type</a>&nbsp;type, <a href="tqobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Constructs 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.
<p> It is generally advisable to explicitly enable or disable the
socket notifier, especially for write notifiers.
<p> <p>See also <a href="#setEnabled">setEnabled</a>() and <a href="#isEnabled">isEnabled</a>().
<h3 class=fn><a name="~TQSocketNotifier"></a>TQSocketNotifier::~TQSocketNotifier ()
</h3>
Destroys the socket notifier.
<h3 class=fn>void <a name="activated"></a>TQSocketNotifier::activated ( int&nbsp;socket )<tt> [signal]</tt>
</h3>
<p> This signal is emitted under certain conditions specified by the
notifier <a href="#type">type</a>():
<ol type=1>
<li> TQSocketNotifier::Read - There is data to be read (socket read event).
<li> TQSocketNotifier::Write - Data can be written (socket write event).
<li> TQSocketNofifier::Exception - An exception has occurred (socket
exception event).
</ol>
<p> The <em>socket</em> argument is the <a href="#socket">socket</a> identifier.
<p> <p>See also <a href="#type">type</a>() and <a href="#socket">socket</a>().
<h3 class=fn>bool <a name="isEnabled"></a>TQSocketNotifier::isEnabled () const
</h3>
<p> Returns TRUE if the notifier is enabled; otherwise returns FALSE.
<p> <p>See also <a href="#setEnabled">setEnabled</a>().
<h3 class=fn>void <a name="setEnabled"></a>TQSocketNotifier::setEnabled ( bool&nbsp;enable )<tt> [virtual]</tt>
</h3>
Enables the notifier if <em>enable</em> is TRUE or disables it if <em>enable</em> is FALSE.
<p> The notifier is enabled by default.
<p> If the notifier is enabled, it emits the <a href="#activated">activated</a>() signal
whenever a socket event corresponding to its <a href="#type">type</a> occurs. If it is disabled, it ignores socket events
(the same effect as not creating the socket notifier).
<p> Write notifiers should normally be disabled immediately after the
activated() signal has been emitted; see discussion of write
notifiers in the <a href="#details">class description</a> above.
<p> <p>See also <a href="#isEnabled">isEnabled</a>() and <a href="#activated">activated</a>().
<h3 class=fn>int <a name="socket"></a>TQSocketNotifier::socket () const
</h3>
<p> Returns the socket identifier specified to the constructor.
<p> <p>See also <a href="#type">type</a>().
<h3 class=fn><a href="tqsocketnotifier.html#Type-enum">Type</a> <a name="type"></a>TQSocketNotifier::type () const
</h3>
<p> Returns the socket event type specified to the constructor: <a href="#Type-enum">TQSocketNotifier::Read</a>, <a href="#Type-enum">TQSocketNotifier::Write</a>, or <a href="#Type-enum">TQSocketNotifier::Exception</a>.
<p> <p>See also <a href="#socket">socket</a>().
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>