~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/q3socketdevice.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/qt3support/network/q3socketdevice.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: Q3SocketDevice Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">Q3SocketDevice Class Reference</h1>
 
21
<p>The Q3SocketDevice class provides a platform-independent low-level socket API. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;Q3SocketDevice&gt;</pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See the <a href="porting4.html">Porting Guide</a> for more information.</p>
 
23
<p>Part of the <a href="qt3support.html">Qt3Support</a> module.</p>
 
24
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p>
 
25
<ul>
 
26
<li><a href="q3socketdevice-members.html">List of all members, including inherited members</a></li>
 
27
</ul>
 
28
<a name="public-types"></a>
 
29
<h3>Public Types</h3>
 
30
<ul>
 
31
<li><div class="fn"/>enum <b><a href="q3socketdevice.html#Error-enum">Error</a></b> { NoError, AlreadyBound, Inaccessible, NoResources, ..., UnknownError }</li>
 
32
<li><div class="fn"/>enum <b><a href="q3socketdevice.html#Protocol-enum">Protocol</a></b> { IPv4, IPv6, Unknown }</li>
 
33
<li><div class="fn"/>enum <b><a href="q3socketdevice.html#Type-enum">Type</a></b> { Stream, Datagram }</li>
 
34
</ul>
 
35
<a name="public-functions"></a>
 
36
<h3>Public Functions</h3>
 
37
<ul>
 
38
<li><div class="fn"/><b><a href="q3socketdevice.html#Q3SocketDevice">Q3SocketDevice</a></b> ( Type <i>type</i> = Stream )</li>
 
39
<li><div class="fn"/><b><a href="q3socketdevice.html#Q3SocketDevice-2">Q3SocketDevice</a></b> ( Type <i>type</i>, Protocol <i>protocol</i>, int <i>dummy</i> )</li>
 
40
<li><div class="fn"/><b><a href="q3socketdevice.html#Q3SocketDevice-3">Q3SocketDevice</a></b> ( int <i>socket</i>, Type <i>type</i> )</li>
 
41
<li><div class="fn"/>virtual <b><a href="q3socketdevice.html#dtor.Q3SocketDevice">~Q3SocketDevice</a></b> ()</li>
 
42
<li><div class="fn"/>virtual int <b><a href="q3socketdevice.html#accept">accept</a></b> ()</li>
 
43
<li><div class="fn"/>QHostAddress <b><a href="q3socketdevice.html#address">address</a></b> () const</li>
 
44
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#addressReusable">addressReusable</a></b> () const</li>
 
45
<li><div class="fn"/>Offset <b><a href="q3socketdevice.html#at">at</a></b> () const</li>
 
46
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#at-2">at</a></b> ( Offset <i>offset</i> )</li>
 
47
<li><div class="fn"/>virtual bool <b><a href="q3socketdevice.html#bind">bind</a></b> ( const QHostAddress &amp; <i>address</i>, Q_UINT16 <i>port</i> )</li>
 
48
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#blocking">blocking</a></b> () const</li>
 
49
<li><div class="fn"/>virtual qint64 <b><a href="q3socketdevice.html#bytesAvailable">bytesAvailable</a></b> () const</li>
 
50
<li><div class="fn"/>virtual bool <b><a href="q3socketdevice.html#connect">connect</a></b> ( const QHostAddress &amp; <i>addr</i>, Q_UINT16 <i>port</i> )</li>
 
51
<li><div class="fn"/>Error <b><a href="q3socketdevice.html#error">error</a></b> () const</li>
 
52
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#flush">flush</a></b> ()</li>
 
53
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#isValid">isValid</a></b> () const</li>
 
54
<li><div class="fn"/>virtual bool <b><a href="q3socketdevice.html#listen">listen</a></b> ( int <i>backlog</i> )</li>
 
55
<li><div class="fn"/>bool <b><a href="q3socketdevice.html#open">open</a></b> ( int <i>mode</i> )</li>
 
56
<li><div class="fn"/>QHostAddress <b><a href="q3socketdevice.html#peerAddress">peerAddress</a></b> () const</li>
 
57
<li><div class="fn"/>Q_UINT16 <b><a href="q3socketdevice.html#peerPort">peerPort</a></b> () const</li>
 
58
<li><div class="fn"/>Q_UINT16 <b><a href="q3socketdevice.html#port">port</a></b> () const</li>
 
