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"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { 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 Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main 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 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 <<a href="qsocketdevice-h.html">qsocketdevice.h</a>></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 type = Stream )</li>
|
---|
44 | <li class=fn><a href="#QSocketDevice-2"><b>QSocketDevice</b></a> ( Type type, Protocol protocol, int dummy )</li>
|
---|
45 | <li class=fn><a href="#QSocketDevice-3"><b>QSocketDevice</b></a> ( int socket, Type 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 socket, Type 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 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 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 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 size )</li>
|
---|
60 | <li class=fn>virtual bool <a href="#connect"><b>connect</b></a> ( const QHostAddress & addr, Q_UINT16 port )</li>
|
---|
61 | <li class=fn>virtual bool <a href="#bind"><b>bind</b></a> ( const QHostAddress & address, Q_UINT16 port )</li>
|
---|
62 | <li class=fn>virtual bool <a href="#listen"><b>listen</b></a> ( int 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 msecs, bool * timeout = 0 ) const</li>
|
---|
66 | <li class=fn>virtual Q_LONG <a href="#readBlock"><b>readBlock</b></a> ( char * data, Q_ULONG maxlen )</li>
|
---|
67 | <li class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const char * data, Q_ULONG len )</li>
|
---|
68 | <li class=fn>virtual Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const char * data, Q_ULONG len, const QHostAddress & host, Q_UINT16 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 err )</li>
|
---|
79 | </ul>
|
---|
80 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
81 |
|
---|
82 |
|
---|
83 | The 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
|
---|
88 | this 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
|
---|
90 | certain things (like UDP) can't be done with QSocket and if you need a
|
---|
91 | platform-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
|
---|
93 | works 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
|
---|
95 | protocol family (IPv4, IPv6) automatically. Passing the protocol
|
---|
96 | family to QSocketDevice's constructor or to <a href="#setSocket">setSocket</a>() forces
|
---|
97 | creation of a socket device of a specific protocol. If not set, the
|
---|
98 | protocol 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
|
---|
109 | the 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
|
---|
113 | no sense. For example:
|
---|
114 | <pre>
|
---|
115 | ::close( sd->socket() );
|
---|
116 | sd->writeBlock( someData, 42 );
|
---|
117 | </pre>
|
---|
118 |
|
---|
119 | The libc ::close() closes the socket, but QSocketDevice is not aware
|
---|
120 | of 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
|
---|
122 | another file.
|
---|
123 | <li><tt>QSocketDevice::ConnectionRefused</tt> - A connection attempt was rejected by the
|
---|
124 | peer.
|
---|
125 | <li><tt>QSocketDevice::NetworkFailure</tt> - There is a network failure.
|
---|
126 | <li><tt>QSocketDevice::UnknownError</tt> - The operating system did something
|
---|
127 | unexpected.
|
---|
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
|
---|
132 | are:
|
---|
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
|
---|
137 | happen if you use QSocketDevice with an already existing socket; it
|
---|
138 | tries to determine the protocol family, but this can fail if the
|
---|
139 | protocol 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> type = Stream )
|
---|
151 | </h3>
|
---|
152 | Creates 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
|
---|
154 | reliable, 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> type, <a href="qsocketdevice.html#Protocol-enum">Protocol</a> protocol, int dummy )
|
---|
159 | </h3>
|
---|
160 | Creates 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
|
---|
162 | reliable, 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
|
---|
164 | or IPv6. Passing <a href="#Protocol-enum">Unknown</a> is not meaningful in this context and you
|
---|
165 | should avoid using (it creates an IPv4 socket, but your code is not easily
|
---|
166 | readable).
|
---|
167 | <p> The argument <em>dummy</em> is necessary for compatibility with some
|
---|
168 | compilers.
|
---|
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 socket, <a href="qsocketdevice.html#Type-enum">Type</a> type )
|
---|
172 | </h3>
|
---|
173 | Creates 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
|
---|
175 | socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable,
|
---|
176 | connectionless UDP socket.
|
---|
177 |
|
---|
178 | <h3 class=fn><a name="~QSocketDevice"></a>QSocketDevice::~QSocketDevice ()<tt> [virtual]</tt>
|
---|
179 | </h3>
|
---|
180 | Destroys 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>
|
---|
184 | Extracts the first connection from the queue of pending
|
---|
185 | connections for this socket and returns a new socket identifier.
|
---|
186 | Returns -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>
|
---|
191 | Returns the address of this socket device. This may be 0.0.0.0 for
|
---|
192 | a while, but is set to something sensible as soon as a sensible
|
---|
193 | value is available.
|
---|
194 |
|
---|
195 | <h3 class=fn>bool <a name="addressReusable"></a>QSocketDevice::addressReusable () const
|
---|
196 | </h3>
|
---|
197 | Returns TRUE if the address of this socket can be used by other
|
---|
198 | sockets at the same time, and FALSE if this socket claims
|
---|
199 | exclusive ownership.
|
---|
200 | <p> <p>See also <a href="#setAddressReusable">setAddressReusable</a>().
|
---|
201 |
|
---|
202 | <h3 class=fn>bool <a name="bind"></a>QSocketDevice::bind ( const <a href="qhostaddress.html">QHostAddress</a> & address, Q_UINT16 port )<tt> [virtual]</tt>
|
---|
203 | </h3>
|
---|
204 | Assigns 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
|
---|
207 | what <a href="#port">port</a>() and <a href="#address">address</a>() return.
|
---|
208 | <p> bind() is used by servers for setting up incoming connections.
|
---|
209 | Call bind() before <a href="#listen">listen</a>().
|
---|
210 |
|
---|
211 | <h3 class=fn>bool <a name="blocking"></a>QSocketDevice::blocking () const
|
---|
212 | </h3>
|
---|
213 | Returns TRUE if the socket is valid and in blocking mode;
|
---|
214 | otherwise 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
|
---|
217 | ioctlsocket() 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>
|
---|
222 | Returns the number of bytes available for reading, or -1 if an
|
---|
223 | error occurred.
|
---|
224 | <p> <b>Warning:</b> On Microsoft Windows, we use the ioctlsocket() function
|
---|
225 | to determine the number of bytes queued on the socket. According
|
---|
226 | to Microsoft (KB Q125486), ioctlsocket() sometimes returns an
|
---|
227 | incorrect number. The only safe way to determine the amount of
|
---|
228 | data on the socket is to read it using <a href="#readBlock">readBlock</a>(). <a href="qsocket.html">QSocket</a> has
|
---|
229 | workarounds to deal with this problem.
|
---|
230 |
|
---|
231 | <h3 class=fn>bool <a name="connect"></a>QSocketDevice::connect ( const <a href="qhostaddress.html">QHostAddress</a> & addr, Q_UINT16 port )<tt> [virtual]</tt>
|
---|
232 | </h3>
|
---|
233 | Connects 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.
|
---|
234 | If it returns FALSE, <a href="#error">error</a>() explains why.
|
---|
235 | <p> Note that error() commonly returns NoError for non-blocking
|
---|
236 | sockets; this just means that you can call <a href="#connect">connect</a>() again in a
|
---|
237 | little 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>
|
---|
241 | Returns the first error seen.
|
---|
242 |
|
---|
243 | <h3 class=fn>bool <a name="isValid"></a>QSocketDevice::isValid () const
|
---|
244 | </h3>
|
---|
245 | Returns 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 backlog )<tt> [virtual]</tt>
|
---|
249 | </h3>
|
---|
250 | Specifies how many pending connections a server socket can have.
|
---|
251 | Returns TRUE if the operation was successful; otherwise returns
|
---|
252 | FALSE. 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
|
---|
254 | called 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>
|
---|
259 | Returns the address of the port this socket device is connected
|
---|
260 | to. This may be 0.0.0.0 for a while, but is set to something
|
---|
261 | sensible as soon as a sensible value is available.
|
---|
262 | <p> Note that for Datagram sockets, this is the source port of the
|
---|
263 | last packet received.
|
---|
264 |
|
---|
265 | <h3 class=fn>Q_UINT16 <a name="peerPort"></a>QSocketDevice::peerPort () const
|
---|
266 | </h3>
|
---|
267 | Returns the port number of the port this socket device is
|
---|
268 | connected to. This may be 0 for a while, but is set to something
|
---|
269 | sensible as soon as a sensible value is available.
|
---|
270 | <p> Note that for Datagram sockets, this is the source port of the
|
---|
271 | last 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>
|
---|
275 | Returns the port number of this socket device. This may be 0 for a
|
---|
276 | while, but is set to something sensible as soon as a sensible
|
---|
277 | value is available.
|
---|
278 | <p> Note that Qt always uses native byte order, i.e. 67 is 67 in Qt;
|
---|
279 | there 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>
|
---|
283 | Returns the socket's protocol family, which is one of <a href="#Protocol-enum">Unknown</a>, <a href="#Protocol-enum">IPv4</a>,
|
---|
284 | or <a href="#Protocol-enum">IPv6</a>.
|
---|
285 | <p> QSocketDevice either creates a socket with a well known protocol family or
|
---|
286 | it uses an already existing socket. In the first case, this function
|
---|
287 | returns the protocol family it was constructed with. In the second case, it
|
---|
288 | tries to determine the protocol family of the socket; if this fails, it
|
---|
289 | returns <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 * data, Q_ULONG maxlen )<tt> [virtual]</tt>
|
---|
293 | </h3>
|
---|
294 | Reads <em>maxlen</em> bytes from the socket into <em>data</em> and returns the
|
---|
295 | number of bytes read. Returns -1 if an error occurred. Returning 0
|
---|
296 | is not an error. For Stream sockets, 0 is returned when the remote
|
---|
297 | host closes the connection. For Datagram sockets, 0 is a valid
|
---|
298 | datagram 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>
|
---|
303 | Returns 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>
|
---|
308 | Returns 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 enable )<tt> [virtual]</tt>
|
---|
312 | </h3>
|
---|
313 | Sets the address of this socket to be usable by other sockets too
|
---|
314 | if <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
|
---|
317 | number (and IP address), which is generally useful. Of course
|
---|
318 | other sockets cannot use the same
|
---|
319 | (address,port,peer-address,peer-port) 4-tuple as this socket, so
|
---|
320 | there 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 enable )<tt> [virtual]</tt>
|
---|
324 | </h3>
|
---|
325 | Makes 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
|
---|
328 | nonblocking socket operations, especially for GUI programs that
|
---|
329 | need to be responsive.
|
---|
330 | <p> <b>Warning:</b> On Windows, this function should be used with care since
|
---|
331 | whenever you use a <a href="qsocketnotifier.html">QSocketNotifier</a> on Windows, the socket is
|
---|
332 | immediately 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> err )<tt> [protected]</tt>
|
---|
336 | </h3>
|
---|
337 | Allows subclasses to set the error state to <em>err</em>.
|
---|
338 |
|
---|
339 | <h3 class=fn>void <a name="setReceiveBufferSize"></a>QSocketDevice::setReceiveBufferSize ( uint size )<tt> [virtual]</tt>
|
---|
340 | </h3>
|
---|
341 | Sets the size of the operating system receive buffer to <em>size</em>.
|
---|
342 | <p> The operating system receive buffer size effectively limits two
|
---|
343 | things: how much data can be in transit at any one moment, and how
|
---|
344 | much data can be received in one iteration of the main event loop.
|
---|
345 | <p> The default is operating system-dependent. A socket that receives
|
---|
346 | large amounts of data is probably best with a buffer size of
|
---|
347 | 49152.
|
---|
348 |
|
---|
349 | <h3 class=fn>void <a name="setSendBufferSize"></a>QSocketDevice::setSendBufferSize ( uint size )<tt> [virtual]</tt>
|
---|
350 | </h3>
|
---|
351 | Sets the size of the operating system send buffer to <em>size</em>.
|
---|
352 | <p> The operating system send buffer size effectively limits how much
|
---|
353 | data can be in transit at any one moment.
|
---|
354 | <p> The default is operating system-dependent. A socket that sends
|
---|
355 | large amounts of data is probably best with a buffer size of
|
---|
356 | 49152.
|
---|
357 |
|
---|
358 | <h3 class=fn>void <a name="setSocket"></a>QSocketDevice::setSocket ( int socket, <a href="qsocketdevice.html#Type-enum">Type</a> type )<tt> [virtual]</tt>
|
---|
359 | </h3>
|
---|
360 | Sets 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
|
---|
362 | socket, or <a href="#Type-enum">QSocketDevice::Datagram</a> for an unreliable,
|
---|
363 | connectionless 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>
|
---|
369 | Returns 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>
|
---|
376 | or <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 msecs, bool * timeout = 0 ) const
|
---|
380 | </h3>
|
---|
381 | Wait 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
|
---|
384 | error occurred.
|
---|
385 | <p> If <em>timeout</em> is non-null and no error occurred (i.e. it does not
|
---|
386 | return -1): this function sets <em>*timeout</em> to TRUE, if the reason
|
---|
387 | for 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
|
---|
389 | closed the connection.
|
---|
390 | <p> <b>Warning:</b> This is a blocking call and should be avoided in event
|
---|
391 | driven 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 char * data, Q_ULONG len )<tt> [virtual]</tt>
|
---|
395 | </h3>
|
---|
396 | Writes <em>len</em> bytes to the socket from <em>data</em> and returns the
|
---|
397 | number 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 char * data, Q_ULONG len, const <a href="qhostaddress.html">QHostAddress</a> & host, Q_UINT16 port )<tt> [virtual]</tt>
|
---|
402 | </h3>
|
---|
403 | This 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
|
---|
405 | number 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
|
---|
407 | specify the <em>host</em> and <em>port</em> of the destination of the data.
|
---|
408 |
|
---|
409 | <!-- eof -->
|
---|
410 | <hr><p>
|
---|
411 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
412 | Copyright © 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 © 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>
|
---|