]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: sckint.h | |
3 | // Purpose: Socket internal classes | |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: April 1999 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | #ifndef _WX_NETWORK_SOCKET_INT_H | |
12 | #define _WX_NETWORK_SOCKET_INT_H | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #if wxUSE_SOCKETS | |
19 | ||
20 | #include <wx/object.h> | |
21 | #include <wx/list.h> | |
22 | #include <wx/socket.h> | |
23 | #include <wx/thread.h> | |
24 | ||
25 | // Socket state | |
26 | class SocketState | |
27 | { | |
28 | public: | |
29 | // TRUE if the background notifyier is on. | |
30 | bool notify_state; | |
31 | // Specifies which events we want to be notified. | |
32 | wxSocketBase::wxRequestNotify evt_notify_state; | |
33 | // Socket flags. | |
34 | wxSocketBase::wxSockFlags socket_flags; | |
35 | // Pointer to the C callback function. | |
36 | wxSocketBase::wxSockCbk c_callback; | |
37 | char *c_callback_data; | |
38 | }; | |
39 | ||
40 | // Socket request | |
41 | class SockRequest | |
42 | { | |
43 | public: | |
44 | // Buffer where to get/put data. | |
45 | char *buffer; | |
46 | // Size of the buffer. | |
47 | size_t size; | |
48 | // Number of bytes really read/written. | |
49 | size_t io_nbytes; | |
50 | // Error. | |
51 | unsigned int error; | |
52 | // Type of the request. | |
53 | wxSocketBase::wxRequestNotify type; | |
54 | // Timeout (in milliseconds). | |
55 | unsigned int timeout; | |
56 | // TRUE if the buffer has been processed. | |
57 | bool done; | |
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. | |
60 | bool wait; | |
61 | }; | |
62 | ||
63 | class wxSocketInternal; | |
64 | ||
65 | #if wxUSE_THREADS | |
66 | class SocketWaiter: public wxThread { | |
67 | public: | |
68 | SocketWaiter(wxSocketBase *socket, wxSocketInternal *internal); | |
69 | ~SocketWaiter(); | |
70 | ||
71 | // Thread Entry point | |
72 | // --- | |
73 | virtual void *Entry(); | |
74 | ||
75 | protected: | |
76 | void ProcessReadEvent(); | |
77 | void ProcessWriteEvent(); | |
78 | ||
79 | public: | |
80 | wxSocketBase *m_socket; | |
81 | wxSocketInternal *m_internal; | |
82 | int m_fd; | |
83 | }; | |
84 | ||
85 | class SocketRequester: public wxThread { | |
86 | public: | |
87 | SocketRequester(wxSocketBase *socket, wxSocketInternal *internal); | |
88 | ~SocketRequester(); | |
89 | ||
90 | void ProcessWaitEvent(SockRequest *req); | |
91 | void ProcessReadEvent(SockRequest *req); | |
92 | void ProcessWriteEvent(SockRequest *req); | |
93 | ||
94 | bool WaitFor(wxSocketBase::wxRequestNotify req, int millisec); | |
95 | ||
96 | // Thread Entry point | |
97 | // --- | |
98 | virtual void *Entry(); | |
99 | ||
100 | public: | |
101 | wxSocketBase *m_socket; | |
102 | wxSocketInternal *m_internal; | |
103 | int m_fd; | |
104 | }; | |
105 | #endif | |
106 | // wxUSE_THREADS | |
107 | ||
108 | class wxSocketInternal { | |
109 | public: | |
110 | wxSocketInternal(wxSocketBase *socket); | |
111 | ~wxSocketInternal(); | |
112 | ||
113 | // wxSocket thread manager | |
114 | // ----------------------- | |
115 | void AcquireData(); | |
116 | void ReleaseData(); | |
117 | void AcquireFD(); | |
118 | void ReleaseFD(); | |
119 | ||
120 | int GetFD() { return m_fd; } | |
121 | ||
122 | void ResumeWaiter(); | |
123 | void StopWaiter(); | |
124 | void ResumeRequester(); | |
125 | void StopRequester(); | |
126 | ||
127 | void QueueRequest(SockRequest *request, bool async); | |
128 | void WaitForEnd(SockRequest *request); | |
129 | ||
130 | SockRequest *WaitForReq(); | |
131 | void EndRequest(SockRequest *req); | |
132 | public: | |
133 | wxSocketBase *m_socket; | |
134 | #if wxUSE_THREADS | |
135 | wxMutex m_socket_locker, m_fd_locker, m_request_locker, m_end_requester; | |
136 | wxCondition m_socket_cond; | |
137 | SocketWaiter *m_thread_waiter; | |
138 | SocketRequester *m_thread_requester; | |
139 | #endif | |
140 | wxList m_requests; | |
141 | int m_fd; | |
142 | bool m_invalid_requester; | |
143 | }; | |
144 | ||
145 | #endif | |
146 | // wxUSE_SOCKETS | |
147 | ||
148 | #endif | |
149 | // _WX_NETWORK_SOCKET_INT_H |