59
<li><div class="fn"/>Protocol <b><a href="q3socketdevice.html#protocol">protocol</a></b> () const</li>
 
60
<li><div class="fn"/>qint64 <b><a href="q3socketdevice.html#readBlock">readBlock</a></b> ( char * <i>data</i>, Q_ULONG <i>maxlen</i> )</li>
 
61
<li><div class="fn"/>int <b><a href="q3socketdevice.html#receiveBufferSize">receiveBufferSize</a></b> () const</li>
 
62
<li><div class="fn"/>int <b><a href="q3socketdevice.html#sendBufferSize">sendBufferSize</a></b> () const</li>
 
63
<li><div class="fn"/>virtual void <b><a href="q3socketdevice.html#setAddressReusable">setAddressReusable</a></b> ( bool <i>enable</i> )</li>
 
64
<li><div class="fn"/>virtual void <b><a href="q3socketdevice.html#setBlocking">setBlocking</a></b> ( bool <i>enable</i> )</li>
 
65
<li><div class="fn"/>virtual void <b><a href="q3socketdevice.html#setReceiveBufferSize">setReceiveBufferSize</a></b> ( uint <i>size</i> )</li>
 
66
<li><div class="fn"/>virtual void <b><a href="q3socketdevice.html#setSendBufferSize">setSendBufferSize</a></b> ( uint <i>size</i> )</li>
 
67
<li><div class="fn"/>virtual void <b><a href="q3socketdevice.html#setSocket">setSocket</a></b> ( int <i>socket</i>, Type <i>type</i> )</li>
 
68
<li><div class="fn"/>int <b><a href="q3socketdevice.html#socket">socket</a></b> () const</li>
 
69
<li><div class="fn"/>Type <b><a href="q3socketdevice.html#type">type</a></b> () const</li>
 
70
<li><div class="fn"/>Q_LONG <b><a href="q3socketdevice.html#waitForMore">waitForMore</a></b> ( int <i>msecs</i>, bool * <i>timeout</i> = 0 ) const</li>
 
71
<li><div class="fn"/>Q_LONG <b><a href="q3socketdevice.html#writeBlock">writeBlock</a></b> ( const char * <i>data</i>, Q_ULONG <i>len</i> )</li>
 
72
<li><div class="fn"/>virtual Q_LONG <b><a href="q3socketdevice.html#writeBlock-2">writeBlock</a></b> ( const char * <i>data</i>, Q_ULONG <i>len</i>, const QHostAddress &amp; <i>host</i>, Q_UINT16 <i>port</i> )</li>
 
73
</ul>
 
74
<ul>
 
75
<li><div class="fn"/>30 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
 
76
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
77
</ul>
 
78
<a name="protected-functions"></a>
 
79
<h3>Protected Functions</h3>
 
80
<ul>
 
81
<li><div class="fn"/>virtual qint64 <b><a href="q3socketdevice.html#readData">readData</a></b> ( char * <i>data</i>, qint64 <i>maxlen</i> )</li>
 
82
<li><div class="fn"/>void <b><a href="q3socketdevice.html#setError">setError</a></b> ( Error <i>err</i> )</li>
 
83
<li><div class="fn"/>virtual qint64 <b><a href="q3socketdevice.html#writeData">writeData</a></b> ( const char * <i>data</i>, qint64 <i>len</i> )</li>
 
84
</ul>
 
85
<ul>
 
86
<li><div class="fn"/>5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
 
87
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
88
</ul>
 
89
<h3>Additional Inherited Members</h3>
 
90
<ul>
 
91
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
92
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
93
<li><div class="fn"/>3 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
 
94
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
95
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
96
</ul>
 
97
<a name="details"></a>
 
98
<hr />
 
99
<h2>Detailed Description</h2>
 
100
<p>The Q3SocketDevice class provides a platform-independent low-level socket API.</p>
 
101
<p>This class provides a low level API for working with sockets. Users of this class are assumed to have networking experience. For most users the <a href="q3socket.html">Q3Socket</a> class provides a much easier and high level alternative, but certain things (like UDP) can't be done with <a href="q3socket.html">Q3Socket</a> and if you need a platform-independent API for those, Q3SocketDevice is the right choice.</p>
 
102
<p>The essential purpose of the class is to provide a <a href="qiodevice.html">QIODevice</a> that works on sockets, wrapped in a platform-independent API.</p>
 
