]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/socket.tex
new wxMenu stuff and thread implementations
[wxWidgets.git] / docs / latex / wx / socket.tex
1 \section{\class{wxSocketBase}}\label{wxsocketbase}
2
3 \wxheading{Derived from}
4
5 \helpref{wxEvtHandler}{wxevthandler}
6
7 \wxheading{Include files}
8
9 <wx/socket.h>
10
11 \wxheading{wxSocket errors}%\label{wxsocketerrs} % Labels don't work on a non-section!
12
13 \twocolwidtha{7cm}
14 \begin{twocollist}\itemsep=0pt
15 \twocolitem{{\bf wxSOCKET\_NOERROR}}{No error happened.}
16 \twocolitem{{\bf wxSOCKET\_INVOP}}{Invalid operation.}
17 \twocolitem{{\bf wxSOCKET\_IOERR}}{Input/Output error.}
18 \twocolitem{{\bf wxSOCKET\_INVADDR}}{Invalid address passed to wxSocket.}
19 \twocolitem{{\bf wxSOCKET\_INVSOCK}}{Invalid socket (uninitialized).}
20 \twocolitem{{\bf wxSOCKET\_NOHOST}}{No corresponding host.}
21 \twocolitem{{\bf wxSOCKET\_INVPORT}}{Invalid port.}
22 \twocolitem{{\bf wxSOCKET\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.}
23 \twocolitem{{\bf wxSOCKET\_TIMEDOUT}}{The timeout for this operation expired.}
24 \twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.}
25 \end{twocollist}%
26
27 \wxheading{wxSocket events}
28
29 \twocolwidtha{7cm}
30 \begin{twocollist}\itemsep=0pt
31 \twocolitem{{\bf wxSOCKET\_INPUT}}{Some data has arrived to the socket.}
32 \twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.}
33 \twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection arrival (server), or connection establishment (client).}
34 \twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.}
35 \twocolitem{{\bf wxSOCKET\_MAX\_EVENT}}{This should never happen but the compiler may complain about it.}
36 \end{twocollist}%
37
38 A brief note on how to use these events:
39
40 The {\bf wxSOCKET\_INPUT} event will be issued when the incoming queue
41 was empty and new data arrives, but NOT if new data arrives when there
42 was data waiting in the incoming queue.
43
44 The {\bf wxSOCKET\_OUTPUT} event is issued when a socket is first connected
45 with Connect or accepted with Accept, and then, only after an output operation
46 fails because the output buffer was full, and buffer space becomes available
47 again.
48
49 The {\bf wxSOCKET\_CONNECTION} event is issued when a connection request
50 completes (client) or when a new connection arrives at the pending
51 connections queue (server).
52
53 The {\bf wxSOCKET\_LOST} event is issued when a close indication is
54 received for the socket. This means that the connection broke down or
55 that it was closed by the peer.
56
57 % ---------------------------------------------------------------------------
58 % Event handling
59 % ---------------------------------------------------------------------------
60 \wxheading{Event handling}
61
62 To process events from a socket, use the following event handler macro to direct
63 input to member functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument.
64
65 \twocolwidtha{7cm}%
66 \begin{twocollist}\itemsep=0pt
67 \twocolitem{{\bf EVT\_SOCKET(id, func)}}{A socket event occured.}
68 \end{twocollist}%
69
70 % ---------------------------------------------------------------------------
71 % See also ...
72 % ---------------------------------------------------------------------------
73 \wxheading{See also}
74
75 \helpref{wxSocketEvent}{wxsocketevent}\\
76 \helpref{wxSocketClient}{wxsocketclient}\\
77 \helpref{wxSocketServer}{wxsocketserver}
78
79 % ---------------------------------------------------------------------------
80 % Members
81 % ---------------------------------------------------------------------------
82 \latexignore{\rtfignore{\wxheading{Members}}}
83
84 \membersection{wxSocketBase::wxSocketBase}
85
86 \func{}{wxSocketBase}{\void}
87
88 Default constructor. Don't use it; use \helpref{wxSocketClient}{wxsocketclient}
89 or \helpref{wxSocketServer}{wxsocketserver}.
90
91 \membersection{wxSocketBase::\destruct{wxSocketBase}}
92
93 \func{}{\destruct{wxSocketBase}}{\void}
94
95 Destroys the wxSocketBase object.
96
97 % ---------------------------------------------------------------------------
98 % State functions
99 % ---------------------------------------------------------------------------
100
101 %
102 % SetFlags
103 %
104
105 \membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags}
106
107 \func{void}{SetFlags}{\param{wxSocketBase::wxSockFlags}{ flags}}
108
109 \twocolwidtha{7cm}
110 \begin{twocollist}\itemsep=0pt
111 \twocolitem{{\bf wxSOCKET\_NONE}}{Normal functionnality.}
112 \twocolitem{{\bf wxSOCKET\_NOWAIT}}{Get the available data in the input queue and return immediately.}
113 \twocolitem{{\bf wxSOCKET\_WAITALL}}{Wait for all required data unless an error occurs.}
114 \twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not wxYield) while reading / writing data.}
115 \end{twocollist}
116
117 A brief overview on how to use these flags follows.
118
119 If no flag is specified (this is the same as {\bf wxSOCKET\_NONE}),
120 IO calls will return after some data has been read or written, even
121 when the transfer might not be complete. This is the same as issuing
122 exactly one blocking low-level call to recv() or send(). Note that
123 blocking here refers to when the function returns, not to whether
124 the GUI blocks during this time.
125
126 If {\bf wxSOCKET\_NOWAIT} is specified, IO calls will return immediately.
127 Read operations will retrieve only available data. Write operations will
128 write as much data as possible, depending on how much space is available
129 in the output buffer. This is the same as issuing exactly one nonblocking
130 low-level call to recv() or send(). Note that nonblocking here refers to
131 when the function returns, not to whether the GUI blocks during this time.
132
133 If {\bf wxSOCKET\_WAITALL} is specified, IO calls won't return until ALL
134 the data has been read or written (or until an error occurs), blocking if
135 necessary, and issuing several low level calls if necessary. This is the
136 same as having a loop which makes as many blocking low-level calls to
137 recv() or send() as needed so as to transfer all the data. Note that
138 "blocking" here refers to when the function returns, not to whether
139 the GUI blocks during this time.
140
141 The {\bf wxSOCKET\_BLOCK} controls whether the GUI blocks during IO
142 operations. If this flag is not used, then the application must take
143 extra care to avoid unwanted reentrance.
144
145 So:
146
147 {\bf wxSOCKET\_NONE} will try to read SOME data, no matter how much.
148 {\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot
149 read or write ANY data.
150 {\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL
151 the data.
152 {\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and
153 it control whether the GUI blocks.
154
155 %
156 % SetNotify
157 %
158 \membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
159
160 \func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}}
161
162 SetNotify specifies which socket events are to be sent to the event handler.
163 The {\it flags} parameter is a combination of flags ORed toghether. The
164 following flags can be used:
165
166 \twocolwidtha{7cm}
167 \begin{twocollist}\itemsep=0pt
168 \twocolitem{{\bf wxSOCKET\_INPUT\_FLAG}}{to receive wxSOCKET\_INPUT}
169 \twocolitem{{\bf wxSOCKET\_OUTPUT\_FLAG}}{to receive wxSOCKET\_OUTPUT}
170 \twocolitem{{\bf wxSOCKET\_CONNECTION\_FLAG}}{to receive wxSOCKET\_CONNECTION}
171 \twocolitem{{\bf wxSOCKET\_LOST\_FLAG}}{to receive wxSOCKET\_LOST}
172 \end{twocollist}%
173
174 For example:
175 \begin{verbatim}
176 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
177 \end{verbatim}
178 In this example, the user will be notified about incoming socket data and
179 whenever the connection is closed.
180
181 For more information on socket events see \helpref{wxSocket events}{wxsocketbase}.
182
183 %
184 % SetTimeout
185 %
186 \membersection{wxSocketBase::SetTimeout}{wxsocketbasesettimeout}
187
188 \func{void}{SetTimeout}{\param{int }{seconds}}
189
190 This function sets the default socket timeout in seconds. This
191 timeout applies to IO calls and also to Wait functions if you
192 don't specify a wait interval. If you never use SetTimeout, the
193 default timeout will be 10 minutes.
194
195 %
196 % Notify
197 %
198 \membersection{wxSocketBase::Notify}\label{wxsocketbasenotify}
199
200 \func{void}{Notify}{\param{bool}{ notify}}
201
202 Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
203 of socket events.
204
205 %
206 % Ok
207 %
208
209 \membersection{wxSocketBase::Ok}\label{wxsocketbaseok}
210
211 \constfunc{bool}{Ok}{\void}
212
213 Returns TRUE if the socket is initialized and ready and FALSE in other
214 cases.
215
216 \membersection{wxSocketBase::Error}\label{wxsocketbaseerror}
217
218 \constfunc{bool}{Error}{\void}
219
220 Returns TRUE if an error occured in the last IO operation.
221
222 The following operations update the Error() status:
223 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
224
225 \membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected}
226
227 \constfunc{bool}{IsConnected}{\void}
228
229 Returns TRUE if the socket is connected.
230
231 \membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata}
232
233 \constfunc{bool}{IsData}{\void}
234
235 Returns TRUE if there is data available to be read.
236
237 \membersection{wxSocketBase::IsDisconnected}\label{wxsocketbasedisconnected}
238
239 \constfunc{bool}{IsDisconnected}{\void}
240
241 Returns TRUE if the socket is disconnected.
242
243 \membersection{wxSocketBase::IsNoWait}\label{wxsocketbasenowait}
244
245 \constfunc{bool}{IsNoWait}{\void}
246
247 Returns TRUE if the socket mustn't wait.
248
249 \membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount}
250
251 \constfunc{wxUint32}{LastCount}{\void}
252
253 Returns the number of bytes read or written by the last IO call.
254
255 The following operations update the LastCount() value:
256 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
257
258 \membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
259
260 \constfunc{wxSocketError}{LastError}{\void}
261
262 Returns the last wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}.
263
264 Please note that this function merely returns the last error code,
265 but it should not be used to determine if an error has occured (this
266 is because successful operations do not change tha LastError value).
267 Use Error, instead of LastError, to determine if the last IO call
268 failed. If Error returns TRUE, use LastError to discover the
269 cause of the error.
270
271 % ---------------------------------------------------------------------------
272 % IO calls
273 % ---------------------------------------------------------------------------
274 %
275 % Peek
276 %
277 \membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
278
279 \func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
280
281 This function peeks a buffer of {\it nbytes} bytes from the socket. Peeking a buffer
282 doesn't delete it from the system socket in-queue.
283
284 Use LastCount to verify the number of bytes actually peeked.
285
286 Use Error to determine if the operation succeeded.
287
288 \wxheading{Parameters}
289
290 \docparam{buffer}{Buffer where to put peeked data.}
291
292 \docparam{nbytes}{Number of bytes.}
293
294 \wxheading{Return value}
295
296 Returns a reference to the current object.
297
298 \wxheading{Remark/Warning}
299
300 The exact behaviour of wxSocketBase::Peek() depends on the combination
301 of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
302
303 \wxheading{See also}
304
305 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
306 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
307 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
308 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
309
310 %
311 % Read
312 %
313 \membersection{wxSocketBase::Read}\label{wxsocketbaseread}
314
315 \func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
316
317 This function reads a buffer of {\it nbytes} bytes from the socket.
318
319 Use LastCount to verify the number of bytes actually read.
320
321 Use Error to determine if the operation succeeded.
322
323 \wxheading{Parameters}
324
325 \docparam{buffer}{Buffer where to put read data.}
326
327 \docparam{nbytes}{Number of bytes.}
328
329 \wxheading{Return value}
330
331 Returns a reference to the current object.
332
333 \wxheading{Remark/Warning}
334
335 The exact behaviour of wxSocketBase::Read() depends on the combination
336 of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
337
338 \wxheading{See also}
339
340 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
341 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
342 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
343 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
344
345 %
346 % Write
347 %
348 \membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
349
350 \func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
351
352 This function writes a buffer of {\it nbytes} bytes to the socket.
353
354 Use LastCount to verify the number of bytes actually written.
355
356 Use Error to determine if the operation succeeded.
357
358 \wxheading{Parameters}
359
360 \docparam{buffer}{Buffer with the data to be sent.}
361
362 \docparam{nbytes}{Number of bytes.}
363
364 \wxheading{Return value}
365
366 Returns a reference to the current object.
367
368 \wxheading{Remark/Warning}
369
370 The exact behaviour of wxSocketBase::Write() depends on the combination
371 of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
372
373 \wxheading{See also}
374
375 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
376 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
377 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
378 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
379
380 %
381 % WriteMsg
382 %
383 \membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
384
385 \func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
386
387 This function writes a buffer of {\it nbytes} bytes from the socket, but it
388 writes a short header before so that ReadMsg can alloc the right size for
389 the buffer. So, a buffer sent with WriteMsg {\bf must} be read with ReadMsg.
390 This function always waits for the entire buffer to be sent, unless an
391 error occurs.
392
393 Use LastCount to verify the number of bytes actually written.
394
395 Use Error to determine if the operation succeeded.
396
397 \wxheading{Parameters}
398
399 \docparam{buffer}{Buffer with the data to be sent.}
400
401 \docparam{nbytes}{Number of bytes.}
402
403 \wxheading{Return value}
404
405 Returns a reference to the current object.
406
407 \wxheading{Remark/Warning}
408
409 wxSocketBase::WriteMsg() will behave as if the wxSOCKET_WAITALL flag was always set
410 and it will always ignore the wxSOCKET_NOWAIT flag. The exact behaviour of WriteMsg
411 depends on the wxSOCKET_BLOCK flag. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
412
413 \wxheading{See also}
414
415 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
416 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
417 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
418 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}\\
419 \helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
420
421 %
422 % ReadMsg
423 %
424 \membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
425
426 \func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
427
428 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
429 to the function isn't big enough, the remaining bytes will be discarded. This
430 function always waits for the buffer to be entirely filled, unless an error occurs.
431
432 Use LastCount to verify the number of bytes actually read.
433
434 Use Error to determine if the operation succeeded.
435
436 \wxheading{Parameters}
437
438 \docparam{buffer}{Buffer where to put read data.}
439
440 \docparam{nbytes}{Number of bytes allocated for the buffer.}
441
442 \wxheading{Return value}
443
444 Returns a reference to the current object.
445
446 \wxheading{Remark/Warning}
447
448 wxSocketBase::ReadMsg() will behave as if the wxSOCKET_WAITALL flag was always set
449 and it will always ignore the wxSOCKET_NOWAIT flag. The exact behaviour of ReadMsg
450 depends on the wxSOCKET_SPEED flag. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
451
452 \wxheading{See also}
453
454 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
455 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
456 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
457 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}\\
458 \helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
459
460 %
461 % Unread
462 %
463 \membersection{wxSocketBase::Unread}\label{wxsocketbaseunread}
464
465 \func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
466
467 This function unreads a buffer. That is, the data in the buffer is put back
468 in the incoming queue. This function is not affected by wxSocket flags.
469
470 If you use LastCount, it will always return {\it nbytes}.
471
472 If you use Error, it will always return FALSE.
473
474 \wxheading{Parameters}
475
476 \docparam{buffer}{Buffer to be unread.}
477
478 \docparam{nbytes}{Number of bytes.}
479
480 \wxheading{Return value}
481
482 Returns a reference to the current object.
483
484 \wxheading{See also}
485
486 \helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
487 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
488 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
489
490 %
491 % Discard
492 %
493 \membersection{wxSocketBase::Discard}\label{wxsocketbasediscard}
494
495 \func{wxSocketBase\&}{Discard}{\void}
496
497 This function simply deletes all bytes in the incoming queue. This function
498 doesn't wait. That is, it will behave as if the wxSOCKET_NOWAIT flag was set. The
499 wxSOCKET_SPEED and wxSOCKET_WAITALL flags have no effect on this function.
500
501 Use LastCount to see the number of bytes discarded.
502
503 If you use Error, it will always return FALSE.
504
505 % ---------------------------------------------------------------------------
506 % Wait functions
507 % ---------------------------------------------------------------------------
508 \membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
509
510 \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
511
512 This function waits until one of the following conditions is true: there
513 is data available for reading; the output buffer is empty (you can send
514 new data); the connection has been lost; an incoming connection arrived
515 (only for servers); a connection request has completed (only for clients).
516
517 \wxheading{Parameters}
518
519 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
520
521 \docparam{millisecond}{Number of milliseconds to wait.}
522
523 \wxheading{Return value}
524
525 Returns TRUE if an event occured, FALSE if the timeout was reached.
526
527 \wxheading{See also}
528
529 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
530 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
531 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
532
533 %
534 % WaitForRead
535 %
536 \membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
537
538 \func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
539
540 This function waits until there is data available to be read.
541
542 \wxheading{Parameters}
543
544 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
545
546 \docparam{millisecond}{Number of milliseconds to wait.}
547
548 \wxheading{Return value}
549
550 Returns TRUE if there is data to be read, FALSE if the timeout was reached.
551
552 \wxheading{See also}
553
554 \helpref{wxSocketBase::Wait}{wxsocketbasewait}\\
555 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
556 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
557
558 %
559 % WaitForWrite
560 %
561 \membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
562
563 \func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
564
565 This function waits until you can write to the socket.
566
567 \wxheading{Parameters}
568
569 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
570
571 \docparam{millisecond}{Number of milliseconds to wait.}
572
573 \wxheading{Return value}
574
575 Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
576
577 \wxheading{See also}
578
579 \helpref{wxSocketBase::Wait}{wxsocketbasewait}\\
580 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
581 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
582
583 %
584 % WaitForLost
585 %
586 \membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
587
588 \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
589
590 This function waits until the connection is lost. This may happen if the
591 peer closes the connection or if the connection breaks.
592
593 \wxheading{Parameters}
594
595 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
596
597 \docparam{millisecond}{Number of milliseconds to wait.}
598
599 \wxheading{Return value}
600
601 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
602
603 \wxheading{See also}
604
605 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
606 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
607 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
608
609 % ---------------------------------------------------------------------------
610 % Socket state
611 % ---------------------------------------------------------------------------
612
613 %
614 % RestoreState
615 %
616 \membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
617
618 \func{void}{RestoreState}{\void}
619
620 This function restores the previous state of the socket, as saved
621 with SaveState.
622
623 Calls to SaveState / RestoreState can be nested.
624
625 \wxheading{See also}
626
627 \helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
628
629 %
630 % SaveState
631 %
632 \membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
633
634 \func{void}{SaveState}{\void}
635
636 This function saves the current state of the socket object in a stack:
637 actually it saves all flags (those set with SetFlags, SetNotify, Notfy)
638 and the state of the asynchronous callbacks (Callback, CallbackData).
639
640 Calls to SaveState / RestoreState can be nested.
641
642 \wxheading{See also}
643
644 \helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
645
646 %
647 % GetLocal
648 %
649 \membersection{wxSocketBase::GetLocal}{wxsocketbasegetlocal}
650
651 \constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr_man}}
652
653 This function returns the local address field of the socket. The local
654 address field contains the complete local address of the socket (local
655 address, local port, ...).
656
657 \wxheading{Return value}
658
659 It returns TRUE if no errors happened, FALSE otherwise.
660
661 %
662 % GetPeer
663 %
664 \membersection{wxSocketBase::GetPeer}{wxsocketbasegetlocal}
665
666 \constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr_man}}
667
668 This function returns the peer address field of the socket. The peer
669 address field contains the complete peer host address of the socket
670 (address, port, ...).
671
672 \wxheading{Return value}
673
674 It returns TRUE if no errors happened, FALSE otherwise.
675
676 % ---------------------------------------------------------------------------
677 % Socket callbacks
678 % ---------------------------------------------------------------------------
679 \membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler}
680
681 \func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
682
683 Sets an event handler to be called when a socket event occurs. The handler
684 will be called for those events for which notification is enabled with
685 SetNotify and Notify.
686
687 You can also specify a C callback to be called when an event occurs. See
688 Callback and CallbackData.
689
690 \wxheading{Parameters}
691
692 \docparam{evt\_hdlr}{Specifies the event handler you want to use.}
693
694 \docparam{id}{The id of socket event.}
695
696 \wxheading{See also}
697
698 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
699 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}\\
700 \helpref{wxSocketEvent}{wxsocketevent}\\
701 \helpref{wxEvtHandler}{wxevthandler}\\
702 \helpref{wxSocketBase::Callback}{wxsocketbasecallback}\\
703 \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}
704
705 \membersection{wxSocketBase::Callback}\label{wxsocketbasecallback}
706
707 \func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}}
708
709 You can setup a C callback to be called when an event occurs. The callback
710 will be called only for those events for which notification has been enabled
711 with Notify and SetNotify. The prototype of the callback must be as follows:
712
713 \begin{verbatim}
714 void SocketCallback(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
715 \end{verbatim}
716
717 The first parameter is a reference to the socket object in which the event
718 occured. The second parameter tells you which event occured. (See \helpref{wxSocket events}{wxsocketbase}).
719 The third parameter is the user data you specified using \helpref{CallbackData}{wxsocketcallbackdata}.
720
721 \wxheading{Return value}
722
723 A pointer to the previous callback.
724
725 \wxheading{See also}
726
727 \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}\\
728 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
729 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
730
731 \membersection{wxSocketBase::CallbackData}\label{wxsocketbasecallbackdata}
732
733 \func{char *}{CallbackData}{\param{char *}{cdata}}
734
735 This function sets the the user data which will be passed to a \helpref{C callback}{wxsocketbasecallback}.
736
737 \wxheading{Return value}
738
739 A pointer to the previous user data.
740
741 \helpref{wxSocketBase::Callback}{wxsocketbasecallback}\\
742 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
743 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
744
745 % ---------------------------------------------------------------------------
746 % CLASS wxSocketClient
747 % ---------------------------------------------------------------------------
748 \section{\class{wxSocketClient}}\label{wxsocketclient}
749
750 \wxheading{Derived from}
751
752 \helpref{wxSocketBase}{wxsocketbase}
753
754 \wxheading{Include files}
755
756 <wx/socket.h>
757
758 % ---------------------------------------------------------------------------
759 % Members
760 % ---------------------------------------------------------------------------
761 %
762 % wxSocketClient
763 %
764 \membersection{wxSocketClient::wxSocketClient}
765
766 \func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
767
768 Constructs a new wxSocketClient.
769
770 \wxheading{Parameters}
771
772 \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
773
774 %
775 % ~wxSocketClient
776 %
777 \membersection{wxSocketClient::\destruct{wxSocketClient}}
778
779 \func{}{\destruct{wxSocketClient}}{\void}
780
781 Destroys a wxSocketClient object.
782
783 %
784 % Connect
785 %
786 \membersection{wxSocketClient::Connect}\label{wxsocketclientconnect}
787
788 \func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
789
790 Connects to a server using the specified address.
791
792 If {\it wait} is TRUE, Connect will wait until the connection completes and
793 the socket is ready to send or receive data, or until an event occurs.
794 {\bf Warning !} This will block the GUI.
795
796 If {\it wait} is FALSE, Connect will try to establish the connection and
797 return immediately, without blocking the GUI. When used this way, even if
798 Connect returns FALSE, the connection request can be completed later.
799 To detect this, use WaitConnection, or watch "connection" events (for
800 succesful establishment) and "lost" events (for connection failure)
801
802
803 \wxheading{Parameters}
804
805 \docparam{address}{Address of the server.}
806
807 \docparam{wait}{If true, waits for the connection to be ready.}
808
809 \wxheading{Return value}
810
811 Returns TRUE if the connection is established and no error occurs.
812
813 If {\it wait} was TRUE, and Connect returns FALSE, an error occured
814 and the connection failed.
815
816 If {\it wait} was FALSE, and Connect returns FALSE, you should still
817 be prepared to handle the completion of this connection request, either
818 with WaitOnConnect or by watching "connection" and "lost" events.
819
820 \wxheading{See also}
821
822 \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}\\
823 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
824 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
825
826 %
827 % WaitOnConnect
828 %
829 \membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect}
830
831 \func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}}
832
833 Wait until the connection is succesfully established or until it fails.
834 Use this function after a call to Connect with {\it wait} set to FALSE.
835
836 \wxheading{Parameters}
837
838 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
839
840 \docparam{millisecond}{Number of milliseconds to wait.}
841
842 \wxheading{Return value}
843
844 If the connection is succesfully established, it returns TRUE.
845
846 If the timeout expires, or if the connection fails, it returns FALSE.
847
848 \wxheading{See also}
849
850 \helpref{wxSocketClient::Connect}{wxsocketclientconnect}
851
852 % ---------------------------------------------------------------------------
853 % CLASS: wxSocketEvent
854 % ---------------------------------------------------------------------------
855 \section{\class{wxSocketEvent}}\label{wxsocketevent}
856
857 This event class contains information about socket events.
858
859 \wxheading{Derived from}
860
861 \helpref{wxEvent}{wxevent}
862
863 \wxheading{Include files}
864
865 <wx/socket.h>
866
867 \wxheading{Event table macros}
868
869 To process a socket event, use these event handler macros to direct input to member
870 functions that take a wxSocketEvent argument.
871
872 \twocolwidtha{7cm}
873 \begin{twocollist}\itemsep=0pt
874 \twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a socket event, supplying the member function.}
875 \end{twocollist}%
876
877 [TODO:]
878 A brief note on how to use events.
879 The wxSOCKET_INPUT event is generated when the
880
881 \wxheading{See also}
882
883 \helpref{wxSocketBase}{wxsocketbase},\rtfsp
884 \helpref{wxSocketClient}{wxsocketclient},\rtfsp
885 \helpref{wxSocketServer}{wxsocketserver}
886
887 \latexignore{\rtfignore{\wxheading{Members}}}
888
889 \membersection{wxSocketEvent::wxSocketEvent}
890
891 \func{}{wxSocketEvent}{\param{int}{ id = 0}}
892
893 Constructor.
894
895 \membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
896
897 \constfunc{wxSocketNotify}{SocketEvent}{\void}
898
899 Returns the socket event type.
900
901 % ---------------------------------------------------------------------------
902 % CLASS: wxSocketServer
903 % ---------------------------------------------------------------------------
904 \section{\class{wxSocketServer}}\label{wxsocketserver}
905
906 \wxheading{Derived from}
907
908 \helpref{wxSocketBase}{wxsocketbase}
909
910 \wxheading{Include files}
911
912 <wx/socket.h>
913
914 % ---------------------------------------------------------------------------
915 % Members
916 % ---------------------------------------------------------------------------
917 \latexignore{\rtfignore{\wxheading{Members}}}
918
919 %
920 % wxSocketServer
921 %
922 \membersection{wxSocketServer::wxSocketServer}\label{wxsocketserverconstr}
923
924 \func{}{wxSocketServer}{\param{wxSockAddress\&}{ address}, \param{wxSockFlags}{ flags = wxSocketBase::NONE}}
925
926 Constructs a new wxSocketServer.
927
928 \wxheading{Parameters}
929
930 \docparam{address}{Specifies the local address for the server (e.g. port number).}
931
932 \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
933
934 %
935 % ~wxSocketServer
936 %
937 \membersection{wxSocketServer::\destruct{wxSocketServer}}
938
939 \func{}{\destruct{wxSocketServer}}{\void}
940
941 Destroys a wxSocketServer object (it doesn't close the accepted connections).
942
943 %
944 % Accept
945 %
946 \membersection{wxSocketServer::Accept}
947
948 \func{wxSocketBase *}{Accept}{\param{bool}{ wait = TRUE}}
949
950 Creates a new object wxSocketBase and accepts an incoming connection.
951
952 If {\it wait} is TRUE and there are no pending connections to be
953 accepted, it will wait for the next incoming connection to arrive.
954 {\bf Warning !} This will block the GUI.
955
956 If {\it wait} is FALSE, it will try to accept a pending connection
957 if there is one, but it will always return immediately without
958 blocking the GUI. If you want to use Accept in this way, you can
959 either check for incoming connections with WaitForAccept or watch
960 "connection" events, then call Accept once you know that there is
961 an incoming connection waiting to be accepted.
962
963 \wxheading{Return value}
964
965 Returns an opened socket connection, or NULL if an error occured or
966 if the {\it wait} parameter was FALSE and there were no pending
967 connections.
968
969 \wxheading{See also}
970
971 \helpref{wxSocketServer::WaitForAccept}{wxsocketbasewaitforaccept}\\
972 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
973 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}\\
974 \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
975
976 %
977 % AcceptWith
978 %
979 \membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith}
980
981 \func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}, \param{bool}{ wait = TRUE}}
982
983 Accept an incoming connection using the specified socket object.
984 This is useful when someone wants to inherit wxSocketBase.
985
986 \wxheading{Parameters}
987
988 \docparam{socket}{Socket to be initialized}
989
990 \wxheading{Return value}
991
992 Returns TRUE on success, or FALSE if an error occured or if the
993 {\it wait} parameter was FALSE and there were no pending
994 connections.
995
996 \helpref{wxSocketServer::WaitForAccept}{wxsocketbasewaitforaccept}\\
997 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}\\
998 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}\\
999 \helpref{wxSocketServer::Accept}{wxsocketserveraccept} for a detailed explanation
1000
1001
1002 %
1003 % WaitForAccept
1004 %
1005 \membersection{wxSocketServer::WaitForAccept}\label{wxsocketserverwaitforaccept}
1006
1007 \func{bool}{WaitForAccept}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
1008
1009 This function waits for an incoming connection. Use it if you want to call
1010 Accept or AcceptWith with {\it wait} set to FALSE, to detect when an incoming
1011 connection is waiting to be accepted.
1012
1013 \wxheading{Parameters}
1014
1015 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
1016
1017 \docparam{millisecond}{Number of milliseconds to wait.}
1018
1019 \wxheading{Return value}
1020
1021 Returns TRUE if an incoming connection arrived, FALSE if the timeout expired.
1022
1023 \wxheading{See also}
1024
1025 \helpref{wxSocketServer::Accept}{wxsocketserveraccept}\\
1026 \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
1027
1028