source: trunk/doc/html/qsocketdevice.html@ 190

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

reference documentation added

File size: 23.9 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/network/qsocketdevice.cpp:59 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSocketDevice 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>QSocketDevice Class Reference<br><small>[<a href="network.html">network module</a>]</small></h1>
33
34<p>The QSocketDevice class provides a platform-independent low-level socket API.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qsocketdevice-h.html">qsocketdevice.h</a>&gt;</tt>
37<p>Inherits <a href="qiodevice.html">QIODevice</a>.
38<p><a href="qsocketdevice-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> { Stream, Datagram }</li>
42<li class=fn>enum <a href="#Protocol-enum"><b>Protocol</b></a> { IPv4, IPv6, Unknown }</li>
43<li class=fn><a href="#QSocketDevice"><b>QSocketDevice</b></a> ( Type&nbsp;type = Stream )</li>
44<li class=fn><a href="#QSocketDevice-2"><b>QSocketDevice</b></a> ( Type&nbsp;type, Protocol&nbsp;protocol, int&nbsp;dummy )</li>
45<li class=fn><a href="#QSocketDevice-3"><b>QSocketDevice</b></a> ( int&nbsp;socket, Type&nbsp;type )</li>
46<li class=fn>virtual <a href="#~QSocketDevice"><b>~QSocketDevice</b></a> ()</li>
47<li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
48<li class=fn>Type <a href="#type"><b>type</b></a> () const</li>
49<li class=fn>Protocol <a href="#protocol"><b>protocol</b></a> () const</li>
50<li class=fn>int <a href="#socket"><b>socket</b></a> () const</li>
51<li class=fn>virtual void <a href="#setSocket"><b>setSocket</b></a> ( int&nbsp;socket, Type&nbsp;type )</li>
52<li class=fn>bool <a href="#blocking"><b>blocking</b></a> () const</li>
53<li class=fn>virtual void <a href="#setBlocking"><b>setBlocking</b></a> ( bool&nbsp;enable )</li>
54<li class=fn>bool <a href="#addressReusable"><b>addressReusable</b></a> () const</li>
55<li class=fn>virtual void <a href="#setAddressReusable"><b>setAddressReusable</b></a> ( bool&nbsp;enable )</li>
56<li class=fn>int <a href="#receiveBufferSize"><b>receiveBufferSize</b></a> () const</li>
57<li class=fn>virtual void <a href="#setReceiveBufferSize"><b>setReceiveBufferSize</b></a> ( uint&nbsp;size )</li>
58<li class=fn>int <a href="#sendBufferSize"><b>sendBufferSize</b></a> () const</li>
59<li class=fn>virtual void <a href="#setSendBufferSize"><b>setSendBufferSize</b></a> ( uint&nbsp;size )</li>
60<li class=fn>virtual bool <a href="#connect"><b>connect</b></a> ( const&nbsp;QHostAddress&nbsp;&amp;&nbsp;addr, Q_UINT16&nbsp;port )</li>
61<li class=fn>virtual bool <a href="#bind"><b>bind</b></a> ( const&nbsp;QHostAddress&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port )</li>
62<li class=fn>virtual bool <a href="#listen"><b>listen</b></a> ( int&nbsp;backlog )</li>
63<li class=fn>virtual int <a href="#accept"><b>accept</b></a> ()</li>
64<li class=fn>Q_LONG <a href="#bytesAvailable"><b>bytesAvailable</b></a> () const</li>
65<li class=fn>Q_LONG <a href="#waitForMore"><b>waitForMore</b></a> ( int&nbsp;msecs, bool&nbsp;*&nbsp;timeout = 0 ) const</li>
66<li class=fn>virtual Q_LONG <a href="#readBlock"><b>readBlock</b></a> ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen )</li>
67<li class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len )</li>
68<li class=fn>virtual Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len, const&nbsp;QHostAddress&nbsp;&amp;&nbsp;host, Q_UINT16&nbsp;port )</li>
69<li class=fn>Q_UINT16 <a href="#port"><b>port</b></a> () const</li>
70<li class=fn>Q_UINT16 <a href="#peerPort"><b>peerPort</b></a> () const</li>
71<li class=fn>QHostAddress <a href="#address"><b>address</b></a> () const</li>
72<li class=fn>QHostAddress <a href="#peerAddress"><b>peerAddress</b></a> () const</li>
73<li class=fn>enum <a href="#Error-enum"><b>Error</b></a> { NoError, AlreadyBound, Inaccessible, NoResources, InternalError, Bug = InternalError, Impossible, NoFiles, ConnectionRefused, NetworkFailure, UnknownError }</li>
74<li class=fn>Error <a href="#error"><b>error</b></a> () const</li>
75</ul>
76<h2>Protected Members</h2>
77<ul>
78<li class=fn>void <a href="#setError"><b>setError</b></a> ( Error&nbsp;err )</li>
79</ul>
80<hr><a name="details"></a><h2>Detailed Description</h2>
81
82
83The QSocketDevice class provides a platform-independent low-level socket API.
84
85<p>
86
87<p> This class provides a low level API for working with sockets. Users of
88this class are assumed to have networking experience. For most users the
89<a href="qsocket.html">QSocket</a> class provides a much easier and high level alternative, but
90certain things (like UDP) can't be done with QSocket and if you need a
91platform-independent API for those, QSocketDevice is the right choice.
92<p> The essential purpose of the class is to provide a <a href="qiodevice.html">QIODevice</a> that
93works on sockets, wrapped in a platform-independent API.
94<p> When calling <a href="#connect">connect</a>() or <a href="#bind">bind</a>(), QSocketDevice detects the
95protocol family (IPv4, IPv6) automatically. Passing the protocol
96family to QSocketDevice's constructor or to <a href="#setSocket">setSocket</a>() forces
97creation of a socket device of a specific protocol. If not set, the
98protocol will be detected at the first call to connect() or bind().
99<p> <p>See also <a href="qsocket.html">QSocket</a>, <a href="qsocketnotifier.html">QSocketNotifier</a>, <a href="qhostaddress.html">QHostAddress</a>, and <a href="io.html">Input/Output and Networking</a>.
100
101<hr><h2>Member Type Documentation</h2>
102<h3 class=fn><a name="Error-enum"></a>QSocketDevice::Error</h3>
103
104<p> This enum type describes the error states of QSocketDevice.
105<ul>
106<li><tt>QSocketDevice::NoError</tt> - No error has occurred.
107<li><tt>QSocketDevice::AlreadyBound</tt> - The device is already bound, according to <a href="#bind">bind</a>().
108<li><tt>QSocketDevice::Inaccessible</tt> - The operating system or firewall prohibited
109the action.
110<li><tt>QSocketDevice::NoResources</tt> - The operating system ran out of a resource.
111<li><tt>QSocketDevice::InternalError</tt> - An internal error occurred in QSocketDevice.
112<li><tt>QSocketDevice::Impossible</tt> - An attempt was made to do something which makes
113no sense. For example:
114<pre>
115 ::close( sd-&gt;socket() );
116 sd-&gt;writeBlock( someData, 42 );
117 </pre>
118
119The libc ::close() closes the socket, but QSocketDevice is not aware
120of this. So when you call <a href="#writeBlock">writeBlock</a>(), the impossible happens.
121<li><tt>QSocketDevice::NoFiles</tt> - The operating system will not let QSocketDevice open
122another file.
123<li><tt>QSocketDevice::ConnectionRefused</tt> - A connection attempt was rejected by the
124peer.
125<li><tt>QSocketDevice::NetworkFailure</tt> - There is a network failure.
126<li><tt>QSocketDevice::UnknownError</tt> - The operating system did something
127unexpected.
128</ul>
129<h3 class=fn><a name="Protocol-enum"></a>QSocketDevice::Protocol</h3>
130
131<p> This enum type describes the protocol family of the socket. Possible values
132are:
133<ul>
134<li><tt>QSocketDevice::IPv4</tt> - The socket is an IPv4 socket.
135<li><tt>QSocketDevice::IPv6</tt> - The socket is an IPv6 socket.
136<li><tt>QSocketDevice::Unknown</tt> - The protocol family of the socket is not known. This can
137happen if you use QSocketDevice with an already existing socket; it
138tries to determine the protocol family, but this can fail if the
139protocol family is not known to QSocketDevice.
140</ul><p> <p>See also <a href="#protocol">protocol</a>() and <a href="#setSocket">setSocket</a>().
141
142<h3 class=fn><a name="Type-enum"></a>QSocketDevice::Type</h3>
143
144<p> This enum type describes the type of the socket:
145<ul>
146<li><tt>QSocketDevice::Stream</tt> - a stream socket (TCP, usually)
147<li><tt>QSocketDevice::Datagram</tt> - a datagram socket (UDP, usually)
148</ul>
149<hr><h2>Member Function Documentation</h2>
150<h3 class=fn><a name="QSocketDevice"></a>QSocketDevice::QSocketDevice ( <a href="qsocketdevice.html#Type-enum">Type</a>&nbsp;type = Stream )
151</h3>
152Creates a QSocketDevice object for a stream or datagram socket.
153<p> The <em>type</em> argument must be either <a href="#Type-enum">QSocketDevice::Stream</a> for a
154reliable, connection-oriented TCP socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable UDP socket.
155<p> The socket is created as an IPv4 socket.
156<p> <p>See also <a href="#blocking">blocking</a>() and <a href="#protocol">protocol</a>().
157
158<h3 class=fn><a name="QSocketDevice-2"></a>QSocketDevice::QSocketDevice ( <a href="qsocketdevice.html#Type-enum">Type</a>&nbsp;type, <a href="qsocketdevice.html#Protocol-enum">Protocol</a>&nbsp;protocol, int&nbsp;dummy )
159</h3>
160Creates a QSocketDevice object for a stream or datagram socket.
161<p> The <em>type</em> argument must be either <a href="#Type-enum">QSocketDevice::Stream</a> for a
162reliable, connection-oriented TCP socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable UDP socket.
163<p> The <em>protocol</em> indicates whether the socket should be of type IPv4
164or IPv6. Passing <a href="#Protocol-enum">Unknown</a> is not meaningful in this context and you
165should avoid using (it creates an IPv4 socket, but your code is not easily
166readable).
167<p> The argument <em>dummy</em> is necessary for compatibility with some
168compilers.
169<p> <p>See also <a href="#blocking">blocking</a>() and <a href="#protocol">protocol</a>().
170
171<h3 class=fn><a name="QSocketDevice-3"></a>QSocketDevice::QSocketDevice ( int&nbsp;socket, <a href="qsocketdevice.html#Type-enum">Type</a>&nbsp;type )
172</h3>
173Creates a QSocketDevice object for the existing socket <em>socket</em>.
174<p> The <em>type</em> argument must match the actual socket type; use <a href="#Type-enum">QSocketDevice::Stream</a> for a reliable, connection-oriented TCP
175socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable,
176connectionless UDP socket.
177
178<h3 class=fn><a name="~QSocketDevice"></a>QSocketDevice::~QSocketDevice ()<tt> [virtual]</tt>
179</h3>
180Destroys the socket device and closes the socket if it is open.
181
182<h3 class=fn>int <a name="accept"></a>QSocketDevice::accept ()<tt> [virtual]</tt>
183</h3>
184Extracts the first connection from the queue of pending
185connections for this socket and returns a new socket identifier.
186Returns -1 if the operation failed.
187<p> <p>See also <a href="#bind">bind</a>() and <a href="#listen">listen</a>().
188
189<h3 class=fn><a href="qhostaddress.html">QHostAddress</a> <a name="address"></a>QSocketDevice::address () const
190</h3>
191Returns the address of this socket device. This may be 0.0.0.0 for
192a while, but is set to something sensible as soon as a sensible
193value is available.
194
195<h3 class=fn>bool <a name="addressReusable"></a>QSocketDevice::addressReusable () const
196</h3>
197Returns TRUE if the address of this socket can be used by other
198sockets at the same time, and FALSE if this socket claims
199exclusive ownership.
200<p> <p>See also <a href="#setAddressReusable">setAddressReusable</a>().
201
202<h3 class=fn>bool <a name="bind"></a>QSocketDevice::bind ( const&nbsp;<a href="qhostaddress.html">QHostAddress</a>&nbsp;&amp;&nbsp;address, Q_UINT16&nbsp;port )<tt> [virtual]</tt>
203</h3>
204Assigns a name to an unnamed socket. The name is the host address
205<em>address</em> and the port number <em>port</em>. If the operation succeeds,
206<a href="#bind">bind</a>() returns TRUE; otherwise it returns FALSE without changing
207what <a href="#port">port</a>() and <a href="#address">address</a>() return.
208<p> bind() is used by servers for setting up incoming connections.
209Call bind() before <a href="#listen">listen</a>().
210
211<h3 class=fn>bool <a name="blocking"></a>QSocketDevice::blocking () const
212</h3>
213Returns TRUE if the socket is valid and in blocking mode;
214otherwise returns FALSE.
215<p> Note that this function does not set <a href="#error">error</a>().
216<p> <b>Warning:</b> On Windows, this function always returns TRUE since the
217ioctlsocket() function is broken.
218<p> <p>See also <a href="#setBlocking">setBlocking</a>() and <a href="#isValid">isValid</a>().
219
220<h3 class=fn>Q_LONG <a name="bytesAvailable"></a>QSocketDevice::bytesAvailable () const
221</h3>
222Returns the number of bytes available for reading, or -1 if an
223error occurred.
224<p> <b>Warning:</b> On Microsoft Windows, we use the ioctlsocket() function
225to determine the number of bytes queued on the socket. According
226to Microsoft (KB Q125486), ioctlsocket() sometimes returns an
227incorrect number. The only safe way to determine the amount of
228data on the socket is to read it using <a href="#readBlock">readBlock</a>(). <a href="qsocket.html">QSocket</a> has
229workarounds to deal with this problem.
230
231<h3 class=fn>bool <a name="connect"></a>QSocketDevice::connect ( const&nbsp;<a href="qhostaddress.html">QHostAddress</a>&nbsp;&amp;&nbsp;addr, Q_UINT16&nbsp;port )<tt> [virtual]</tt>
232</h3>
233Connects to the IP address and port specified by <em>addr</em> and <em>port</em>. Returns TRUE if it establishes a connection; otherwise returns FALSE.
234If it returns FALSE, <a href="#error">error</a>() explains why.
235<p> Note that error() commonly returns NoError for non-blocking
236sockets; this just means that you can call <a href="#connect">connect</a>() again in a
237little while and it'll probably succeed.
238
239<h3 class=fn><a href="qsocketdevice.html#Error-enum">Error</a> <a name="error"></a>QSocketDevice::error () const
240</h3>
241Returns the first error seen.
242
243<h3 class=fn>bool <a name="isValid"></a>QSocketDevice::isValid () const
244</h3>
245Returns TRUE if this is a valid socket; otherwise returns FALSE.
246<p> <p>See also <a href="#socket">socket</a>().
247
248<h3 class=fn>bool <a name="listen"></a>QSocketDevice::listen ( int&nbsp;backlog )<tt> [virtual]</tt>
249</h3>
250Specifies how many pending connections a server socket can have.
251Returns TRUE if the operation was successful; otherwise returns
252FALSE. A <em>backlog</em> value of 50 is quite common.
253<p> The <a href="#listen">listen</a>() call only applies to sockets where <a href="#type">type</a>() is <a href="#Type-enum">Stream</a>, i.e. not to <a href="#Type-enum">Datagram</a> sockets. listen() must not be
254called before <a href="#bind">bind</a>() or after <a href="#accept">accept</a>().
255<p> <p>See also <a href="#bind">bind</a>() and <a href="#accept">accept</a>().
256
257<h3 class=fn><a href="qhostaddress.html">QHostAddress</a> <a name="peerAddress"></a>QSocketDevice::peerAddress () const
258</h3>
259Returns the address of the port this socket device is connected
260to. This may be 0.0.0.0 for a while, but is set to something
261sensible as soon as a sensible value is available.
262<p> Note that for Datagram sockets, this is the source port of the
263last packet received.
264
265<h3 class=fn>Q_UINT16 <a name="peerPort"></a>QSocketDevice::peerPort () const
266</h3>
267Returns the port number of the port this socket device is
268connected to. This may be 0 for a while, but is set to something
269sensible as soon as a sensible value is available.
270<p> Note that for Datagram sockets, this is the source port of the
271last packet received, and that it is in native byte order.
272
273<h3 class=fn>Q_UINT16 <a name="port"></a>QSocketDevice::port () const
274</h3>
275Returns the port number of this socket device. This may be 0 for a
276while, but is set to something sensible as soon as a sensible
277value is available.
278<p> Note that Qt always uses native byte order, i.e. 67 is 67 in Qt;
279there is no need to call htons().
280
281<h3 class=fn><a href="qsocketdevice.html#Protocol-enum">Protocol</a> <a name="protocol"></a>QSocketDevice::protocol () const
282</h3>
283Returns the socket's protocol family, which is one of <a href="#Protocol-enum">Unknown</a>, <a href="#Protocol-enum">IPv4</a>,
284or <a href="#Protocol-enum">IPv6</a>.
285<p> QSocketDevice either creates a socket with a well known protocol family or
286it uses an already existing socket. In the first case, this function
287returns the protocol family it was constructed with. In the second case, it
288tries to determine the protocol family of the socket; if this fails, it
289returns <a href="#Protocol-enum">Unknown</a>.
290<p> <p>See also <a href="#Protocol-enum">Protocol</a> and <a href="#setSocket">setSocket</a>().
291
292<h3 class=fn>Q_LONG <a name="readBlock"></a>QSocketDevice::readBlock ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen )<tt> [virtual]</tt>
293</h3>
294Reads <em>maxlen</em> bytes from the socket into <em>data</em> and returns the
295number of bytes read. Returns -1 if an error occurred. Returning 0
296is not an error. For Stream sockets, 0 is returned when the remote
297host closes the connection. For Datagram sockets, 0 is a valid
298datagram size.
299
300<p>Reimplemented from <a href="qiodevice.html#readBlock">QIODevice</a>.
301<h3 class=fn>int <a name="receiveBufferSize"></a>QSocketDevice::receiveBufferSize () const
302</h3>
303Returns the size of the operating system receive buffer.
304<p> <p>See also <a href="#setReceiveBufferSize">setReceiveBufferSize</a>().
305
306<h3 class=fn>int <a name="sendBufferSize"></a>QSocketDevice::sendBufferSize () const
307</h3>
308Returns the size of the operating system send buffer.
309<p> <p>See also <a href="#setSendBufferSize">setSendBufferSize</a>().
310
311<h3 class=fn>void <a name="setAddressReusable"></a>QSocketDevice::setAddressReusable ( bool&nbsp;enable )<tt> [virtual]</tt>
312</h3>
313Sets the address of this socket to be usable by other sockets too
314if <em>enable</em> is TRUE, and to be used exclusively by this socket if
315<em>enable</em> is FALSE.
316<p> When a socket is reusable, other sockets can use the same port
317number (and IP address), which is generally useful. Of course
318other sockets cannot use the same
319(address,port,peer-address,peer-port) 4-tuple as this socket, so
320there is no risk of confusing the two TCP connections.
321<p> <p>See also <a href="#addressReusable">addressReusable</a>().
322
323<h3 class=fn>void <a name="setBlocking"></a>QSocketDevice::setBlocking ( bool&nbsp;enable )<tt> [virtual]</tt>
324</h3>
325Makes the socket blocking if <em>enable</em> is TRUE or nonblocking if
326<em>enable</em> is FALSE.
327<p> Sockets are blocking by default, but we recommend using
328nonblocking socket operations, especially for GUI programs that
329need to be responsive.
330<p> <b>Warning:</b> On Windows, this function should be used with care since
331whenever you use a <a href="qsocketnotifier.html">QSocketNotifier</a> on Windows, the socket is
332immediately made nonblocking.
333<p> <p>See also <a href="#blocking">blocking</a>() and <a href="#isValid">isValid</a>().
334
335<h3 class=fn>void <a name="setError"></a>QSocketDevice::setError ( <a href="qsocketdevice.html#Error-enum">Error</a>&nbsp;err )<tt> [protected]</tt>
336</h3>
337Allows subclasses to set the error state to <em>err</em>.
338
339<h3 class=fn>void <a name="setReceiveBufferSize"></a>QSocketDevice::setReceiveBufferSize ( uint&nbsp;size )<tt> [virtual]</tt>
340</h3>
341Sets the size of the operating system receive buffer to <em>size</em>.
342<p> The operating system receive buffer size effectively limits two
343things: how much data can be in transit at any one moment, and how
344much data can be received in one iteration of the main event loop.
345<p> The default is operating system-dependent. A socket that receives
346large amounts of data is probably best with a buffer size of
34749152.
348
349<h3 class=fn>void <a name="setSendBufferSize"></a>QSocketDevice::setSendBufferSize ( uint&nbsp;size )<tt> [virtual]</tt>
350</h3>
351Sets the size of the operating system send buffer to <em>size</em>.
352<p> The operating system send buffer size effectively limits how much
353data can be in transit at any one moment.
354<p> The default is operating system-dependent. A socket that sends
355large amounts of data is probably best with a buffer size of
35649152.
357
358<h3 class=fn>void <a name="setSocket"></a>QSocketDevice::setSocket ( int&nbsp;socket, <a href="qsocketdevice.html#Type-enum">Type</a>&nbsp;type )<tt> [virtual]</tt>
359</h3>
360Sets the socket device to operate on the existing socket <em>socket</em>.
361<p> The <em>type</em> argument must match the actual socket type; use <a href="#Type-enum">QSocketDevice::Stream</a> for a reliable, connection-oriented TCP
362socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable,
363connectionless UDP socket.
364<p> Any existing socket is closed.
365<p> <p>See also <a href="#isValid">isValid</a>() and <a href="qiodevice.html#close">close</a>().
366
367<h3 class=fn>int <a name="socket"></a>QSocketDevice::socket () const
368</h3>
369Returns the socket number, or -1 if it is an invalid socket.
370<p> <p>See also <a href="#isValid">isValid</a>() and <a href="#type">type</a>().
371
372<h3 class=fn><a href="qsocketdevice.html#Type-enum">Type</a> <a name="type"></a>QSocketDevice::type () const
373</h3>
374
375<p> Returns the socket type which is either <a href="#Type-enum">QSocketDevice::Stream</a>
376or <a href="#Type-enum">QSocketDevice::Datagram</a>.
377<p> <p>See also <a href="#socket">socket</a>().
378
379<h3 class=fn>Q_LONG <a name="waitForMore"></a>QSocketDevice::waitForMore ( int&nbsp;msecs, bool&nbsp;*&nbsp;timeout = 0 ) const
380</h3>
381Wait up to <em>msecs</em> milliseconds for more data to be available. If
382<em>msecs</em> is -1 the call will block indefinitely.
383<p> Returns the number of bytes available for reading, or -1 if an
384error occurred.
385<p> If <em>timeout</em> is non-null and no error occurred (i.e. it does not
386return -1): this function sets <em>*timeout</em> to TRUE, if the reason
387for returning was that the timeout was reached; otherwise it sets
388<em>*timeout</em> to FALSE. This is useful to find out if the peer
389closed the connection.
390<p> <b>Warning:</b> This is a blocking call and should be avoided in event
391driven applications.
392<p> <p>See also <a href="#bytesAvailable">bytesAvailable</a>().
393
394<h3 class=fn>Q_LONG <a name="writeBlock"></a>QSocketDevice::writeBlock ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len )<tt> [virtual]</tt>
395</h3>
396Writes <em>len</em> bytes to the socket from <em>data</em> and returns the
397number of bytes written. Returns -1 if an error occurred.
398<p> This is used for <a href="#Type-enum">QSocketDevice::Stream</a> sockets.
399
400<p>Reimplemented from <a href="qiodevice.html#writeBlock">QIODevice</a>.
401<h3 class=fn>Q_LONG <a name="writeBlock-2"></a>QSocketDevice::writeBlock ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len, const&nbsp;<a href="qhostaddress.html">QHostAddress</a>&nbsp;&amp;&nbsp;host, Q_UINT16&nbsp;port )<tt> [virtual]</tt>
402</h3>
403This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
404<p> Writes <em>len</em> bytes to the socket from <em>data</em> and returns the
405number of bytes written. Returns -1 if an error occurred.
406<p> This is used for <a href="#Type-enum">QSocketDevice::Datagram</a> sockets. You must
407specify the <em>host</em> and <em>port</em> of the destination of the data.
408
409<!-- eof -->
410<hr><p>
411This file is part of the <a href="index.html">Qt toolkit</a>.
412Copyright &copy; 1995-2007
413<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
414<table width=100% cellspacing=0 border=0><tr>
415<td>Copyright &copy; 2007
416<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
417<td align=right><div align=right>Qt 3.3.8</div>
418</table></div></address></body>
419</html>
Note: See TracBrowser for help on using the repository browser.