103
<p>When calling <a href="q3socketdevice.html#connect">connect</a>() or <a href="q3socketdevice.html#bind">bind</a>(), Q3SocketDevice detects the protocol family (<a href="q3socketdevice.html#Protocol-enum">IPv4</a>, <a href="q3socketdevice.html#Protocol-enum">IPv6</a>) automatically. Passing the protocol family to Q3SocketDevice's constructor or to <a href="q3socketdevice.html#setSocket">setSocket</a>() forces creation of a socket device of a specific protocol. If not set, the protocol will be detected at the first call to <a href="q3socketdevice.html#connect">connect</a>() or <a href="q3socketdevice.html#bind">bind</a>().</p>
 
104
<p>See also <a href="q3socket.html">Q3Socket</a>, <a href="qsocketnotifier.html">QSocketNotifier</a>, and <a href="qhostaddress.html">QHostAddress</a>.</p>
 
105
<hr />
 
106
<h2>Member Type Documentation</h2>
 
107
<h3 class="fn"><a name="Error-enum"></a>enum Q3SocketDevice::Error</h3>
 
108
<p>This enum type describes the error states of <a href="q3socketdevice.html">Q3SocketDevice</a>.</p>
 
109
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
110
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
111
<tr><td valign="top"><tt>Q3SocketDevice::NoError</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">No error has occurred.</td></tr>
 
112
<tr><td valign="top"><tt>Q3SocketDevice::AlreadyBound</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The device is already bound, according to <a href="q3socketdevice.html#bind">bind</a>().</td></tr>
 
113
<tr><td valign="top"><tt>Q3SocketDevice::Inaccessible</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The operating system or firewall prohibited the action.</td></tr>
 
114
<tr><td valign="top"><tt>Q3SocketDevice::NoResources</tt></td><td align="center" valign="top"><tt>3</tt></td><td valign="top">The operating system ran out of a resource.</td></tr>
 
115
<tr><td valign="top"><tt>Q3SocketDevice::InternalError</tt></td><td align="center" valign="top"><tt>4</tt></td><td valign="top">An internal error occurred in <a href="q3socketdevice.html">Q3SocketDevice</a>.</td></tr>
 
116
<tr><td valign="top"><tt>Q3SocketDevice::Impossible</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">An attempt was made to do something which makes no sense. For example:<pre>&nbsp;   ::close( sd-&gt;socket() );
 
117
    sd-&gt;writeBlock( someData, 42 );</pre>
 
118
</td></tr>
 
119
</table>
 
120
<p>The libc ::close() closes the socket, but <a href="q3socketdevice.html">Q3SocketDevice</a> is not aware of this. So when you call <a href="q3socketdevice.html#writeBlock">writeBlock</a>(), the impossible happens.</p>
 
121
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
122
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
123
<tr><td valign="top"><tt>Q3SocketDevice::NoFiles</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">The operating system will not let <a href="q3socketdevice.html">Q3SocketDevice</a> open another file.</td></tr>
 
124
<tr><td valign="top"><tt>Q3SocketDevice::ConnectionRefused</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">A connection attempt was rejected by the peer.</td></tr>
 
125
<tr><td valign="top"><tt>Q3SocketDevice::NetworkFailure</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">There is a network failure.</td></tr>
 
126
<tr><td valign="top"><tt>Q3SocketDevice::UnknownError</tt></td><td align="center" valign="top">&nbsp;</td><td valign="top">The operating system did something unexpected.</td></tr>
 
127
</table>
 
128
<h3 class="fn"><a name="Protocol-enum"></a>enum Q3SocketDevice::Protocol</h3>
 
129
<p>This enum type describes the protocol family of the socket. Possible values are:</p>
 
130
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
131
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
132
<tr><td valign="top"><tt>Q3SocketDevice::IPv4</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">The socket is an IPv4 socket.</td></tr>
 
133
<tr><td valign="top"><tt>Q3SocketDevice::IPv6</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The socket is an IPv6 socket.</td></tr>
 
134
<tr><td valign="top"><tt>Q3SocketDevice::Unknown</tt></td><td align="center" valign="top"><tt>2</tt></td><td valign="top">The protocol family of the socket is not known. This can happen if you use <a href="q3socketdevice.html">Q3SocketDevice</a> with an already existing socket; it tries to determine the protocol family, but this can fail if the protocol family is not known to <a href="q3socketdevice.html">Q3SocketDevice</a>.</td></tr>
 
