1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Socket handler classes
4 // Authors: Guilhem Lavaux, Guillermo Rodriguez Garcia
6 // Copyright: (C) 1999-1997, Guilhem Lavaux
7 // (C) 2000-1999, Guillermo Rodriguez Garcia
9 // License: see wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "socket.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 // ==========================================================================
26 // Headers and constants
27 // ==========================================================================
31 #include "wx/object.h"
32 #include "wx/string.h"
35 #include "wx/module.h"
41 #include "wx/gdicmn.h" // for wxPendingDelete
44 #include "wx/sckaddr.h"
45 #include "wx/socket.h"
49 #define MAX_DISCARD_SIZE (10 * 1024)
51 // what to do within waits
53 #define PROCESS_EVENTS() wxYield()
55 #define PROCESS_EVENTS()
58 // use wxPostEvent or not
59 #define USE_DELAYED_EVENTS 1
62 // --------------------------------------------------------------------------
64 // --------------------------------------------------------------------------
66 IMPLEMENT_CLASS(wxSocketBase
, wxObject
)
67 IMPLEMENT_CLASS(wxSocketServer
, wxSocketBase
)
68 IMPLEMENT_CLASS(wxSocketClient
, wxSocketBase
)
69 IMPLEMENT_CLASS(wxDatagramSocket
, wxSocketBase
)
70 IMPLEMENT_DYNAMIC_CLASS(wxSocketEvent
, wxEvent
)
72 class wxSocketState
: public wxObject
76 wxSocketEventFlags m_neededreq
;
77 wxSocketFlags m_flags
;
78 wxSocketBase::wxSockCbk m_cbk
;
82 wxSocketState() : wxObject() {}
86 // ==========================================================================
88 // ==========================================================================
90 // --------------------------------------------------------------------------
92 // --------------------------------------------------------------------------
94 void wxSocketBase::Init()
97 m_type
= wxSOCKET_UNINIT
;
108 m_beingDeleted
= FALSE
;
119 m_notify_state
= FALSE
;
125 wxSocketBase::wxSocketBase()
130 wxSocketBase::wxSocketBase(wxSocketFlags flags
, wxSocketType type
)
138 wxSocketBase::~wxSocketBase()
140 // Just in case the app called Destroy() *and* then deleted
141 // the socket immediately: don't leave dangling pointers.
143 wxPendingDelete
.DeleteObject(this);
146 // Shutdown and close the socket
150 // Destroy the GSocket object
152 GSocket_destroy(m_socket
);
154 // Free the pushback buffer
159 bool wxSocketBase::Destroy()
161 // Delayed destruction: the socket will be deleted during the next
162 // idle loop iteration. This ensures that all pending events have
164 m_beingDeleted
= TRUE
;
166 // Shutdown and close the socket
170 if ( wxPendingDelete
.Member(this) )
171 wxPendingDelete
.Append(this);
180 // --------------------------------------------------------------------------
181 // Basic IO operations
182 // --------------------------------------------------------------------------
184 // The following IO operations update m_error and m_lcount:
185 // {Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard}
187 // TODO: Should Connect, Accept and AcceptWith update m_error?
189 bool wxSocketBase::Close()
191 // Interrupt pending waits
197 GSocket_UnsetCallback(m_socket
, GSOCK_INPUT_FLAG
| GSOCK_OUTPUT_FLAG
|
198 GSOCK_LOST_FLAG
| GSOCK_CONNECTION_FLAG
);
200 // Shutdown the connection
201 GSocket_Shutdown(m_socket
);
205 m_establishing
= FALSE
;
209 wxSocketBase
& wxSocketBase::Read(void* buffer
, wxUint32 nbytes
)
214 m_lcount
= _Read(buffer
, nbytes
);
216 // If in wxSOCKET_WAITALL mode, all bytes should have been read.
217 if (m_flags
& wxSOCKET_WAITALL
)
218 m_error
= (m_lcount
!= nbytes
);
220 m_error
= (m_lcount
== 0);
222 // Allow read events from now on
228 wxUint32
wxSocketBase::_Read(void* buffer
, wxUint32 nbytes
)
233 // Try the pushback buffer first
234 total
= GetPushback(buffer
, nbytes
, FALSE
);
236 buffer
= (char *)buffer
+ total
;
238 // If the socket is invalid or we got all the data, return now
239 if (!m_socket
|| !nbytes
)
242 // Possible combinations (they are checked in this order)
244 // wxSOCKET_WAITALL | wxSOCKET_BLOCK
249 if (m_flags
& wxSOCKET_NOWAIT
)
251 GSocket_SetNonBlocking(m_socket
, TRUE
);
252 ret
= GSocket_Read(m_socket
, (char *)buffer
, nbytes
);
253 GSocket_SetNonBlocking(m_socket
, FALSE
);
258 else if (m_flags
& wxSOCKET_WAITALL
)
260 while (ret
> 0 && nbytes
> 0)
262 if (!(m_flags
& wxSOCKET_BLOCK
) && !WaitForRead())
265 ret
= GSocket_Read(m_socket
, (char *)buffer
, nbytes
);
271 buffer
= (char *)buffer
+ ret
;
277 if ((m_flags
& wxSOCKET_BLOCK
) || WaitForRead())
279 ret
= GSocket_Read(m_socket
, (char *)buffer
, nbytes
);
289 wxSocketBase
& wxSocketBase::ReadMsg(void* buffer
, wxUint32 nbytes
)
291 wxUint32 len
, len2
, sig
, total
;
296 unsigned char sig
[4];
297 unsigned char len
[4];
306 SetFlags((m_flags
& wxSOCKET_BLOCK
) | wxSOCKET_WAITALL
);
308 if (_Read(&msg
, sizeof(msg
)) != sizeof(msg
))
311 sig
= (wxUint32
)msg
.sig
[0];
312 sig
|= (wxUint32
)(msg
.sig
[1] << 8);
313 sig
|= (wxUint32
)(msg
.sig
[2] << 16);
314 sig
|= (wxUint32
)(msg
.sig
[3] << 24);
316 if (sig
!= 0xfeeddead)
318 wxLogWarning( _("wxSocket: invalid signature in ReadMsg."));
322 len
= (wxUint32
)msg
.len
[0];
323 len
|= (wxUint32
)(msg
.len
[1] << 8);
324 len
|= (wxUint32
)(msg
.len
[2] << 16);
325 len
|= (wxUint32
)(msg
.len
[3] << 24);
335 // Don't attemp to read if the msg was zero bytes long.
338 total
= _Read(buffer
, len
);
345 char *discard_buffer
= new char[MAX_DISCARD_SIZE
];
348 // NOTE: discarded bytes don't add to m_lcount.
351 discard_len
= ((len2
> MAX_DISCARD_SIZE
)? MAX_DISCARD_SIZE
: len2
);
352 discard_len
= _Read(discard_buffer
, (wxUint32
)discard_len
);
353 len2
-= (wxUint32
)discard_len
;
355 while ((discard_len
> 0) && len2
);
357 delete [] discard_buffer
;
362 if (_Read(&msg
, sizeof(msg
)) != sizeof(msg
))
365 sig
= (wxUint32
)msg
.sig
[0];
366 sig
|= (wxUint32
)(msg
.sig
[1] << 8);
367 sig
|= (wxUint32
)(msg
.sig
[2] << 16);
368 sig
|= (wxUint32
)(msg
.sig
[3] << 24);
370 if (sig
!= 0xdeadfeed)
372 wxLogWarning( _("wxSocket: invalid signature in ReadMsg."));
388 wxSocketBase
& wxSocketBase::Peek(void* buffer
, wxUint32 nbytes
)
393 m_lcount
= _Read(buffer
, nbytes
);
394 Pushback(buffer
, m_lcount
);
396 // If in wxSOCKET_WAITALL mode, all bytes should have been read.
397 if (m_flags
& wxSOCKET_WAITALL
)
398 m_error
= (m_lcount
!= nbytes
);
400 m_error
= (m_lcount
== 0);
402 // Allow read events again
408 wxSocketBase
& wxSocketBase::Write(const void *buffer
, wxUint32 nbytes
)
413 m_lcount
= _Write(buffer
, nbytes
);
415 // If in wxSOCKET_WAITALL mode, all bytes should have been written.
416 if (m_flags
& wxSOCKET_WAITALL
)
417 m_error
= (m_lcount
!= nbytes
);
419 m_error
= (m_lcount
== 0);
421 // Allow write events again
427 wxUint32
wxSocketBase::_Write(const void *buffer
, wxUint32 nbytes
)
432 // If the socket is invalid, return immediately
436 // Possible combinations (they are checked in this order)
438 // wxSOCKET_WAITALL | wxSOCKET_BLOCK
443 if (m_flags
& wxSOCKET_NOWAIT
)
445 GSocket_SetNonBlocking(m_socket
, TRUE
);
446 ret
= GSocket_Write(m_socket
, (const char *)buffer
, nbytes
);
447 GSocket_SetNonBlocking(m_socket
, FALSE
);
452 else if (m_flags
& wxSOCKET_WAITALL
)
454 while (ret
> 0 && nbytes
> 0)
456 if (!(m_flags
& wxSOCKET_BLOCK
) && !WaitForWrite())
459 ret
= GSocket_Write(m_socket
, (const char *)buffer
, nbytes
);
465 buffer
= (const char *)buffer
+ ret
;
471 if ((m_flags
& wxSOCKET_BLOCK
) || WaitForWrite())
473 ret
= GSocket_Write(m_socket
, (const char *)buffer
, nbytes
);
483 wxSocketBase
& wxSocketBase::WriteMsg(const void *buffer
, wxUint32 nbytes
)
490 unsigned char sig
[4];
491 unsigned char len
[4];
500 SetFlags((m_flags
& wxSOCKET_BLOCK
) | wxSOCKET_WAITALL
);
502 msg
.sig
[0] = (unsigned char) 0xad;
503 msg
.sig
[1] = (unsigned char) 0xde;
504 msg
.sig
[2] = (unsigned char) 0xed;
505 msg
.sig
[3] = (unsigned char) 0xfe;
507 msg
.len
[0] = (unsigned char) (nbytes
& 0xff);
508 msg
.len
[1] = (unsigned char) ((nbytes
>> 8) & 0xff);
509 msg
.len
[2] = (unsigned char) ((nbytes
>> 16) & 0xff);
510 msg
.len
[3] = (unsigned char) ((nbytes
>> 24) & 0xff);
512 if (_Write(&msg
, sizeof(msg
)) < sizeof(msg
))
515 total
= _Write(buffer
, nbytes
);
520 msg
.sig
[0] = (unsigned char) 0xed;
521 msg
.sig
[1] = (unsigned char) 0xfe;
522 msg
.sig
[2] = (unsigned char) 0xad;
523 msg
.sig
[3] = (unsigned char) 0xde;
524 msg
.len
[0] = msg
.len
[1] = msg
.len
[2] = msg
.len
[3] = (char) 0;
526 if ((_Write(&msg
, sizeof(msg
))) < sizeof(msg
))
540 wxSocketBase
& wxSocketBase::Unread(const void *buffer
, wxUint32 nbytes
)
543 Pushback(buffer
, nbytes
);
551 wxSocketBase
& wxSocketBase::Discard()
554 char *buffer
= new char[MAX_DISCARD_SIZE
];
562 SetFlags(wxSOCKET_NOWAIT
);
566 ret
= _Read(buffer
, MAX_DISCARD_SIZE
);
569 while (ret
== MAX_DISCARD_SIZE
);
575 // Allow read events again
581 // --------------------------------------------------------------------------
583 // --------------------------------------------------------------------------
585 // All Wait functions poll the socket using GSocket_Select() to
586 // check for the specified combination of conditions, until one
587 // of these conditions become true, an error occurs, or the
588 // timeout elapses. The polling loop calls PROCESS_EVENTS(), so
589 // this won't block the GUI.
591 bool wxSocketBase::_Wait(long seconds
, long milliseconds
,
592 wxSocketEventFlags flags
)
594 GSocketEventFlags result
;
597 // Set this to TRUE to interrupt ongoing waits
600 // Check for valid socket
604 // Check for valid timeout value.
606 timeout
= seconds
* 1000 + milliseconds
;
608 timeout
= m_timeout
* 1000;
610 // Active polling (without using events)
612 // NOTE: this duplicates some of the code in OnRequest (lost
613 // connection and connection establishment handling) but
614 // this doesn't hurt. It has to be here because the event
615 // might be a bit delayed, and it has to be in OnRequest
616 // as well because maybe the Wait functions are not being
619 // Do this at least once (important if timeout == 0, when
620 // we are just polling). Also, if just polling, do not yield.
627 result
= GSocket_Select(m_socket
, flags
| GSOCK_LOST_FLAG
);
629 // Incoming connection (server) or connection established (client)
630 if (result
& GSOCK_CONNECTION_FLAG
)
633 m_establishing
= FALSE
;
637 // Data available or output buffer ready
638 if ((result
& GSOCK_INPUT_FLAG
) || (result
& GSOCK_OUTPUT_FLAG
))
644 if (result
& GSOCK_LOST_FLAG
)
647 m_establishing
= FALSE
;
648 return (flags
& GSOCK_LOST_FLAG
);
652 if ((!timeout
) || (chrono
.Time() > timeout
) || (m_interrupt
))
661 bool wxSocketBase::Wait(long seconds
, long milliseconds
)
663 return _Wait(seconds
, milliseconds
, GSOCK_INPUT_FLAG
|
665 GSOCK_CONNECTION_FLAG
|
669 bool wxSocketBase::WaitForRead(long seconds
, long milliseconds
)
671 // Check pushback buffer before entering _Wait
675 // Note that GSOCK_INPUT_LOST has to be explicitly passed to
676 // _Wait becuase of the semantics of WaitForRead: a return
677 // value of TRUE means that a GSocket_Read call will return
678 // immediately, not that there is actually data to read.
680 return _Wait(seconds
, milliseconds
, GSOCK_INPUT_FLAG
|
684 bool wxSocketBase::WaitForWrite(long seconds
, long milliseconds
)
686 return _Wait(seconds
, milliseconds
, GSOCK_OUTPUT_FLAG
);
689 bool wxSocketBase::WaitForLost(long seconds
, long milliseconds
)
691 return _Wait(seconds
, milliseconds
, GSOCK_LOST_FLAG
);
694 // --------------------------------------------------------------------------
696 // --------------------------------------------------------------------------
699 // Get local or peer address
702 bool wxSocketBase::GetPeer(wxSockAddress
& addr_man
) const
709 peer
= GSocket_GetPeer(m_socket
);
710 addr_man
.SetAddress(peer
);
711 GAddress_destroy(peer
);
716 bool wxSocketBase::GetLocal(wxSockAddress
& addr_man
) const
723 local
= GSocket_GetLocal(m_socket
);
724 addr_man
.SetAddress(local
);
725 GAddress_destroy(local
);
731 // Save and restore socket state
734 void wxSocketBase::SaveState()
736 wxSocketState
*state
;
738 state
= new wxSocketState();
740 state
->m_notify_state
= m_notify_state
;
741 state
->m_neededreq
= m_neededreq
;
742 state
->m_flags
= m_flags
;
743 state
->m_cbk
= m_cbk
;
744 state
->m_cdata
= m_cdata
;
746 m_states
.Append(state
);
749 void wxSocketBase::RestoreState()
752 wxSocketState
*state
;
754 node
= m_states
.Last();
758 state
= (wxSocketState
*)node
->Data();
760 SetFlags(state
->m_flags
);
761 m_cbk
= state
->m_cbk
;
762 m_cdata
= state
->m_cdata
;
763 m_neededreq
= state
->m_neededreq
;
764 Notify(state
->m_notify_state
);
774 void wxSocketBase::SetTimeout(long seconds
)
779 GSocket_SetTimeout(m_socket
, m_timeout
* 1000);
782 void wxSocketBase::SetFlags(wxSocketFlags flags
)
788 // --------------------------------------------------------------------------
789 // Callbacks (now obsolete - use events instead)
790 // --------------------------------------------------------------------------
792 wxSocketBase::wxSockCbk
wxSocketBase::Callback(wxSockCbk cbk_
)
794 wxSockCbk old_cbk
= cbk_
;
800 char *wxSocketBase::CallbackData(char *data
)
802 char *old_data
= m_cdata
;
808 // --------------------------------------------------------------------------
810 // --------------------------------------------------------------------------
812 // Callback function from GSocket. All events are internally
813 // monitored, but users only get these they are interested in.
815 static void LINKAGEMODE
wx_socket_callback(GSocket
* WXUNUSED(socket
),
819 wxSocketBase
*sckobj
= (wxSocketBase
*)cdata
;
821 sckobj
->OnRequest((wxSocketNotify
) notify
);
825 void wxSocketBase::OnRequest(wxSocketNotify req_evt
)
827 // This duplicates some code in _Wait, but this doesn't
828 // hurt. It has to be here because we don't know whether
829 // the Wait functions will be used, and it has to be in
830 // _Wait as well because the event might be a bit delayed.
834 case wxSOCKET_CONNECTION
:
835 m_establishing
= FALSE
;
839 // If we are in the middle of a R/W operation, do not
840 // propagate events to users. Also, filter 'late' events
841 // which are no longer valid.
844 if (m_reading
|| !GSocket_Select(m_socket
, GSOCK_INPUT_FLAG
))
848 case wxSOCKET_OUTPUT
:
849 if (m_writing
|| !GSocket_Select(m_socket
, GSOCK_OUTPUT_FLAG
))
855 m_establishing
= FALSE
;
862 // Schedule the event
864 wxSocketEventFlags flag
= -1;
867 case GSOCK_INPUT
: flag
= GSOCK_INPUT_FLAG
; break;
868 case GSOCK_OUTPUT
: flag
= GSOCK_OUTPUT_FLAG
; break;
869 case GSOCK_CONNECTION
: flag
= GSOCK_CONNECTION_FLAG
; break;
870 case GSOCK_LOST
: flag
= GSOCK_LOST_FLAG
; break;
873 if (((m_neededreq
& flag
) == flag
) && m_notify_state
)
875 wxSocketEvent
event(m_id
);
877 event
.m_event
= req_evt
;
878 event
.m_clientData
= m_clientData
;
879 event
.SetEventObject(this);
882 #if USE_DELAYED_EVENTS
883 m_handler
->AddPendingEvent(event
);
885 m_handler
->ProcessEvent(event
);
889 m_cbk(*this, req_evt
, m_cdata
);
893 void wxSocketBase::Notify(bool notify
)
895 m_notify_state
= notify
;
898 void wxSocketBase::SetNotify(wxSocketEventFlags flags
)
903 void wxSocketBase::SetEventHandler(wxEvtHandler
& handler
, int id
)
905 m_handler
= &handler
;
910 // --------------------------------------------------------------------------
912 // --------------------------------------------------------------------------
914 void wxSocketBase::Pushback(const void *buffer
, wxUint32 size
)
918 if (m_unread
== NULL
)
919 m_unread
= malloc(size
);
924 tmp
= malloc(m_unrd_size
+ size
);
925 memcpy((char *)tmp
+ size
, m_unread
, m_unrd_size
);
933 memcpy(m_unread
, buffer
, size
);
936 wxUint32
wxSocketBase::GetPushback(void *buffer
, wxUint32 size
, bool peek
)
941 if (size
> (m_unrd_size
-m_unrd_cur
))
942 size
= m_unrd_size
-m_unrd_cur
;
944 memcpy(buffer
, (char *)m_unread
+ m_unrd_cur
, size
);
949 if (m_unrd_size
== m_unrd_cur
)
962 // ==========================================================================
964 // ==========================================================================
966 // --------------------------------------------------------------------------
968 // --------------------------------------------------------------------------
970 wxSocketServer::wxSocketServer(wxSockAddress
& addr_man
,
972 : wxSocketBase(flags
, wxSOCKET_SERVER
)
975 m_socket
= GSocket_new();
980 // Setup the socket as server
981 GSocket_SetLocal(m_socket
, addr_man
.GetAddress());
982 if (GSocket_SetServer(m_socket
) != GSOCK_NOERROR
)
984 GSocket_destroy(m_socket
);
989 GSocket_SetTimeout(m_socket
, m_timeout
* 1000);
990 GSocket_SetCallback(m_socket
, GSOCK_INPUT_FLAG
| GSOCK_OUTPUT_FLAG
|
991 GSOCK_LOST_FLAG
| GSOCK_CONNECTION_FLAG
,
992 wx_socket_callback
, (char *)this);
996 // --------------------------------------------------------------------------
998 // --------------------------------------------------------------------------
1000 bool wxSocketServer::AcceptWith(wxSocketBase
& sock
, bool wait
)
1002 GSocket
*child_socket
;
1007 // If wait == FALSE, then the call should be nonblocking.
1008 // When we are finished, we put the socket to blocking mode
1012 GSocket_SetNonBlocking(m_socket
, TRUE
);
1014 child_socket
= GSocket_WaitConnection(m_socket
);
1017 GSocket_SetNonBlocking(m_socket
, FALSE
);
1022 sock
.m_type
= wxSOCKET_BASE
;
1023 sock
.m_socket
= child_socket
;
1024 sock
.m_connected
= TRUE
;
1026 GSocket_SetTimeout(sock
.m_socket
, sock
.m_timeout
* 1000);
1027 GSocket_SetCallback(sock
.m_socket
, GSOCK_INPUT_FLAG
| GSOCK_OUTPUT_FLAG
|
1028 GSOCK_LOST_FLAG
| GSOCK_CONNECTION_FLAG
,
1029 wx_socket_callback
, (char *)&sock
);
1034 wxSocketBase
*wxSocketServer::Accept(bool wait
)
1036 wxSocketBase
* sock
= new wxSocketBase();
1038 sock
->SetFlags(m_flags
);
1040 if (!AcceptWith(*sock
, wait
))
1046 bool wxSocketServer::WaitForAccept(long seconds
, long milliseconds
)
1048 return _Wait(seconds
, milliseconds
, GSOCK_CONNECTION_FLAG
);
1051 // ==========================================================================
1053 // ==========================================================================
1055 // --------------------------------------------------------------------------
1057 // --------------------------------------------------------------------------
1059 wxSocketClient::wxSocketClient(wxSocketFlags flags
)
1060 : wxSocketBase(flags
, wxSOCKET_CLIENT
)
1064 wxSocketClient::~wxSocketClient()
1068 // --------------------------------------------------------------------------
1070 // --------------------------------------------------------------------------
1072 bool wxSocketClient::Connect(wxSockAddress
& addr_man
, bool wait
)
1078 // Shutdown and destroy the socket
1080 GSocket_destroy(m_socket
);
1083 m_socket
= GSocket_new();
1084 m_connected
= FALSE
;
1085 m_establishing
= FALSE
;
1090 GSocket_SetTimeout(m_socket
, m_timeout
* 1000);
1091 GSocket_SetCallback(m_socket
, GSOCK_INPUT_FLAG
| GSOCK_OUTPUT_FLAG
|
1092 GSOCK_LOST_FLAG
| GSOCK_CONNECTION_FLAG
,
1093 wx_socket_callback
, (char *)this);
1095 // If wait == FALSE, then the call should be nonblocking.
1096 // When we are finished, we put the socket to blocking mode
1100 GSocket_SetNonBlocking(m_socket
, TRUE
);
1102 GSocket_SetPeer(m_socket
, addr_man
.GetAddress());
1103 err
= GSocket_Connect(m_socket
, GSOCK_STREAMED
);
1106 GSocket_SetNonBlocking(m_socket
, FALSE
);
1108 if (err
!= GSOCK_NOERROR
)
1110 if (err
== GSOCK_WOULDBLOCK
)
1111 m_establishing
= TRUE
;
1120 bool wxSocketClient::WaitOnConnect(long seconds
, long milliseconds
)
1122 if (m_connected
) // Already connected
1125 if (!m_establishing
|| !m_socket
) // No connection in progress
1128 return _Wait(seconds
, milliseconds
, GSOCK_CONNECTION_FLAG
|
1132 // ==========================================================================
1134 // ==========================================================================
1136 /* NOTE: experimental stuff - might change */
1138 wxDatagramSocket::wxDatagramSocket( wxSockAddress
& addr
,
1139 wxSocketFlags flags
)
1140 : wxSocketBase( flags
, wxSOCKET_DATAGRAM
)
1142 // Create the socket
1143 m_socket
= GSocket_new();
1148 // Setup the socket as non connection oriented
1149 GSocket_SetLocal(m_socket
, addr
.GetAddress());
1150 if( GSocket_SetNonOriented(m_socket
) != GSOCK_NOERROR
)
1152 GSocket_destroy(m_socket
);
1157 // Initialize all stuff
1158 m_connected
= FALSE
;
1159 m_establishing
= FALSE
;
1160 GSocket_SetTimeout( m_socket
, m_timeout
);
1161 GSocket_SetCallback( m_socket
, GSOCK_INPUT_FLAG
| GSOCK_OUTPUT_FLAG
|
1162 GSOCK_LOST_FLAG
| GSOCK_CONNECTION_FLAG
,
1163 wx_socket_callback
, (char*)this );
1167 wxDatagramSocket
& wxDatagramSocket::RecvFrom( wxSockAddress
& addr
,
1176 wxDatagramSocket
& wxDatagramSocket::SendTo( wxSockAddress
& addr
,
1180 GSocket_SetPeer(m_socket
, addr
.GetAddress());
1185 // ==========================================================================
1187 // ==========================================================================
1189 wxSocketEvent::wxSocketEvent(int id
) : wxEvent(id
)
1191 SetEventType( (wxEventType
)wxEVT_SOCKET
);
1194 void wxSocketEvent::CopyObject(wxObject
& object_dest
) const
1196 wxSocketEvent
*event
= (wxSocketEvent
*)&object_dest
;
1198 wxEvent::CopyObject(object_dest
);
1200 event
->m_event
= m_event
;
1201 event
->m_clientData
= m_clientData
;
1205 // ==========================================================================
1207 // ==========================================================================
1209 class WXDLLEXPORT wxSocketModule
: public wxModule
1211 DECLARE_DYNAMIC_CLASS(wxSocketModule
)
1214 bool OnInit() { return GSocket_Init(); }
1215 void OnExit() { GSocket_Cleanup(); }
1218 IMPLEMENT_DYNAMIC_CLASS(wxSocketModule
, wxModule
)