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
22 #include "wx/object.h"
24 #include "wx/socket.h"
25 #include "wx/thread.h"
31 // TRUE if the background notifyier is on.
33 // Specifies which events we want to be notified.
34 wxSocketBase::wxRequestNotify evt_notify_state
;
36 wxSocketBase::wxSockFlags socket_flags
;
37 // Pointer to the C callback function.
38 wxSocketBase::wxSockCbk c_callback
;
39 char *c_callback_data
;
46 // Buffer where to get/put data.
48 // Size of the buffer.
50 // Number of bytes really read/written.
54 // Type of the request.
55 wxSocketBase::wxRequestNotify type
;
56 // Timeout (in milliseconds).
58 // TRUE if the buffer has been processed.
60 // TRUE if we must wait for the request completion, in the other case an
61 // event will be sent to the main thread when the request is finished.
65 class wxSocketInternal
;
68 class SocketWaiter
: public wxThread
{
70 SocketWaiter(wxSocketBase
*socket
, wxSocketInternal
*internal
);
75 virtual void *Entry();
78 void ProcessReadEvent();
79 void ProcessWriteEvent();
82 wxSocketBase
*m_socket
;
83 wxSocketInternal
*m_internal
;
94 SocketRequester(wxSocketBase
*socket
, wxSocketInternal
*internal
);
97 void ProcessWaitEvent(SockRequest
*req
);
98 void ProcessReadEvent(SockRequest
*req
);
99 void ProcessWriteEvent(SockRequest
*req
);
101 bool WaitFor(wxSocketBase::wxRequestNotify req
, int millisec
);
104 // Thread Entry point
106 virtual void *Entry();
110 wxSocketBase
*m_socket
;
111 wxSocketInternal
*m_internal
;
115 class wxSocketInternal
{
117 wxSocketInternal(wxSocketBase
*socket
);
120 // wxSocket thread manager
121 // -----------------------
127 int GetFD() { return m_fd
; }
128 void SetFD(int fd
) { m_fd
= fd
; }
132 void ResumeRequester();
133 void StopRequester();
135 void QueueRequest(SockRequest
*request
, bool async
);
136 void WaitForEnd(SockRequest
*request
);
138 // Used by SocketRequester
139 SockRequest
*WaitForReq();
140 void EndRequest(SockRequest
*req
);
142 wxSocketBase
*m_socket
;
144 wxMutex m_socket_locker
, m_fd_locker
, m_request_locker
, m_end_requester
;
145 wxCondition m_socket_cond
;
146 SocketWaiter
*m_thread_waiter
;
148 SocketRequester
*m_thread_requester
;
151 bool m_invalid_requester
;
158 // _WX_NETWORK_SOCKET_INT_H