135
</table>
 
136
<p>See also <a href="q3socketdevice.html#protocol">protocol</a>() and <a href="q3socketdevice.html#setSocket">setSocket</a>().</p>
 
137
<h3 class="fn"><a name="Type-enum"></a>enum Q3SocketDevice::Type</h3>
 
138
<p>This enum type describes the type of the socket:</p>
 
139
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
140
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
141
<tr><td valign="top"><tt>Q3SocketDevice::Stream</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">a stream socket (TCP, usually)</td></tr>
 
142
<tr><td valign="top"><tt>Q3SocketDevice::Datagram</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">a datagram socket (UDP, usually)</td></tr>
 
143
</table>
 
144
<hr />
 
145
<h2>Member Function Documentation</h2>
 
146
<h3 class="fn"><a name="Q3SocketDevice"></a>Q3SocketDevice::Q3SocketDevice ( <a href="q3socketdevice.html#Type-enum">Type</a> <i>type</i> = Stream )</h3>
 
147
<p>Creates a <a href="q3socketdevice.html">Q3SocketDevice</a> object for a stream or datagram socket.</p>
 
148
<p>The <i>type</i> argument must be either <tt>Q3SocketDevice::Stream</tt> for a reliable, connection-oriented TCP socket, or <tt>Q3SocketDevice::Datagram</tt> for an unreliable UDP socket.</p>
 
149
<p>The socket is created as an <a href="q3socketdevice.html#Protocol-enum">IPv4</a> socket.</p>
 
150
<p>See also <a href="q3socketdevice.html#blocking">blocking</a>() and <a href="q3socketdevice.html#protocol">protocol</a>().</p>
 
151
<h3 class="fn"><a name="Q3SocketDevice-2"></a>Q3SocketDevice::Q3SocketDevice ( <a href="q3socketdevice.html#Type-enum">Type</a> <i>type</i>, <a href="q3socketdevice.html#Protocol-enum">Protocol</a> <i>protocol</i>, int <i>dummy</i> )</h3>
 
152
<p>Creates a <a href="q3socketdevice.html">Q3SocketDevice</a> object for a stream or datagram socket.</p>
 
153
<p>The <i>type</i> argument must be either <tt>Q3SocketDevice::Stream</tt> for a reliable, connection-oriented TCP socket, or <tt>Q3SocketDevice::Datagram</tt> for an unreliable UDP socket.</p>
 
154
<p>The <i>protocol</i> indicates whether the socket should be of type <a href="q3socketdevice.html#Protocol-enum">IPv4</a> or <a href="q3socketdevice.html#Protocol-enum">IPv6</a>. Passing <tt>Unknown</tt> is not meaningful in this context and you should avoid using (it creates an <a href="q3socketdevice.html#Protocol-enum">IPv4</a> socket, but your code is not easily readable).</p>
 
155
<p>The argument <i>dummy</i> is necessary for compatibility with some compilers.</p>
 
156
<p>See also <a href="q3socketdevice.html#blocking">blocking</a>() and <a href="q3socketdevice.html#protocol">protocol</a>().</p>
 
157
<h3 class="fn"><a name="Q3SocketDevice-3"></a>Q3SocketDevice::Q3SocketDevice ( int <i>socket</i>, <a href="q3socketdevice.html#Type-enum">Type</a> <i>type</i> )</h3>
 
158
<p>Creates a <a href="q3socketdevice.html">Q3SocketDevice</a> object for the existing socket <i>socket</i>.</p>
 
159
<p>The <i>type</i> argument must match the actual socket type; use <tt>Q3SocketDevice::Stream</tt> for a reliable, connection-oriented TCP socket, or <tt>Q3SocketDevice::Datagram</tt> for an unreliable, connectionless UDP socket.</p>
 
160
<h3 class="fn"><a name="dtor.Q3SocketDevice"></a>Q3SocketDevice::~Q3SocketDevice ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
161
<p>Destroys the socket device and closes the socket if it is open.</p>
 
162
<h3 class="fn"><a name="accept"></a>int Q3SocketDevice::accept ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
163
<p>Extracts the first connection from the queue of pending connections for this socket and returns a new socket identifier. Returns -1 if the operation failed.</p>
 
