]>
Commit | Line | Data |
---|---|---|
105521d1 GRG |
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 | %% Name: socket.tex | |
3 | %% Purpose: wxSocket docs | |
4 | %% Author: Guillermo Rodriguez Garcia <guille@iies.es> | |
5 | %% Modified by: | |
6 | %% Created: 1999 | |
7 | %% RCS-ID: $Id$ | |
fc2171bd JS |
8 | %% Copyright: (c) wxWidgets team |
9 | %% License: wxWidgets license | |
105521d1 GRG |
10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
11 | ||
e79848ac GL |
12 | \section{\class{wxSocketBase}}\label{wxsocketbase} |
13 | ||
7cd315c6 GRG |
14 | wxSocketBase is the base class for all socket-related objects, and it |
15 | defines all basic IO functionality. | |
16 | ||
4cc90442 VZ |
17 | Note: (Workaround for implementation limitation for wxWidgets up to 2.5.x) |
18 | If you want to use sockets or derived classes such as wxFTP in a secondary thread, | |
19 | call wxSocketBase::Initialize() (undocumented) from the main thread before creating | |
20 | any sockets - in wxApp::OnInit for example. | |
21 | See http://wiki.wxwidgets.org/wiki.pl?WxSocket or | |
22 | http://www.litwindow.com/knowhow/knowhow.html for more details. | |
23 | ||
e79848ac GL |
24 | \wxheading{Derived from} |
25 | ||
5adbbc29 | 26 | \helpref{wxObject}{wxobject} |
e79848ac | 27 | |
954b8ae6 JS |
28 | \wxheading{Include files} |
29 | ||
30 | <wx/socket.h> | |
31 | ||
407f3681 | 32 | \wxheading{wxSocket errors} |
aa6d9706 GL |
33 | |
34 | \twocolwidtha{7cm} | |
35 | \begin{twocollist}\itemsep=0pt | |
36 | \twocolitem{{\bf wxSOCKET\_NOERROR}}{No error happened.} | |
37 | \twocolitem{{\bf wxSOCKET\_INVOP}}{Invalid operation.} | |
38 | \twocolitem{{\bf wxSOCKET\_IOERR}}{Input/Output error.} | |
39 | \twocolitem{{\bf wxSOCKET\_INVADDR}}{Invalid address passed to wxSocket.} | |
40 | \twocolitem{{\bf wxSOCKET\_INVSOCK}}{Invalid socket (uninitialized).} | |
41 | \twocolitem{{\bf wxSOCKET\_NOHOST}}{No corresponding host.} | |
42 | \twocolitem{{\bf wxSOCKET\_INVPORT}}{Invalid port.} | |
cf85cb95 GRG |
43 | \twocolitem{{\bf wxSOCKET\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.} |
44 | \twocolitem{{\bf wxSOCKET\_TIMEDOUT}}{The timeout for this operation expired.} | |
aa6d9706 | 45 | \twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.} |
a4625b8c | 46 | \end{twocollist} |
aa6d9706 | 47 | |
7e9a386e | 48 | \wxheading{wxSocket events} |
5a96d2f4 | 49 | |
aa6d9706 GL |
50 | \twocolwidtha{7cm} |
51 | \begin{twocollist}\itemsep=0pt | |
a4625b8c | 52 | \twocolitem{{\bf wxSOCKET\_INPUT}}{There is data available for reading.} |
aa6d9706 | 53 | \twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.} |
f6bcfd97 | 54 | \twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection request (server), or successful connection establishment (client).} |
cf85cb95 | 55 | \twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.} |
a4625b8c | 56 | \end{twocollist} |
5a96d2f4 | 57 | |
cf85cb95 GRG |
58 | A brief note on how to use these events: |
59 | ||
a4625b8c GRG |
60 | The {\bf wxSOCKET\_INPUT} event will be issued whenever there is data |
61 | available for reading. This will be the case if the input queue was | |
62 | empty and new data arrives, or if the application has read some data | |
63 | yet there is still more data available. This means that the application | |
fa482912 | 64 | does not need to read all available data in response to a |
a4625b8c GRG |
65 | {\bf wxSOCKET\_INPUT} event, as more events will be produced as |
66 | necessary. | |
67 | ||
68 | The {\bf wxSOCKET\_OUTPUT} event is issued when a socket is first | |
105521d1 GRG |
69 | connected with \helpref{Connect}{wxsocketclientconnect} or accepted |
70 | with \helpref{Accept}{wxsocketserveraccept}. After that, new | |
a4625b8c GRG |
71 | events will be generated only after an output operation fails |
72 | with {\bf wxSOCKET\_WOULDBLOCK} and buffer space becomes available | |
73 | again. This means that the application should assume that it | |
fa482912 | 74 | can write data to the socket until an {\bf wxSOCKET\_WOULDBLOCK} |
a4625b8c | 75 | error occurs; after this, whenever the socket becomes writable |
fa482912 | 76 | again the application will be notified with another |
a4625b8c GRG |
77 | {\bf wxSOCKET\_OUTPUT} event. |
78 | ||
79 | The {\bf wxSOCKET\_CONNECTION} event is issued when a delayed connection | |
2edb0bde | 80 | request completes successfully (client) or when a new connection arrives |
a4625b8c | 81 | at the incoming queue (server). |
cf85cb95 GRG |
82 | |
83 | The {\bf wxSOCKET\_LOST} event is issued when a close indication is | |
84 | received for the socket. This means that the connection broke down or | |
a4625b8c | 85 | that it was closed by the peer. Also, this event will be issued if |
f6bcfd97 | 86 | a connection request fails. |
cf85cb95 | 87 | |
e79848ac GL |
88 | \wxheading{Event handling} |
89 | ||
7cd315c6 | 90 | To process events coming from a socket object, use the following event |
f6bcfd97 BP |
91 | handler macro to direct events to member functions that take |
92 | a \helpref{wxSocketEvent}{wxsocketevent} argument. | |
e79848ac | 93 | |
42ff6409 | 94 | \twocolwidtha{7cm}% |
e79848ac | 95 | \begin{twocollist}\itemsep=0pt |
7cd315c6 | 96 | \twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a wxEVT\_SOCKET event.} |
a4625b8c | 97 | \end{twocollist} |
e79848ac | 98 | |
e79848ac GL |
99 | \wxheading{See also} |
100 | ||
407f3681 JS |
101 | \helpref{wxSocketEvent}{wxsocketevent}, |
102 | \helpref{wxSocketClient}{wxsocketclient}, | |
fa482912 | 103 | \helpref{wxSocketServer}{wxsocketserver}, |
105521d1 | 104 | \helpref{Sockets sample}{samplesockets} |
e79848ac GL |
105 | |
106 | % --------------------------------------------------------------------------- | |
7cd315c6 | 107 | % Function groups |
e79848ac | 108 | % --------------------------------------------------------------------------- |
105521d1 | 109 | |
7cd315c6 GRG |
110 | \latexignore{\rtfignore{\wxheading{Function groups}}} |
111 | ||
112 | \membersection{Construction and destruction} | |
113 | ||
114 | \helpref{wxSocketBase}{wxsocketbaseconstruct}\\ | |
5cb91489 | 115 | \helpref{\destruct{wxSocketBase}}{wxsocketbasedestruct}\\ |
f6bcfd97 | 116 | \helpref{Destroy}{wxsocketbasedestroy} |
7cd315c6 GRG |
117 | |
118 | \membersection{Socket state} | |
119 | ||
120 | Functions to retrieve current state and miscellaneous info. | |
121 | ||
122 | \helpref{Error}{wxsocketbaseerror}\\ | |
123 | \helpref{GetLocal}{wxsocketbasegetlocal}\\ | |
124 | \helpref{GetPeer}{wxsocketbasegetpeer} | |
125 | \helpref{IsConnected}{wxsocketbaseisconnected}\\ | |
126 | \helpref{IsData}{wxsocketbaseisdata}\\ | |
127 | \helpref{IsDisconnected}{wxsocketbaseisdisconnected}\\ | |
128 | \helpref{LastCount}{wxsocketbaselastcount}\\ | |
129 | \helpref{LastError}{wxsocketbaselasterror}\\ | |
130 | \helpref{Ok}{wxsocketbaseok}\\ | |
131 | \helpref{SaveState}{wxsocketbasesavestate}\\ | |
132 | \helpref{RestoreState}{wxsocketbaserestorestate} | |
133 | ||
134 | \membersection{Basic IO} | |
135 | ||
136 | Functions that perform basic IO functionality. | |
137 | ||
138 | \helpref{Close}{wxsocketbaseclose}\\ | |
139 | \helpref{Discard}{wxsocketbasediscard}\\ | |
140 | \helpref{Peek}{wxsocketbasepeek}\\ | |
141 | \helpref{Read}{wxsocketbaseread}\\ | |
142 | \helpref{ReadMsg}{wxsocketbasereadmsg}\\ | |
143 | \helpref{Unread}{wxsocketbaseunread}\\ | |
144 | \helpref{Write}{wxsocketbasewrite}\\ | |
145 | \helpref{WriteMsg}{wxsocketbasewritemsg} | |
146 | ||
147 | Functions that perform a timed wait on a certain IO condition. | |
148 | ||
5adbbc29 | 149 | \helpref{InterruptWait}{wxsocketbaseinterruptwait}\\ |
7cd315c6 | 150 | \helpref{Wait}{wxsocketbasewait}\\ |
5adbbc29 | 151 | \helpref{WaitForLost}{wxsocketbasewaitforlost}\\ |
7cd315c6 GRG |
152 | \helpref{WaitForRead}{wxsocketbasewaitforread}\\ |
153 | \helpref{WaitForWrite}{wxsocketbasewaitforwrite}\\ | |
5adbbc29 GRG |
154 | |
155 | and also: | |
156 | ||
157 | \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}\\ | |
158 | \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect} | |
7cd315c6 GRG |
159 | |
160 | Functions that allow applications to customize socket IO as needed. | |
161 | ||
5adbbc29 | 162 | \helpref{GetFlags}{wxsocketbasegetflags}\\ |
7cd315c6 GRG |
163 | \helpref{SetFlags}{wxsocketbasesetflags}\\ |
164 | \helpref{SetTimeout}{wxsocketbasesettimeout} | |
165 | ||
166 | \membersection{Handling socket events} | |
167 | ||
168 | Functions that allow applications to receive socket events. | |
169 | ||
170 | \helpref{Notify}{wxsocketbasenotify}\\ | |
171 | \helpref{SetNotify}{wxsocketbasesetnotify}\\ | |
5adbbc29 GRG |
172 | \helpref{GetClientData}{wxsocketbasegetclientdata}\\ |
173 | \helpref{SetClientData}{wxsocketbasesetclientdata}\\ | |
7cd315c6 GRG |
174 | \helpref{SetEventHandler}{wxsocketbaseseteventhandler} |
175 | ||
176 | Callback functions are also available, but they are provided for backwards | |
5adbbc29 GRG |
177 | compatibility only. Their use is strongly discouraged in favour of events, |
178 | and should be considered deprecated. Callbacks may be unsupported in future | |
fc2171bd | 179 | releases of wxWidgets. |
7cd315c6 GRG |
180 | |
181 | \helpref{Callback}{wxsocketbasecallback}\\ | |
182 | \helpref{CallbackData}{wxsocketbasecallbackdata} | |
183 | ||
184 | ||
185 | % --------------------------------------------------------------------------- | |
186 | % Members here | |
187 | % --------------------------------------------------------------------------- | |
188 | ||
189 | \helponly{\insertatlevel{2}{ | |
e79848ac | 190 | |
7cd315c6 GRG |
191 | \wxheading{Members} |
192 | ||
193 | }} | |
194 | ||
195 | \membersection{wxSocketBase::wxSocketBase}\label{wxsocketbaseconstruct} | |
42ff6409 | 196 | |
e79848ac GL |
197 | \func{}{wxSocketBase}{\void} |
198 | ||
fa482912 JS |
199 | Default constructor. Don't use it directly; instead, use |
200 | \helpref{wxSocketClient}{wxsocketclient} to construct a socket client, or | |
7cd315c6 | 201 | \helpref{wxSocketServer}{wxsocketserver} to construct a socket server. |
e79848ac | 202 | |
7cd315c6 | 203 | \membersection{wxSocketBase::\destruct{wxSocketBase}}\label{wxsocketbasedestruct} |
e79848ac GL |
204 | |
205 | \func{}{\destruct{wxSocketBase}}{\void} | |
206 | ||
5cb91489 | 207 | Destructor. Do not destroy a socket using the delete operator directly; |
5adbbc29 GRG |
208 | use \helpref{Destroy}{wxsocketbasedestroy} instead. Also, do not create |
209 | socket objects in the stack. | |
e79848ac | 210 | |
7cd315c6 GRG |
211 | % |
212 | % Callback | |
213 | % | |
214 | \membersection{wxSocketBase::Callback}\label{wxsocketbasecallback} | |
215 | ||
216 | \func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}} | |
217 | ||
218 | You can setup a callback function to be called when an event occurs. | |
219 | The function will be called only for those events for which notification | |
fa482912 | 220 | has been enabled with \helpref{Notify}{wxsocketbasenotify} and |
7cd315c6 GRG |
221 | \helpref{SetNotify}{wxsocketbasesetnotify}. The prototype of the |
222 | callback must be as follows: | |
223 | ||
224 | \begin{verbatim} | |
225 | void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata); | |
226 | \end{verbatim} | |
227 | ||
228 | The first parameter is a reference to the socket object in which the | |
f6bcfd97 | 229 | event occurred. The second parameter tells you which event occurred. |
7cd315c6 | 230 | (See \helpref{wxSocket events}{wxsocketbase}). The third parameter |
5adbbc29 | 231 | is the user data you specified using \helpref{CallbackData}{wxsocketbasecallbackdata}. |
7cd315c6 | 232 | |
7cd315c6 GRG |
233 | \wxheading{Return value} |
234 | ||
235 | A pointer to the previous callback. | |
236 | ||
f6bcfd97 BP |
237 | \wxheading{Remark/Warning} |
238 | ||
239 | Note that callbacks are now deprecated and unsupported, and they remain | |
240 | for backwards compatibility only. Use events instead. | |
241 | ||
7cd315c6 GRG |
242 | \wxheading{See also} |
243 | ||
244 | \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}, | |
245 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
246 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} | |
e79848ac | 247 | |
5a96d2f4 | 248 | % |
7cd315c6 GRG |
249 | % CallbackData |
250 | % | |
251 | \membersection{wxSocketBase::CallbackData}\label{wxsocketbasecallbackdata} | |
252 | ||
253 | \func{char *}{CallbackData}{\param{char *}{cdata}} | |
254 | ||
255 | This function sets the the user data which will be passed to a | |
256 | callback function set via \helpref{Callback}{wxsocketbasecallback}. | |
257 | ||
7cd315c6 GRG |
258 | \wxheading{Return value} |
259 | ||
260 | A pointer to the previous user data. | |
261 | ||
f6bcfd97 BP |
262 | \wxheading{Remark/Warning} |
263 | ||
264 | Note that callbacks are now deprecated and unsupported, and they remain | |
265 | for backwards compatibility only. Use events instead. | |
266 | ||
267 | \wxheading{See also} | |
268 | ||
7cd315c6 GRG |
269 | \helpref{wxSocketBase::Callback}{wxsocketbasecallback}, |
270 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
271 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} | |
272 | ||
273 | % | |
274 | % Close | |
275 | % | |
276 | \membersection{wxSocketBase::Close}\label{wxsocketbaseclose} | |
277 | ||
278 | \func{void}{Close}{\void} | |
279 | ||
280 | This function shuts down the socket, disabling further transmission and | |
281 | reception of data; it also disables events for the socket and frees the | |
ed8297b9 | 282 | associated system resources. Upon socket destruction, Close is automatically |
f6bcfd97 BP |
283 | called, so in most cases you won't need to do it yourself, unless you |
284 | explicitly want to shut down the socket, typically to notify the peer | |
285 | that you are closing the connection. | |
7cd315c6 GRG |
286 | |
287 | \wxheading{Remark/Warning} | |
288 | ||
289 | Although Close immediately disables events for the socket, it is possible | |
290 | that event messages may be waiting in the application's event queue. The | |
291 | application must therefore be prepared to handle socket event messages | |
292 | even after calling Close. | |
293 | ||
5cb91489 | 294 | % |
6b4a39fb | 295 | % Destroy |
5cb91489 GRG |
296 | % |
297 | \membersection{wxSocketBase::Destroy}\label{wxsocketbasedestroy} | |
298 | ||
6b4a39fb | 299 | \func{bool}{Destroy}{\void} |
5cb91489 GRG |
300 | |
301 | Destroys the socket safely. Use this function instead of the delete operator, | |
302 | since otherwise socket events could reach the application even after the | |
303 | socket has been destroyed. To prevent this problem, this function appends | |
304 | the wxSocket to a list of object to be deleted on idle time, after all | |
305 | events have been processed. For the same reason, you should avoid creating | |
306 | socket objects in the stack. | |
307 | ||
308 | Destroy calls \helpref{Close}{wxsocketbaseclose} automatically. | |
309 | ||
6b4a39fb GRG |
310 | \wxheading{Return value} |
311 | ||
cc81d32f | 312 | Always true. |
6b4a39fb | 313 | |
7cd315c6 GRG |
314 | % |
315 | % Discard | |
316 | % | |
317 | \membersection{wxSocketBase::Discard}\label{wxsocketbasediscard} | |
318 | ||
319 | \func{wxSocketBase\&}{Discard}{\void} | |
320 | ||
321 | This function simply deletes all bytes in the incoming queue. This function | |
322 | always returns immediately and its operation is not affected by IO flags. | |
323 | ||
324 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually discarded. | |
325 | ||
cc81d32f | 326 | If you use \helpref{Error}{wxsocketbaseerror}, it will always return false. |
7cd315c6 GRG |
327 | |
328 | % | |
329 | % Error | |
330 | % | |
331 | \membersection{wxSocketBase::Error}\label{wxsocketbaseerror} | |
332 | ||
333 | \constfunc{bool}{Error}{\void} | |
334 | ||
cc81d32f | 335 | Returns true if an error occurred in the last IO operation. |
7cd315c6 GRG |
336 | |
337 | Use this function to check for an error condition after one of the | |
338 | following calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg. | |
339 | ||
5adbbc29 GRG |
340 | % |
341 | % GetClientData | |
342 | % | |
343 | \membersection{wxSocketBase::GetClientData}\label{wxsocketbasegetclientdata} | |
344 | ||
345 | \constfunc{void *}{GetClientData}{\void} | |
346 | ||
fa482912 | 347 | Returns a pointer of the client data for this socket, as set with |
5adbbc29 GRG |
348 | \helpref{SetClientData}{wxsocketbasesetclientdata} |
349 | ||
7cd315c6 GRG |
350 | % |
351 | % GetLocal | |
352 | % | |
353 | \membersection{wxSocketBase::GetLocal}\label{wxsocketbasegetlocal} | |
354 | ||
f6bcfd97 | 355 | \constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr}} |
7cd315c6 GRG |
356 | |
357 | This function returns the local address field of the socket. The local | |
358 | address field contains the complete local address of the socket (local | |
359 | address, local port, ...). | |
360 | ||
361 | \wxheading{Return value} | |
362 | ||
cc81d32f | 363 | true if no error happened, false otherwise. |
7cd315c6 | 364 | |
5adbbc29 GRG |
365 | % |
366 | % GetFlags | |
367 | % | |
368 | \membersection{wxSocketBase::GetFlags}\label{wxsocketbasegetflags} | |
369 | ||
370 | \constfunc{wxSocketFlags}{GetFlags}{\void} | |
371 | ||
372 | Returns current IO flags, as set with \helpref{SetFlags}{wxsocketbasesetflags} | |
373 | ||
5a96d2f4 | 374 | % |
7cd315c6 GRG |
375 | % GetPeer |
376 | % | |
377 | \membersection{wxSocketBase::GetPeer}\label{wxsocketbasegetpeer} | |
5a96d2f4 | 378 | |
f6bcfd97 | 379 | \constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr}} |
7cd315c6 GRG |
380 | |
381 | This function returns the peer address field of the socket. The peer | |
382 | address field contains the complete peer host address of the socket | |
383 | (address, port, ...). | |
384 | ||
385 | \wxheading{Return value} | |
386 | ||
cc81d32f | 387 | true if no error happened, false otherwise. |
7cd315c6 | 388 | |
5adbbc29 GRG |
389 | % |
390 | % InterruptWait | |
391 | % | |
392 | \membersection{wxSocketBase::InterruptWait}\label{wxsocketbaseinterruptwait} | |
393 | ||
394 | \func{void}{InterruptWait}{\void} | |
395 | ||
396 | Use this function to interrupt any wait operation currently in progress. | |
397 | Note that this is not intended as a regular way to interrupt a Wait call, | |
398 | but only as an escape mechanism for exceptional situations where it is | |
399 | absolutely necessary to use it, for example to abort an operation due to | |
400 | some exception or abnormal problem. InterruptWait is automatically called | |
401 | when you \helpref{Close}{wxsocketbaseclose} a socket (and thus also upon | |
402 | socket destruction), so you don't need to use it in these cases. | |
403 | ||
fa482912 JS |
404 | \helpref{wxSocketBase::Wait}{wxsocketbasewait}, |
405 | \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}, | |
406 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}, | |
407 | \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, | |
408 | \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, | |
5adbbc29 GRG |
409 | \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect} |
410 | ||
7cd315c6 GRG |
411 | % |
412 | % IsConnected | |
413 | % | |
414 | \membersection{wxSocketBase::IsConnected}\label{wxsocketbaseisconnected} | |
415 | ||
416 | \constfunc{bool}{IsConnected}{\void} | |
417 | ||
cc81d32f | 418 | Returns true if the socket is connected. |
7cd315c6 GRG |
419 | |
420 | % | |
421 | % IsData | |
422 | % | |
423 | \membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata} | |
424 | ||
425 | \constfunc{bool}{IsData}{\void} | |
426 | ||
261b9a3d | 427 | This function waits until the socket is readable. This might mean that |
7cd315c6 | 428 | queued data is available for reading or, for streamed sockets, that |
261b9a3d GRG |
429 | the connection has been closed, so that a read operation will complete |
430 | immediately without blocking (unless the {\bf wxSOCKET\_WAITALL} flag | |
431 | is set, in which case the operation might still block). | |
7cd315c6 GRG |
432 | |
433 | \membersection{wxSocketBase::IsDisconnected}\label{wxsocketbaseisdisconnected} | |
434 | ||
435 | % | |
436 | % IsDisconnected | |
437 | % | |
438 | \constfunc{bool}{IsDisconnected}{\void} | |
439 | ||
cc81d32f | 440 | Returns true if the socket is not connected. |
7cd315c6 GRG |
441 | |
442 | \membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount} | |
443 | ||
444 | % | |
445 | % LastCount | |
446 | % | |
447 | \constfunc{wxUint32}{LastCount}{\void} | |
448 | ||
449 | Returns the number of bytes read or written by the last IO call. | |
450 | ||
451 | Use this function to get the number of bytes actually transferred | |
452 | after using one of the following IO calls: Discard, Peek, Read, | |
453 | ReadMsg, Unread, Write, WriteMsg. | |
454 | ||
455 | % | |
456 | % LastError | |
457 | % | |
458 | \membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror} | |
459 | ||
460 | \constfunc{wxSocketError}{LastError}{\void} | |
461 | ||
462 | Returns the last wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}. | |
463 | ||
464 | Please note that this function merely returns the last error code, | |
f6bcfd97 | 465 | but it should not be used to determine if an error has occurred (this |
7cd315c6 GRG |
466 | is because successful operations do not change the LastError value). |
467 | Use \helpref{Error}{wxsocketbaseerror} first, in order to determine | |
cc81d32f | 468 | if the last IO call failed. If this returns true, use LastError |
7cd315c6 GRG |
469 | to discover the cause of the error. |
470 | ||
471 | % | |
472 | % Notify | |
473 | % | |
474 | \membersection{wxSocketBase::Notify}\label{wxsocketbasenotify} | |
475 | ||
476 | \func{void}{Notify}{\param{bool}{ notify}} | |
477 | ||
478 | According to the {\it notify} value, this function enables | |
cc81d32f | 479 | or disables socket events. If {\it notify} is true, the events |
7cd315c6 | 480 | configured with \helpref{SetNotify}{wxsocketbasesetnotify} will |
cc81d32f | 481 | be sent to the application. If {\it notify} is false; no events |
7cd315c6 GRG |
482 | will be sent. |
483 | ||
484 | % | |
485 | % Ok | |
486 | % | |
487 | \membersection{wxSocketBase::Ok}\label{wxsocketbaseok} | |
488 | ||
489 | \constfunc{bool}{Ok}{\void} | |
490 | ||
cc81d32f | 491 | Returns true if the socket is initialized and ready and false in other |
7cd315c6 GRG |
492 | cases. |
493 | ||
5cb91489 GRG |
494 | \wxheading{Remark/Warning} |
495 | ||
cc81d32f | 496 | For \helpref{wxSocketClient}{wxsocketclient}, Ok won't return true unless |
5cb91489 GRG |
497 | the client is connected to a server. |
498 | ||
cc81d32f | 499 | For \helpref{wxSocketServer}{wxsocketserver}, Ok will return true if the |
5cb91489 GRG |
500 | server could bind to the specified address and is already listening for |
501 | new connections. | |
502 | ||
f6bcfd97 BP |
503 | Ok does not check for IO errors; |
504 | use \helpref{Error}{wxsocketbaseerror} instead for that purpose. | |
5cb91489 | 505 | |
7cd315c6 GRG |
506 | % |
507 | % RestoreState | |
508 | % | |
509 | \membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate} | |
510 | ||
511 | \func{void}{RestoreState}{\void} | |
512 | ||
513 | This function restores the previous state of the socket, as saved | |
514 | with \helpref{SaveState}{wxsocketbasesavestate} | |
515 | ||
516 | Calls to SaveState and RestoreState can be nested. | |
517 | ||
518 | \wxheading{See also} | |
519 | ||
520 | \helpref{wxSocketBase::SaveState}{wxsocketbasesavestate} | |
521 | ||
522 | % | |
523 | % SaveState | |
524 | % | |
525 | \membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate} | |
526 | ||
527 | \func{void}{SaveState}{\void} | |
528 | ||
529 | This function saves the current state of the socket in a stack. Socket | |
530 | state includes flags, as set with \helpref{SetFlags}{wxsocketbasesetflags}, | |
fa482912 JS |
531 | event mask, as set with \helpref{SetNotify}{wxsocketbasesetnotify} and |
532 | \helpref{Notify}{wxsocketbasenotify}, user data, as set with | |
5adbbc29 | 533 | \helpref{SetClientData}{wxsocketbasesetclientdata}, and asynchronous |
fa482912 | 534 | callback settings, as set with \helpref{Callback}{wxsocketbasecallback} |
7cd315c6 GRG |
535 | and \helpref{CallbackData}{wxsocketbasecallbackdata}. |
536 | ||
537 | Calls to SaveState and RestoreState can be nested. | |
538 | ||
539 | \wxheading{See also} | |
540 | ||
541 | \helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate} | |
542 | ||
5adbbc29 GRG |
543 | % |
544 | % SetClientData | |
545 | % | |
546 | \membersection{wxSocketBase::SetClientData}\label{wxsocketbasesetclientdata} | |
547 | ||
548 | \func{void}{SetClientData}{\param{void *}{data}} | |
549 | ||
550 | Sets user-supplied client data for this socket. All socket events will | |
f6bcfd97 BP |
551 | contain a pointer to this data, which can be retrieved with |
552 | the \helpref{wxSocketEvent::GetClientData}{wxsocketeventgetclientdata} function. | |
5adbbc29 | 553 | |
7cd315c6 GRG |
554 | % |
555 | % SetEventHandler | |
556 | % | |
557 | \membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler} | |
558 | ||
f6bcfd97 | 559 | \func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ handler}, \param{int}{ id = -1}} |
7cd315c6 GRG |
560 | |
561 | Sets an event handler to be called when a socket event occurs. The | |
562 | handler will be called for those events for which notification is | |
fa482912 | 563 | enabled with \helpref{SetNotify}{wxsocketbasesetnotify} and |
7cd315c6 GRG |
564 | \helpref{Notify}{wxsocketbasenotify}. |
565 | ||
7cd315c6 GRG |
566 | \wxheading{Parameters} |
567 | ||
f6bcfd97 | 568 | \docparam{handler}{Specifies the event handler you want to use.} |
7cd315c6 GRG |
569 | |
570 | \docparam{id}{The id of socket event.} | |
571 | ||
572 | \wxheading{See also} | |
573 | ||
574 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
575 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify}, | |
576 | \helpref{wxSocketEvent}{wxsocketevent}, | |
fa482912 | 577 | \helpref{wxEvtHandler}{wxevthandler} |
7cd315c6 GRG |
578 | |
579 | % | |
580 | % SetFlags | |
581 | % | |
5a96d2f4 GL |
582 | \membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags} |
583 | ||
f6bcfd97 | 584 | \func{void}{SetFlags}{\param{wxSocketFlags}{ flags}} |
5a96d2f4 | 585 | |
f6bcfd97 | 586 | Use SetFlags to customize IO operation for this socket. |
2edb0bde | 587 | The {\it flags} parameter may be a combination of flags ORed together. |
f6bcfd97 | 588 | The following flags can be used: |
5adbbc29 | 589 | |
5a96d2f4 GL |
590 | \twocolwidtha{7cm} |
591 | \begin{twocollist}\itemsep=0pt | |
a4625b8c GRG |
592 | \twocolitem{{\bf wxSOCKET\_NONE}}{Normal functionality.} |
593 | \twocolitem{{\bf wxSOCKET\_NOWAIT}}{Read/write as much data as possible and return immediately.} | |
594 | \twocolitem{{\bf wxSOCKET\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.} | |
105521d1 | 595 | \twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not yield) while reading/writing data.} |
5a96d2f4 GL |
596 | \end{twocollist} |
597 | ||
cf85cb95 GRG |
598 | A brief overview on how to use these flags follows. |
599 | ||
600 | If no flag is specified (this is the same as {\bf wxSOCKET\_NONE}), | |
601 | IO calls will return after some data has been read or written, even | |
602 | when the transfer might not be complete. This is the same as issuing | |
f6bcfd97 BP |
603 | exactly one blocking low-level call to recv() or send(). Note |
604 | that {\it blocking} here refers to when the function returns, not | |
605 | to whether the GUI blocks during this time. | |
cf85cb95 GRG |
606 | |
607 | If {\bf wxSOCKET\_NOWAIT} is specified, IO calls will return immediately. | |
608 | Read operations will retrieve only available data. Write operations will | |
609 | write as much data as possible, depending on how much space is available | |
610 | in the output buffer. This is the same as issuing exactly one nonblocking | |
105521d1 GRG |
611 | low-level call to recv() or send(). Note that {\it nonblocking} here |
612 | refers to when the function returns, not to whether the GUI blocks during | |
613 | this time. | |
cf85cb95 GRG |
614 | |
615 | If {\bf wxSOCKET\_WAITALL} is specified, IO calls won't return until ALL | |
616 | the data has been read or written (or until an error occurs), blocking if | |
617 | necessary, and issuing several low level calls if necessary. This is the | |
618 | same as having a loop which makes as many blocking low-level calls to | |
f6bcfd97 BP |
619 | recv() or send() as needed so as to transfer all the data. Note |
620 | that {\it blocking} here refers to when the function returns, not | |
621 | to whether the GUI blocks during this time. | |
cf85cb95 | 622 | |
bf9b6711 | 623 | The {\bf wxSOCKET\_BLOCK} flag controls whether the GUI blocks during |
105521d1 GRG |
624 | IO operations. If this flag is specified, the socket will not yield |
625 | during IO calls, so the GUI will remain blocked until the operation | |
626 | completes. If it is not used, then the application must take extra | |
627 | care to avoid unwanted reentrance. | |
cf85cb95 GRG |
628 | |
629 | So: | |
630 | ||
a4625b8c | 631 | {\bf wxSOCKET\_NONE} will try to read at least SOME data, no matter how much. |
407f3681 | 632 | |
cf85cb95 GRG |
633 | {\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot |
634 | read or write ANY data. | |
407f3681 | 635 | |
cf85cb95 GRG |
636 | {\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL |
637 | the data. | |
407f3681 | 638 | |
cf85cb95 | 639 | {\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and |
bf9b6711 | 640 | it controls whether the GUI blocks. |
cf85cb95 | 641 | |
5a96d2f4 GL |
642 | % |
643 | % SetNotify | |
644 | % | |
645 | \membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify} | |
646 | ||
cf85cb95 | 647 | \func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}} |
5a96d2f4 | 648 | |
cf85cb95 | 649 | SetNotify specifies which socket events are to be sent to the event handler. |
2edb0bde | 650 | The {\it flags} parameter may be combination of flags ORed together. The |
cf85cb95 | 651 | following flags can be used: |
aa6d9706 GL |
652 | |
653 | \twocolwidtha{7cm} | |
654 | \begin{twocollist}\itemsep=0pt | |
cf85cb95 GRG |
655 | \twocolitem{{\bf wxSOCKET\_INPUT\_FLAG}}{to receive wxSOCKET\_INPUT} |
656 | \twocolitem{{\bf wxSOCKET\_OUTPUT\_FLAG}}{to receive wxSOCKET\_OUTPUT} | |
657 | \twocolitem{{\bf wxSOCKET\_CONNECTION\_FLAG}}{to receive wxSOCKET\_CONNECTION} | |
658 | \twocolitem{{\bf wxSOCKET\_LOST\_FLAG}}{to receive wxSOCKET\_LOST} | |
a4625b8c | 659 | \end{twocollist} |
aa6d9706 GL |
660 | |
661 | For example: | |
407f3681 | 662 | |
aa6d9706 | 663 | \begin{verbatim} |
cf85cb95 | 664 | sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); |
cc81d32f | 665 | sock.Notify(true); |
aa6d9706 | 666 | \end{verbatim} |
407f3681 | 667 | |
cf85cb95 GRG |
668 | In this example, the user will be notified about incoming socket data and |
669 | whenever the connection is closed. | |
aa6d9706 | 670 | |
7e9a386e | 671 | For more information on socket events see \helpref{wxSocket events}{wxsocketbase}. |
aa6d9706 GL |
672 | |
673 | % | |
674 | % SetTimeout | |
675 | % | |
bf9b6711 | 676 | \membersection{wxSocketBase::SetTimeout}\label{wxsocketbasesettimeout} |
7e9a386e | 677 | |
aa6d9706 GL |
678 | \func{void}{SetTimeout}{\param{int }{seconds}} |
679 | ||
7cd315c6 | 680 | This function sets the default socket timeout in seconds. This timeout |
f6bcfd97 BP |
681 | applies to all IO calls, and also to the \helpref{Wait}{wxsocketbasewait} family |
682 | of functions if you don't specify a wait interval. Initially, the default | |
683 | timeout is 10 minutes. | |
e79848ac | 684 | |
e79848ac GL |
685 | % |
686 | % Peek | |
687 | % | |
e79848ac GL |
688 | \membersection{wxSocketBase::Peek}\label{wxsocketbasepeek} |
689 | ||
061379e2 | 690 | \func{wxSocketBase\&}{Peek}{\param{void *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 691 | |
a4625b8c GRG |
692 | This function peeks a buffer of {\it nbytes} bytes from the socket. |
693 | Peeking a buffer doesn't delete it from the socket input queue. | |
e79848ac | 694 | |
105521d1 | 695 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually peeked. |
cf85cb95 | 696 | |
105521d1 | 697 | Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded. |
cf85cb95 | 698 | |
e79848ac GL |
699 | \wxheading{Parameters} |
700 | ||
701 | \docparam{buffer}{Buffer where to put peeked data.} | |
42ff6409 | 702 | |
e79848ac GL |
703 | \docparam{nbytes}{Number of bytes.} |
704 | ||
42ff6409 JS |
705 | \wxheading{Return value} |
706 | ||
e79848ac GL |
707 | Returns a reference to the current object. |
708 | ||
cf85cb95 GRG |
709 | \wxheading{Remark/Warning} |
710 | ||
7cd315c6 | 711 | The exact behaviour of wxSocketBase::Peek depends on the combination |
cf85cb95 GRG |
712 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
713 | ||
e79848ac GL |
714 | \wxheading{See also} |
715 | ||
407f3681 JS |
716 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
717 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
718 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
cf85cb95 | 719 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
e79848ac GL |
720 | |
721 | % | |
722 | % Read | |
723 | % | |
e79848ac GL |
724 | \membersection{wxSocketBase::Read}\label{wxsocketbaseread} |
725 | ||
061379e2 | 726 | \func{wxSocketBase\&}{Read}{\param{void *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac GL |
727 | |
728 | This function reads a buffer of {\it nbytes} bytes from the socket. | |
729 | ||
105521d1 | 730 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually read. |
cf85cb95 | 731 | |
105521d1 | 732 | Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded. |
cf85cb95 | 733 | |
e79848ac GL |
734 | \wxheading{Parameters} |
735 | ||
736 | \docparam{buffer}{Buffer where to put read data.} | |
42ff6409 | 737 | |
e79848ac GL |
738 | \docparam{nbytes}{Number of bytes.} |
739 | ||
42ff6409 JS |
740 | \wxheading{Return value} |
741 | ||
e79848ac GL |
742 | Returns a reference to the current object. |
743 | ||
9f3430a6 GL |
744 | \wxheading{Remark/Warning} |
745 | ||
7cd315c6 | 746 | The exact behaviour of wxSocketBase::Read depends on the combination |
407f3681 | 747 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. |
cf85cb95 | 748 | |
e79848ac GL |
749 | \wxheading{See also} |
750 | ||
407f3681 JS |
751 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
752 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
753 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
cf85cb95 | 754 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
e79848ac | 755 | |
e79848ac GL |
756 | % |
757 | % ReadMsg | |
758 | % | |
e79848ac GL |
759 | \membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg} |
760 | ||
061379e2 | 761 | \func{wxSocketBase\&}{ReadMsg}{\param{void *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 762 | |
fa482912 | 763 | This function reads a buffer sent by \helpref{WriteMsg}{wxsocketbasewritemsg} |
105521d1 GRG |
764 | on a socket. If the buffer passed to the function isn't big enough, the |
765 | remaining bytes will be discarded. This function always waits for the | |
766 | buffer to be entirely filled, unless an error occurs. | |
cf85cb95 | 767 | |
105521d1 | 768 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually read. |
cf85cb95 | 769 | |
105521d1 | 770 | Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded. |
e79848ac GL |
771 | |
772 | \wxheading{Parameters} | |
773 | ||
774 | \docparam{buffer}{Buffer where to put read data.} | |
42ff6409 | 775 | |
105521d1 | 776 | \docparam{nbytes}{Size of the buffer.} |
e79848ac | 777 | |
42ff6409 JS |
778 | \wxheading{Return value} |
779 | ||
e79848ac GL |
780 | Returns a reference to the current object. |
781 | ||
cf85cb95 GRG |
782 | \wxheading{Remark/Warning} |
783 | ||
7cd315c6 | 784 | wxSocketBase::ReadMsg will behave as if the {\bf wxSOCKET\_WAITALL} flag |
a4625b8c GRG |
785 | was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag. |
786 | The exact behaviour of ReadMsg depends on the {\bf wxSOCKET\_BLOCK} flag. | |
787 | For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. | |
cf85cb95 | 788 | |
e79848ac GL |
789 | \wxheading{See also} |
790 | ||
407f3681 JS |
791 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
792 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
793 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
794 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}, | |
9f3430a6 | 795 | \helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg} |
e79848ac GL |
796 | |
797 | % | |
798 | % Unread | |
799 | % | |
09eea162 | 800 | \membersection{wxSocketBase::Unread}\label{wxsocketbaseunread} |
e79848ac | 801 | |
061379e2 | 802 | \func{wxSocketBase\&}{Unread}{\param{const void *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 803 | |
cf85cb95 GRG |
804 | This function unreads a buffer. That is, the data in the buffer is put back |
805 | in the incoming queue. This function is not affected by wxSocket flags. | |
806 | ||
105521d1 | 807 | If you use \helpref{LastCount}{wxsocketbaselastcount}, it will always return {\it nbytes}. |
cf85cb95 | 808 | |
cc81d32f | 809 | If you use \helpref{Error}{wxsocketbaseerror}, it will always return false. |
e79848ac GL |
810 | |
811 | \wxheading{Parameters} | |
812 | ||
813 | \docparam{buffer}{Buffer to be unread.} | |
42ff6409 | 814 | |
e79848ac GL |
815 | \docparam{nbytes}{Number of bytes.} |
816 | ||
42ff6409 JS |
817 | \wxheading{Return value} |
818 | ||
e79848ac GL |
819 | Returns a reference to the current object. |
820 | ||
821 | \wxheading{See also} | |
822 | ||
407f3681 JS |
823 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
824 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
9f3430a6 | 825 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror} |
e79848ac GL |
826 | |
827 | % | |
7cd315c6 | 828 | % Wait |
e79848ac | 829 | % |
e79848ac | 830 | \membersection{wxSocketBase::Wait}\label{wxsocketbasewait} |
42ff6409 | 831 | |
aa6d9706 | 832 | \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 833 | |
cc81d32f | 834 | This function waits until any of the following conditions is true: |
105521d1 GRG |
835 | |
836 | \begin{itemize} | |
7cd315c6 | 837 | \item The socket becomes readable. |
105521d1 | 838 | \item The socket becomes writable. |
f6bcfd97 BP |
839 | \item An ongoing connection request has completed (\helpref{wxSocketClient}{wxsocketclient} only) |
840 | \item An incoming connection request has arrived (\helpref{wxSocketServer}{wxsocketserver} only) | |
105521d1 GRG |
841 | \item The connection has been closed. |
842 | \end{itemize} | |
e79848ac | 843 | |
f6bcfd97 BP |
844 | Note that it is recommended to use the individual Wait functions |
845 | to wait for the required condition, instead of this one. | |
846 | ||
e79848ac GL |
847 | \wxheading{Parameters} |
848 | ||
105521d1 GRG |
849 | \docparam{seconds}{Number of seconds to wait. |
850 | If -1, it will wait for the default timeout, | |
851 | as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.} | |
42ff6409 | 852 | |
aa6d9706 | 853 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 854 | |
42ff6409 | 855 | \wxheading{Return value} |
e79848ac | 856 | |
cc81d32f VS |
857 | Returns true when any of the above conditions is satisfied, |
858 | false if the timeout was reached. | |
e79848ac GL |
859 | |
860 | \wxheading{See also} | |
861 | ||
fa482912 JS |
862 | \helpref{wxSocketBase::InterruptWait}{wxsocketbaseinterruptwait}, |
863 | \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}, | |
864 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}, | |
407f3681 | 865 | \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, |
fa482912 | 866 | \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, |
5adbbc29 | 867 | \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect} |
e79848ac GL |
868 | |
869 | % | |
5adbbc29 | 870 | % WaitForLost |
e79848ac | 871 | % |
5adbbc29 | 872 | \membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost} |
42ff6409 | 873 | |
5adbbc29 | 874 | \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 875 | |
5adbbc29 GRG |
876 | This function waits until the connection is lost. This may happen if |
877 | the peer gracefully closes the connection or if the connection breaks. | |
e79848ac GL |
878 | |
879 | \wxheading{Parameters} | |
880 | ||
105521d1 GRG |
881 | \docparam{seconds}{Number of seconds to wait. |
882 | If -1, it will wait for the default timeout, | |
883 | as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.} | |
42ff6409 | 884 | |
aa6d9706 | 885 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 886 | |
42ff6409 | 887 | \wxheading{Return value} |
e79848ac | 888 | |
cc81d32f | 889 | Returns true if the connection was lost, false if the timeout was reached. |
e79848ac GL |
890 | |
891 | \wxheading{See also} | |
892 | ||
5adbbc29 GRG |
893 | \helpref{wxSocketBase::InterruptWait}{wxsocketbaseinterruptwait}, |
894 | \helpref{wxSocketBase::Wait}{wxsocketbasewait} | |
e79848ac GL |
895 | |
896 | % | |
5adbbc29 | 897 | % WaitForRead |
e79848ac | 898 | % |
5adbbc29 | 899 | \membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread} |
42ff6409 | 900 | |
5adbbc29 | 901 | \func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 902 | |
5adbbc29 GRG |
903 | This function waits until the socket is readable. This might mean that |
904 | queued data is available for reading or, for streamed sockets, that | |
905 | the connection has been closed, so that a read operation will complete | |
906 | immediately without blocking (unless the {\bf wxSOCKET\_WAITALL} flag | |
907 | is set, in which case the operation might still block). | |
e79848ac GL |
908 | |
909 | \wxheading{Parameters} | |
910 | ||
105521d1 GRG |
911 | \docparam{seconds}{Number of seconds to wait. |
912 | If -1, it will wait for the default timeout, | |
913 | as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.} | |
42ff6409 | 914 | |
aa6d9706 | 915 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 916 | |
42ff6409 | 917 | \wxheading{Return value} |
e79848ac | 918 | |
cc81d32f | 919 | Returns true if the socket becomes readable, false on timeout. |
e79848ac GL |
920 | |
921 | \wxheading{See also} | |
922 | ||
fa482912 | 923 | \helpref{wxSocketBase::InterruptWait}{wxsocketbaseinterruptwait}, |
5adbbc29 | 924 | \helpref{wxSocketBase::Wait}{wxsocketbasewait} |
e79848ac GL |
925 | |
926 | % | |
5adbbc29 | 927 | % WaitForWrite |
e79848ac | 928 | % |
5adbbc29 | 929 | \membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite} |
42ff6409 | 930 | |
5adbbc29 | 931 | \func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 932 | |
5adbbc29 GRG |
933 | This function waits until the socket becomes writable. This might mean that |
934 | the socket is ready to send new data, or for streamed sockets, that the | |
935 | connection has been closed, so that a write operation is guaranteed to | |
936 | complete immediately (unless the {\bf wxSOCKET\_WAITALL} flag is set, | |
937 | in which case the operation might still block). | |
e79848ac GL |
938 | |
939 | \wxheading{Parameters} | |
940 | ||
105521d1 GRG |
941 | \docparam{seconds}{Number of seconds to wait. |
942 | If -1, it will wait for the default timeout, | |
943 | as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.} | |
42ff6409 | 944 | |
aa6d9706 | 945 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 946 | |
42ff6409 | 947 | \wxheading{Return value} |
e79848ac | 948 | |
cc81d32f | 949 | Returns true if the socket becomes writable, false on timeout. |
e79848ac GL |
950 | |
951 | \wxheading{See also} | |
952 | ||
fa482912 | 953 | \helpref{wxSocketBase::InterruptWait}{wxsocketbaseinterruptwait}, |
5adbbc29 | 954 | \helpref{wxSocketBase::Wait}{wxsocketbasewait} |
42ff6409 JS |
955 | |
956 | % | |
7cd315c6 | 957 | % Write |
42ff6409 | 958 | % |
7cd315c6 | 959 | \membersection{wxSocketBase::Write}\label{wxsocketbasewrite} |
42ff6409 | 960 | |
061379e2 | 961 | \func{wxSocketBase\&}{Write}{\param{const void *}{ buffer}, \param{wxUint32}{ nbytes}} |
42ff6409 | 962 | |
7cd315c6 | 963 | This function writes a buffer of {\it nbytes} bytes to the socket. |
e79848ac | 964 | |
7cd315c6 | 965 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually written. |
42ff6409 | 966 | |
7cd315c6 | 967 | Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded. |
e79848ac | 968 | |
7cd315c6 | 969 | \wxheading{Parameters} |
cf85cb95 | 970 | |
7cd315c6 | 971 | \docparam{buffer}{Buffer with the data to be sent.} |
e79848ac | 972 | |
7cd315c6 | 973 | \docparam{nbytes}{Number of bytes.} |
e79848ac | 974 | |
7cd315c6 | 975 | \wxheading{Return value} |
aa6d9706 | 976 | |
7cd315c6 | 977 | Returns a reference to the current object. |
7e9a386e | 978 | |
7cd315c6 | 979 | \wxheading{Remark/Warning} |
aa6d9706 | 980 | |
7cd315c6 GRG |
981 | The exact behaviour of wxSocketBase::Write depends on the combination |
982 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. | |
aa6d9706 | 983 | |
7cd315c6 | 984 | \wxheading{See also} |
aa6d9706 | 985 | |
7cd315c6 GRG |
986 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
987 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
988 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
989 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} | |
aa6d9706 GL |
990 | |
991 | % | |
7cd315c6 | 992 | % WriteMsg |
aa6d9706 | 993 | % |
7cd315c6 | 994 | \membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg} |
e79848ac | 995 | |
061379e2 | 996 | \func{wxSocketBase\&}{WriteMsg}{\param{const void *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 997 | |
7cd315c6 | 998 | This function writes a buffer of {\it nbytes} bytes from the socket, but it |
fa482912 JS |
999 | writes a short header before so that \helpref{ReadMsg}{wxsocketbasereadmsg} |
1000 | knows how much data should it actually read. So, a buffer sent with WriteMsg | |
7cd315c6 GRG |
1001 | {\bf must} be read with ReadMsg. This function always waits for the entire |
1002 | buffer to be sent, unless an error occurs. | |
e79848ac | 1003 | |
7cd315c6 | 1004 | Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually written. |
cf85cb95 | 1005 | |
7cd315c6 | 1006 | Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded. |
e79848ac GL |
1007 | |
1008 | \wxheading{Parameters} | |
1009 | ||
7cd315c6 | 1010 | \docparam{buffer}{Buffer with the data to be sent.} |
105521d1 | 1011 | |
7cd315c6 | 1012 | \docparam{nbytes}{Number of bytes to send.} |
aa6d9706 GL |
1013 | |
1014 | \wxheading{Return value} | |
1015 | ||
7cd315c6 | 1016 | Returns a reference to the current object. |
aa6d9706 | 1017 | |
7cd315c6 | 1018 | \wxheading{Remark/Warning} |
aa6d9706 | 1019 | |
7cd315c6 GRG |
1020 | wxSocketBase::WriteMsg will behave as if the {\bf wxSOCKET\_WAITALL} flag |
1021 | was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag. | |
1022 | The exact behaviour of WriteMsg depends on the {\bf wxSOCKET\_BLOCK} flag. | |
1023 | For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. | |
105521d1 | 1024 | |
7cd315c6 | 1025 | \wxheading{See also} |
aa6d9706 | 1026 | |
7cd315c6 GRG |
1027 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
1028 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
1029 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
1030 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}, | |
1031 | \helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg} | |
cf85cb95 | 1032 | |
e79848ac GL |
1033 | |
1034 | % --------------------------------------------------------------------------- | |
1035 | % CLASS wxSocketClient | |
1036 | % --------------------------------------------------------------------------- | |
7cd315c6 | 1037 | |
e79848ac GL |
1038 | \section{\class{wxSocketClient}}\label{wxsocketclient} |
1039 | ||
1040 | \wxheading{Derived from} | |
1041 | ||
1042 | \helpref{wxSocketBase}{wxsocketbase} | |
1043 | ||
954b8ae6 JS |
1044 | \wxheading{Include files} |
1045 | ||
1046 | <wx/socket.h> | |
1047 | ||
fa482912 JS |
1048 | \latexignore{\rtfignore{\wxheading{Members}}} |
1049 | ||
e79848ac GL |
1050 | % --------------------------------------------------------------------------- |
1051 | % Members | |
1052 | % --------------------------------------------------------------------------- | |
e79848ac GL |
1053 | % |
1054 | % wxSocketClient | |
1055 | % | |
e79848ac | 1056 | \membersection{wxSocketClient::wxSocketClient} |
42ff6409 | 1057 | |
e7240349 | 1058 | \func{}{wxSocketClient}{\param{wxSocketFlags}{ flags = wxSOCKET\_NONE}} |
e79848ac | 1059 | |
105521d1 | 1060 | Constructor. |
42ff6409 | 1061 | |
e79848ac GL |
1062 | \wxheading{Parameters} |
1063 | ||
1064 | \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})} | |
1065 | ||
1066 | % | |
1067 | % ~wxSocketClient | |
1068 | % | |
e79848ac | 1069 | \membersection{wxSocketClient::\destruct{wxSocketClient}} |
42ff6409 | 1070 | |
e79848ac GL |
1071 | \func{}{\destruct{wxSocketClient}}{\void} |
1072 | ||
f6bcfd97 | 1073 | Destructor. Please see \helpref{wxSocketBase::Destroy}{wxsocketbasedestroy}. |
e79848ac GL |
1074 | |
1075 | % | |
1076 | % Connect | |
1077 | % | |
42ff6409 | 1078 | \membersection{wxSocketClient::Connect}\label{wxsocketclientconnect} |
e79848ac | 1079 | |
cc81d32f | 1080 | \func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = true}} |
e79848ac | 1081 | |
cf85cb95 GRG |
1082 | Connects to a server using the specified address. |
1083 | ||
cc81d32f | 1084 | If {\it wait} is true, Connect will wait until the connection |
f6bcfd97 | 1085 | completes. {\bf Warning:} This will block the GUI. |
cf85cb95 | 1086 | |
cc81d32f | 1087 | If {\it wait} is false, Connect will try to establish the connection and |
cf85cb95 | 1088 | return immediately, without blocking the GUI. When used this way, even if |
cc81d32f | 1089 | Connect returns false, the connection request can be completed later. |
105521d1 GRG |
1090 | To detect this, use \helpref{WaitOnConnect}{wxsocketclientwaitonconnect}, |
1091 | or catch {\bf wxSOCKET\_CONNECTION} events (for successful establishment) | |
1092 | and {\bf wxSOCKET\_LOST} events (for connection failure). | |
e79848ac GL |
1093 | |
1094 | \wxheading{Parameters} | |
1095 | ||
1096 | \docparam{address}{Address of the server.} | |
42ff6409 | 1097 | |
cc81d32f | 1098 | \docparam{wait}{If true, waits for the connection to complete.} |
e79848ac GL |
1099 | |
1100 | \wxheading{Return value} | |
1101 | ||
cc81d32f | 1102 | Returns true if the connection is established and no error occurs. |
e79848ac | 1103 | |
cc81d32f | 1104 | If {\it wait} was true, and Connect returns false, an error occurred |
cf85cb95 GRG |
1105 | and the connection failed. |
1106 | ||
cc81d32f | 1107 | If {\it wait} was false, and Connect returns false, you should still |
cf85cb95 | 1108 | be prepared to handle the completion of this connection request, either |
f6bcfd97 BP |
1109 | with \helpref{WaitOnConnect}{wxsocketclientwaitonconnect} or by |
1110 | watching {\bf wxSOCKET\_CONNECTION} and {\bf wxSOCKET\_LOST} events. | |
cf85cb95 | 1111 | |
e79848ac GL |
1112 | \wxheading{See also} |
1113 | ||
407f3681 JS |
1114 | \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}, |
1115 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
cf85cb95 | 1116 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} |
e79848ac GL |
1117 | |
1118 | % | |
1119 | % WaitOnConnect | |
1120 | % | |
42ff6409 | 1121 | \membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect} |
e79848ac | 1122 | |
aa6d9706 | 1123 | \func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}} |
e79848ac | 1124 | |
105521d1 | 1125 | Wait until a connection request completes, or until the specified timeout |
f6bcfd97 | 1126 | elapses. Use this function after issuing a call |
cc81d32f | 1127 | to \helpref{Connect}{wxsocketclientconnect} with {\it wait} set to false. |
cf85cb95 GRG |
1128 | |
1129 | \wxheading{Parameters} | |
1130 | ||
105521d1 GRG |
1131 | \docparam{seconds}{Number of seconds to wait. |
1132 | If -1, it will wait for the default timeout, | |
1133 | as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.} | |
cf85cb95 GRG |
1134 | |
1135 | \docparam{millisecond}{Number of milliseconds to wait.} | |
1136 | ||
1137 | \wxheading{Return value} | |
1138 | ||
cc81d32f | 1139 | WaitOnConnect returns true if the connection request completes. This |
2edb0bde | 1140 | does not necessarily mean that the connection was successfully established; |
fa482912 | 1141 | it might also happen that the connection was refused by the peer. Use |
261b9a3d GRG |
1142 | \helpref{IsConnected}{wxsocketbaseisconnected} to distinguish between |
1143 | these two situations. | |
1144 | ||
cc81d32f | 1145 | If the timeout elapses, WaitOnConnect returns false. |
261b9a3d GRG |
1146 | |
1147 | These semantics allow code like this: | |
cf85cb95 | 1148 | |
261b9a3d GRG |
1149 | \begin{verbatim} |
1150 | // Issue the connection request | |
cc81d32f | 1151 | client->Connect(addr, false); |
261b9a3d GRG |
1152 | |
1153 | // Wait until the request completes or until we decide to give up | |
cc81d32f | 1154 | bool waitmore = true; |
a85139a1 | 1155 | while ( !client->WaitOnConnect(seconds, millis) && waitmore ) |
261b9a3d GRG |
1156 | { |
1157 | // possibly give some feedback to the user, | |
f6bcfd97 | 1158 | // and update waitmore as needed. |
261b9a3d GRG |
1159 | } |
1160 | bool success = client->IsConnected(); | |
1161 | \end{verbatim} | |
e79848ac GL |
1162 | |
1163 | \wxheading{See also} | |
1164 | ||
fa482912 JS |
1165 | \helpref{wxSocketClient::Connect}{wxsocketclientconnect}, |
1166 | \helpref{wxSocketBase::InterruptWait}{wxsocketbaseinterruptwait}, | |
105521d1 | 1167 | \helpref{wxSocketBase::IsConnected}{wxsocketbaseisconnected} |
e79848ac GL |
1168 | |
1169 | % --------------------------------------------------------------------------- | |
42ff6409 | 1170 | % CLASS: wxSocketEvent |
e79848ac | 1171 | % --------------------------------------------------------------------------- |
42ff6409 | 1172 | \section{\class{wxSocketEvent}}\label{wxsocketevent} |
e79848ac | 1173 | |
42ff6409 | 1174 | This event class contains information about socket events. |
e79848ac GL |
1175 | |
1176 | \wxheading{Derived from} | |
1177 | ||
42ff6409 | 1178 | \helpref{wxEvent}{wxevent} |
e79848ac | 1179 | |
954b8ae6 JS |
1180 | \wxheading{Include files} |
1181 | ||
1182 | <wx/socket.h> | |
1183 | ||
42ff6409 | 1184 | \wxheading{Event table macros} |
e79848ac | 1185 | |
f6bcfd97 BP |
1186 | To process a socket event, use these event handler macros to direct input |
1187 | to member functions that take a wxSocketEvent argument. | |
e79848ac | 1188 | |
42ff6409 JS |
1189 | \twocolwidtha{7cm} |
1190 | \begin{twocollist}\itemsep=0pt | |
1191 | \twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a socket event, supplying the member function.} | |
105521d1 | 1192 | \end{twocollist} |
e79848ac GL |
1193 | |
1194 | \wxheading{See also} | |
1195 | ||
407f3681 JS |
1196 | \helpref{wxSocketBase}{wxsocketbase}, |
1197 | \helpref{wxSocketClient}{wxsocketclient}, | |
42ff6409 | 1198 | \helpref{wxSocketServer}{wxsocketserver} |
e79848ac | 1199 | |
42ff6409 | 1200 | \latexignore{\rtfignore{\wxheading{Members}}} |
e79848ac | 1201 | |
42ff6409 | 1202 | \membersection{wxSocketEvent::wxSocketEvent} |
e79848ac | 1203 | |
42ff6409 | 1204 | \func{}{wxSocketEvent}{\param{int}{ id = 0}} |
e79848ac | 1205 | |
42ff6409 | 1206 | Constructor. |
e79848ac | 1207 | |
5adbbc29 GRG |
1208 | \membersection{wxSocketEvent::GetClientData}\label{wxsocketeventgetclientdata} |
1209 | ||
1210 | \func{void *}{GetClientData}{\void} | |
1211 | ||
1212 | Gets the client data of the socket which generated this event, as | |
1213 | set with \helpref{wxSocketBase::SetClientData}{wxsocketbasesetclientdata}. | |
1214 | ||
061379e2 | 1215 | \membersection{wxSocketEvent::GetSocket}\label{wxsocketeventgetsocket} |
e5a2291a | 1216 | |
061379e2 | 1217 | \constfunc{wxSocketBase *}{GetSocket}{\void} |
e5a2291a GRG |
1218 | |
1219 | Returns the socket object to which this event refers to. This makes | |
1220 | it possible to use the same event handler for different sockets. | |
1221 | ||
061379e2 | 1222 | \membersection{wxSocketEvent::GetSocketEvent}\label{wxsocketeventgetsocketevent} |
e79848ac | 1223 | |
061379e2 | 1224 | \constfunc{wxSocketNotify}{GetSocketEvent}{\void} |
e79848ac | 1225 | |
42ff6409 | 1226 | Returns the socket event type. |
e79848ac | 1227 |