Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1780

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/kernel/qsocketnotifier.cpp:45 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QSocketNotifier Class</title>
<style type="text/css"><!--
h3.fn,span.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>QSocketNotifier Class Reference</h1>

<p>The QSocketNotifier class provides support for socket callbacks.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsocketnotifier-h.html">qsocketnotifier.h</a>&gt;</tt>
<p>Inherits <a href="qobject.html">QObject</a>.
<p><a href="qsocketnotifier-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn>enum <a href="#Type-enum"><b>Type</b></a> { Read, Write, Exception }</div></li>
<li><div 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 )</div></li>
<li><div class=fn><a href="#~QSocketNotifier"><b>~QSocketNotifier</b></a> ()</div></li>
<li><div class=fn>int <a href="#socket"><b>socket</b></a> () const</div></li>
<li><div class=fn>Type <a href="#type"><b>type</b></a> () const</div></li>
<li><div class=fn>bool <a href="#isEnabled"><b>isEnabled</b></a> () const</div></li>
<li><div class=fn>virtual void <a href="#setEnabled"><b>setEnabled</b></a> ( bool&nbsp;enable )</div></li>
</ul>
<h2>Signals</h2>
<ul>
<li><div class=fn>void <a href="#activated"><b>activated</b></a> ( int&nbsp;socket )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QSocketNotifier class provides support for socket callbacks.
<p> 
<p> This class makes it possible to write asynchronous socket-based code
in Qt.  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> 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> QSocketNotifier::Read - There is data to be read (socket read event).
<li> QSocketNotifier::Write - Data can be written (socket write event).
<li> QSocketNofifier::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> Example:
<pre>
    int sockfd;                                 // socket identifier
    struct sockaddr_in sa;                      // should contain host address
    sockfd = <a href="#socket">socket</a>( AF_INET, SOCK_STREAM, 0 ); // create TCP socket
    // make the socket non-blocking here, usually using fcntl( O_NONBLOCK )
    ::connect( sockfd, (struct sockaddr*)&amp;sa,   // connect to host
               sizeof(sa) );                    //   NOT QObject::connect()!
    QSocketNotifier *sn;
    sn = new QSocketNotifier( sockfd, QSocketNotifier::<a href="#Type-enum">Read</a>, parent );
    QObject::<a href="qobject.html#connect">connect</a>( sn, SIGNAL(<a href="#activated">activated</a>(int)),
                      myObject, SLOT(dataReceived()) );
  </pre>
 
<p> The optional <em>parent</em> argument can be set to make the socket notifier a
child of any <a href="qobject.html">QObject</a>, e.g. a widget, thus being automatically destroyed
when the widget is destroyed.
<p> For read notifiers it makes little sense to connect the <a href="#activated">activated</a>()
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> If you disable the read notifier your program may deadlock. (The
same applies to exception notifiers if you have to use them, for
instance if you <em>have</em> to use TCP urgent data.)
<p> For write notifiers, immediately disable the notifier after the
activated() 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 <a href="#activated">activated</a>() 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="qobject.html#startTimer">timer events</a> or the <a href="qtimer.html">QTimer</a> class.
<p> Socket action is detected in the <a href="qapplication.html#exec">main event
  loop</a> of Qt.  The X11 version of Qt 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="qsocket.html">QSocket</a>, <a href="qserversocket.html">QServerSocket</a>, <a href="qsocketdevice.html">QSocketDevice</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>QSocketNotifier::Type</h3> 
<ul>
<li><tt>QSocketNotifier::Read</tt>
<li><tt>QSocketNotifier::Write</tt>
<li><tt>QSocketNotifier::Exception</tt>
</ul>
<hr><h2>Member Function Documentation</h2>
<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 )
</h3>  Constructs a socket notifier with the <em>parent</em> and the <em>name</em> that
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="~QSocketNotifier"></a>QSocketNotifier::~QSocketNotifier ()
</h3>
Destroys the socket notifier.

<h3 class=fn>void <a name="activated"></a>QSocketNotifier::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> QSocketNotifier::Read - There is data to be read (socket read event).
<li> QSocketNotifier::Write - Data can be written (socket write event).
<li> QSocketNofifier::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>QSocketNotifier::isEnabled () const
</h3>

Returns TRUE if the notifier is enabled; otherwise returns FALSE.
<p>See also <a href="#setEnabled">setEnabled</a>().

<h3 class=fn>void <a name="setEnabled"></a>QSocketNotifier::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 class description above.
<p> <p>See also <a href="#isEnabled">isEnabled</a>() and <a href="#activated">activated</a>().

<h3 class=fn>int <a name="socket"></a>QSocketNotifier::socket () const
</h3>

Returns the socket identifier specified to the constructor.
<p>See also <a href="#type">type</a>().

<h3 class=fn><a href="qsocketnotifier.html#Type-enum">Type</a> <a name="type"></a>QSocketNotifier::type () const
</h3>

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>.
<p>See also <a href="#socket">socket</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<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; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>