164
<p>See also <a href="q3socketdevice.html#bind">bind</a>() and <a href="q3socketdevice.html#listen">listen</a>().</p>
 
165
<h3 class="fn"><a name="address"></a><a href="qhostaddress.html">QHostAddress</a> Q3SocketDevice::address () const</h3>
 
166
<p>Returns the address of this socket device. This may be 0.0.0.0 for a while, but is set to something sensible as soon as a sensible value is available.</p>
 
167
<h3 class="fn"><a name="addressReusable"></a>bool Q3SocketDevice::addressReusable () const</h3>
 
168
<p>Returns true if the address of this socket can be used by other sockets at the same time, and false if this socket claims exclusive ownership.</p>
 
169
<p>See also <a href="q3socketdevice.html#setAddressReusable">setAddressReusable</a>().</p>
 
170
<h3 class="fn"><a name="at"></a><a href="qiodevice-qt3.html#Offset-typedef">Offset</a> Q3SocketDevice::at () const</h3>
 
171
<p>The read/write index is meaningless for a socket, therefore this function returns 0.</p>
 
172
<h3 class="fn"><a name="at-2"></a>bool Q3SocketDevice::at ( <a href="qiodevice-qt3.html#Offset-typedef">Offset</a> <i>offset</i> )</h3>
 
173
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
174
<p>The read/write index is meaningless for a socket, therefore this function does nothing and returns true.</p>
 
175
<p>The <i>offset</i> parameter is ignored.</p>
 
