1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Socket internal classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_NETWORK_SOCKET_INT_H
12 #define _WX_NETWORK_SOCKET_INT_H
20 #include <wx/object.h>
22 #include <wx/socket.h>
23 #include <wx/thread.h>
29 // TRUE if the background notifyier is on.
31 // Specifies which events we want to be notified.
32 wxSocketBase::wxRequestNotify evt_notify_state
;
34 wxSocketBase::wxSockFlags socket_flags
;
35 // Pointer to the C callback function.
36 wxSocketBase::wxSockCbk c_callback
;
37 char *c_callback_data
;
44 // Buffer where to get/put data.
46 // Size of the buffer.
48 // Number of bytes really read/written.
52 // Type of the request.
53 wxSocketBase::wxRequestNotify type
;
54 // Timeout (in milliseconds).
56 // TRUE if the buffer has been processed.
58 // TRUE if we must wait for the request completion, in the other case an
59 // event will be sent to the main thread when the request is finished.
63 class wxSocketInternal
;
66 class SocketWaiter
: public wxThread
{
68 SocketWaiter(wxSocketBase
*socket
, wxSocketInternal
*internal
);
73 virtual void *Entry();
76 void ProcessReadEvent();
77 void ProcessWriteEvent();
80 wxSocketBase
*m_socket
;
81 wxSocketInternal
*m_internal
;
85 class SocketRequester
: public wxThread
{
87 SocketRequester(wxSocketBase
*socket
, wxSocketInternal
*internal
);
90 void ProcessWaitEvent(SockRequest
*req
);
91 void ProcessReadEvent(SockRequest
*req
);
92 void ProcessWriteEvent(SockRequest
*req
);
94 bool WaitFor(wxSocketBase::wxRequestNotify req
, int millisec
);
98 virtual void *Entry();
101 wxSocketBase
*m_socket
;
102 wxSocketInternal
*m_internal
;
108 class wxSocketInternal
{
110 wxSocketInternal(wxSocketBase
*socket
);
113 // wxSocket thread manager
114 // -----------------------
120 int GetFD() { return m_fd
; }
121 void SetFD(int fd
) { m_fd
= fd
; }
125 void ResumeRequester();
126 void StopRequester();
128 void QueueRequest(SockRequest
*request
, bool async
);
129 void WaitForEnd(SockRequest
*request
);
131 SockRequest
*WaitForReq();
132 void EndRequest(SockRequest
*req
);
134 wxSocketBase
*m_socket
;
136 wxMutex m_socket_locker
, m_fd_locker
, m_request_locker
, m_end_requester
;
137 wxCondition m_socket_cond
;
138 SocketWaiter
*m_thread_waiter
;
139 SocketRequester
*m_thread_requester
;
143 bool m_invalid_requester
;
150 // _WX_NETWORK_SOCKET_INT_H