176
<h3 class="fn"><a name="bind"></a>bool Q3SocketDevice::bind ( const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>address</i>, <a href="qtglobal-qt3.html#Q_UINT16-typedef">Q_UINT16</a> <i>port</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
177
<p>Assigns a name to an unnamed socket. The name is the host address <i>address</i> and the port number <i>port</i>. If the operation succeeds, bind() returns true; otherwise it returns false without changing what <a href="q3socketdevice.html#port">port</a>() and <a href="q3socketdevice.html#address">address</a>() return.</p>
 
178
<p>bind() is used by servers for setting up incoming connections. Call bind() before <a href="q3socketdevice.html#listen">listen</a>().</p>
 
179
<h3 class="fn"><a name="blocking"></a>bool Q3SocketDevice::blocking () const</h3>
 
180
<p>Returns true if the socket is valid and in blocking mode; otherwise returns false.</p>
 
181
<p>Note that this function does not set <a href="q3socketdevice.html#error">error</a>().</p>
 
182
<p><b>Warning:</b> On Windows, this function always returns true since the ioctlsocket() function is broken.</p>
 
183
<p>See also <a href="q3socketdevice.html#setBlocking">setBlocking</a>() and <a href="q3socketdevice.html#isValid">isValid</a>().</p>
 
184
<h3 class="fn"><a name="bytesAvailable"></a><a href="qtglobal.html#qint64-typedef">qint64</a> Q3SocketDevice::bytesAvailable () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
185
<p>Returns the number of bytes available for reading, or -1 if an error occurred.</p>
 
186
<p><b>Warning:</b> On Microsoft Windows, we use the ioctlsocket() function to determine the number of bytes queued on the socket. According to Microsoft (KB Q125486), ioctlsocket() sometimes returns an incorrect number. The only safe way to determine the amount of data on the socket is to read it using <a href="q3socketdevice.html#readBlock">readBlock</a>(). QSocket has workarounds to deal with this problem.</p>
 
187
<p>Reimplemented from <a href="qiodevice.html#bytesAvailable">QIODevice</a>.</p>
 
188
<h3 class="fn"><a name="connect"></a>bool Q3SocketDevice::connect ( const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>addr</i>, <a href="qtglobal-qt3.html#Q_UINT16-typedef">Q_UINT16</a> <i>port</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
189
<p>Connects to the IP address and port specified by <i>addr</i> and <i>port</i>. Returns true if it establishes a connection; otherwise returns false. If it returns false, <a href="q3socketdevice.html#error">error</a>() explains why.</p>
 
190
<p>Note that <a href="q3socketdevice.html#error">error</a>() commonly returns <a href="q3socketdevice.html#Error-enum">NoError</a> for non-blocking sockets; this just means that you can call connect() again in a little while and it'll probably succeed.</p>
 
191
<h3 class="fn"><a name="error"></a><a href="q3socketdevice.html#Error-enum">Error</a> Q3SocketDevice::error () const</h3>
 
192
<p>Returns the first error seen.</p>
 
193
<h3 class="fn"><a name="flush"></a>bool Q3SocketDevice::flush ()</h3>
 
194
<p>The current <a href="q3socketdevice.html">Q3SocketDevice</a> implementation does not buffer at all, so this is a no-op.</p>
 
195
<h3 class="fn"><a name="isValid"></a>bool Q3SocketDevice::isValid () const</h3>
 
196
<p>Returns true if this is a valid socket; otherwise returns false.</p>
 
197
<p>See also <a href="q3socketdevice.html#socket">socket</a>().</p>
 
198
<h3 class="fn"><a name="listen"></a>bool Q3SocketDevice::listen ( int <i>backlog</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
199
<p>Specifies how many pending connections a server socket can have. Returns true if the operation was successful; otherwise returns false. A <i>backlog</i> value of 50 is quite common.</p>
 
200
<p>The listen() call only applies to sockets where <a href="q3socketdevice.html#type">type</a>() is <tt>Stream</tt>, i.e. not to <tt>Datagram</tt> sockets. listen() must not be called before <a href="q3socketdevice.html#bind">bind</a>() or after <a href="q3socketdevice.html#accept">accept</a>().</p>
 
201
<p>See also <a href="q3socketdevice.html#bind">bind</a>() and <a href="q3socketdevice.html#accept">accept</a>().</p>
 
202
<h3 class="fn"><a name="open"></a>bool Q3SocketDevice::open ( int <i>mode</i> )</h3>
 
203
<p>Opens the socket using the specified <a href="qiodevice.html">QIODevice</a> file <i>mode</i>. This function is called from the <a href="q3socketdevice.html">Q3SocketDevice</a> constructors and from the <a href="q3socketdevice.html#setSocket">setSocket</a>() function. You should not call it yourself.</p>
 
204
<p>See also <a href="q3socketdevice.html#close">close</a>().</p>
 
205
<h3 class="fn"><a name="peerAddress"></a><a href="qhostaddress.html">QHostAddress</a> Q3SocketDevice::peerAddress () const</h3>
 
206
<p>Returns the address of the port this socket device is connected to. This may be 0.0.0.0 for a while, but is set to something sensible as soon as a sensible value is available.</p>
 
207
<p>Note that for Datagram sockets, this is the source port of the last packet received.</p>
 
208
<h3 class="fn"><a name="peerPort"></a><a href="qtglobal-qt3.html#Q_UINT16-typedef">Q_UINT16</a> Q3SocketDevice::peerPort () const</h3>
 
209
<p>Returns the port number of the port this socket device is connected to. This may be 0 for a while, but is set to something sensible as soon as a sensible value is available.</p>
 
210
<p>Note that for Datagram sockets, this is the source port of the last packet received, and that it is in native byte order.</p>
 
211
<h3 class="fn"><a name="port"></a><a href="qtglobal-qt3.html#Q_UINT16-typedef">Q_UINT16</a> Q3SocketDevice::port () const</h3>
 
212
<p>Returns the port number of this socket device. This may be 0 for a while, but is set to something sensible as soon as a sensible value is available.</p>
 
213
<p>Note that Qt always uses native byte order, i.e. 67 is 67 in Qt; there is no need to call htons().</p>
 
214
<h3 class="fn"><a name="protocol"></a><a href="q3socketdevice.html#Protocol-enum">Protocol</a> Q3SocketDevice::protocol () const</h3>
 
215
<p>Returns the socket's protocol family, which is one of <tt>Unknown</tt>, <tt>IPv4</tt>, or <tt>IPv6</tt>.</p>
 
216
<p><a href="q3socketdevice.html">Q3SocketDevice</a> either creates a socket with a well known protocol family or it uses an already existing socket. In the first case, this function returns the protocol family it was constructed with. In the second case, it tries to determine the protocol family of the socket; if this fails, it returns <tt>Unknown</tt>.</p>
 
217
<p>See also <a href="q3socketdevice.html#Protocol-enum">Protocol</a> and <a href="q3socketdevice.html#setSocket">setSocket</a>().</p>
 
218
<h3 class="fn"><a name="readBlock"></a><a href="qtglobal.html#qint64-typedef">qint64</a> Q3SocketDevice::readBlock ( char * <i>data</i>, <a href="qtglobal-qt3.html#Q_ULONG-typedef">Q_ULONG</a> <i>maxlen</i> )</h3>
 
219
<p>Reads <i>maxlen</i> bytes from the socket into <i>data</i> and returns the number of bytes read. Returns -1 if an error occurred. Returning 0 is not an error. For Stream sockets, 0 is returned when the remote host closes the connection. For Datagram sockets, 0 is a valid datagram size.</p>
 
220
<h3 class="fn"><a name="readData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> Q3SocketDevice::readData ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxlen</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
221
<p>Reads <i>maxlen</i> bytes from the socket into <i>data</i> and returns the number of bytes read. Returns -1 if an error occurred.</p>
 
222
<p>Reimplemented from <a href="qiodevice.html#readData">QIODevice</a>.</p>
 
223
<h3 class="fn"><a name="receiveBufferSize"></a>int Q3SocketDevice::receiveBufferSize () const</h3>
 
224
<p>Returns the size of the operating system receive buffer.</p>
 
225
<p>See also <a href="q3socketdevice.html#setReceiveBufferSize">setReceiveBufferSize</a>().</p>
 
226
<h3 class="fn"><a name="sendBufferSize"></a>int Q3SocketDevice::sendBufferSize () const</h3>
 
227
<p>Returns the size of the operating system send buffer.</p>
 
228
<p>See also <a href="q3socketdevice.html#setSendBufferSize">setSendBufferSize</a>().</p>
 
229
<h3 class="fn"><a name="setAddressReusable"></a>void Q3SocketDevice::setAddressReusable ( bool <i>enable</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
230
<p>Sets the address of this socket to be usable by other sockets too if <i>enable</i> is true, and to be used exclusively by this socket if <i>enable</i> is false.</p>
 
231
<p>When a socket is reusable, other sockets can use the same port number (and IP address), which is generally useful. Of course other sockets cannot use the same (address,port,peer-address,peer-port) 4-tuple as this socket, so there is no risk of confusing the two TCP connections.</p>
 
232
<p>See also <a href="q3socketdevice.html#addressReusable">addressReusable</a>().</p>
 
233
<h3 class="fn"><a name="setBlocking"></a>void Q3SocketDevice::setBlocking ( bool <i>enable</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
234
<p>Makes the socket blocking if <i>enable</i> is true or nonblocking if <i>enable</i> is false.</p>
 
235
<p>Sockets are blocking by default, but we recommend using nonblocking socket operations, especially for GUI programs that need to be responsive.</p>
 
236
<p><b>Warning:</b> On Windows, this function should be used with care since whenever you use a <a href="qsocketnotifier.html">QSocketNotifier</a> on Windows, the socket is immediately made nonblocking.</p>
 
237
<p>See also <a href="q3socketdevice.html#blocking">blocking</a>() and <a href="q3socketdevice.html#isValid">isValid</a>().</p>
 
238
<h3 class="fn"><a name="setError"></a>void Q3SocketDevice::setError ( <a href="q3socketdevice.html#Error-enum">Error</a> <i>err</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
239
<p>Allows subclasses to set the error state to <i>err</i>.</p>
 
240
<h3 class="fn"><a name="setReceiveBufferSize"></a>void Q3SocketDevice::setReceiveBufferSize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
241
<p>Sets the size of the operating system receive buffer to <i>size</i>.</p>
 
242
<p>The operating system receive buffer size effectively limits two things: how much data can be in transit at any one moment, and how much data can be received in one iteration of the main event loop.</p>
 
243
<p>The default is operating system-dependent. A socket that receives large amounts of data is probably best with a buffer size of 49152.</p>
 
244
<h3 class="fn"><a name="setSendBufferSize"></a>void Q3SocketDevice::setSendBufferSize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
245
<p>Sets the size of the operating system send buffer to <i>size</i>.</p>
 
246
<p>The operating system send buffer size effectively limits how much data can be in transit at any one moment.</p>
 
247
<p>The default is operating system-dependent. A socket that sends large amounts of data is probably best with a buffer size of 49152.</p>
 
248
<h3 class="fn"><a name="setSocket"></a>void Q3SocketDevice::setSocket ( int <i>socket</i>, <a href="q3socketdevice.html#Type-enum">Type</a> <i>type</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
249
<p>Sets the socket device to operate on the existing socket <i>socket</i>.</p>
 
250
<p>The <i>type</i> argument must match the actual socket type; use <tt>Q3SocketDevice::Stream</tt> for a reliable, connection-oriented TCP socket, or <tt>Q3SocketDevice::Datagram</tt> for an unreliable, connectionless UDP socket.</p>
 
251
<p>Any existing socket is closed.</p>
 
252
<p>See also <a href="q3socketdevice.html#isValid">isValid</a>() and <a href="q3socketdevice.html#close">close</a>().</p>
 
253
<h3 class="fn"><a name="socket"></a>int Q3SocketDevice::socket () const</h3>
 
254
<p>Returns the socket number, or -1 if it is an invalid socket.</p>
 
255
<p>See also <a href="q3socketdevice.html#isValid">isValid</a>() and <a href="q3socketdevice.html#type">type</a>().</p>
 
256
<h3 class="fn"><a name="type"></a><a href="q3socketdevice.html#Type-enum">Type</a> Q3SocketDevice::type () const</h3>
 
257
<p>Returns the socket type which is either <tt>Q3SocketDevice::Stream</tt> or <tt>Q3SocketDevice::Datagram</tt>.</p>
 
258
<p>See also <a href="q3socketdevice.html#socket">socket</a>().</p>
 
259
<h3 class="fn"><a name="waitForMore"></a><a href="qtglobal-qt3.html#Q_LONG-typedef">Q_LONG</a> Q3SocketDevice::waitForMore ( int <i>msecs</i>, bool * <i>timeout</i> = 0 ) const</h3>
 
260
<p>Wait up to <i>msecs</i> milliseconds for more data to be available. If <i>msecs</i> is -1 the call will block indefinitely.</p>
 
261
<p>Returns the number of bytes available for reading, or -1 if an error occurred.</p>
 
262
<p>If <i>timeout</i> is non-null and no error occurred (i.e. it does not return -1): this function sets *<i>timeout</i> to true, if the reason for returning was that the timeout was reached; otherwise it sets *<i>timeout</i> to false. This is useful to find out if the peer closed the connection.</p>
 
263
<p><b>Warning:</b> This is a blocking call and should be avoided in event driven applications.</p>
 
264
<p>See also <a href="q3socketdevice.html#bytesAvailable">bytesAvailable</a>().</p>
 
265
<h3 class="fn"><a name="writeBlock"></a><a href="qtglobal-qt3.html#Q_LONG-typedef">Q_LONG</a> Q3SocketDevice::writeBlock ( const char * <i>data</i>, <a href="qtglobal-qt3.html#Q_ULONG-typedef">Q_ULONG</a> <i>len</i> )</h3>
 
266
<p>Writes <i>len</i> bytes to the socket from <i>data</i> and returns the number of bytes written. Returns -1 if an error occurred.</p>
 
267
<p>This is used for <tt>QSocketDevice::Stream</tt> sockets.</p>
 
268
<h3 class="fn"><a name="writeBlock-2"></a><a href="qtglobal-qt3.html#Q_LONG-typedef">Q_LONG</a> Q3SocketDevice::writeBlock ( const char * <i>data</i>, <a href="qtglobal-qt3.html#Q_ULONG-typedef">Q_ULONG</a> <i>len</i>, const <a href="qhostaddress.html">QHostAddress</a> &amp; <i>host</i>, <a href="qtglobal-qt3.html#Q_UINT16-typedef">Q_UINT16</a> <i>port</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
269
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
270
<p>Writes <i>len</i> bytes to the socket from <i>data</i> and returns the number of bytes written. Returns -1 if an error occurred.</p>
 
271
<p>This is used for <tt>Q3SocketDevice::Datagram</tt> sockets. You must specify the <i>host</i> and <i>port</i> of the destination of the data.</p>
 
272
<h3 class="fn"><a name="writeData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> Q3SocketDevice::writeData ( const char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>len</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
273
<p>Writes <i>len</i> bytes to the socket from <i>data</i> and returns the number of bytes written. Returns -1 if an error occurred.</p>
 
274
<p>This is used for <tt>Q3SocketDevice::Stream</tt> sockets.</p>
 
275
<p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice</a>.</p>
 
276
<p /><address><hr /><div align="center">
 
277
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
278
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
279
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
280
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
281
</tr></table></div></address></body>
 
282
</html>