]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sckint.h
*** empty log message ***
[wxWidgets.git] / include / wx / sckint.h
CommitLineData
a737331d
GL
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
2df7be7f
RR
18#include "wx/defs.h"
19
a737331d
GL
20#if wxUSE_SOCKETS
21
2df7be7f
RR
22#include "wx/object.h"
23#include "wx/list.h"
24#include "wx/socket.h"
25#include "wx/thread.h"
a737331d
GL
26
27// Socket state
28class SocketState
29{
30 public:
31 // TRUE if the background notifyier is on.
32 bool notify_state;
33 // Specifies which events we want to be notified.
34 wxSocketBase::wxRequestNotify evt_notify_state;
35 // Socket flags.
36 wxSocketBase::wxSockFlags socket_flags;
37 // Pointer to the C callback function.
38 wxSocketBase::wxSockCbk c_callback;
39 char *c_callback_data;
40};
41
42// Socket request
43class SockRequest
44{
45 public:
46 // Buffer where to get/put data.
47 char *buffer;
48 // Size of the buffer.
49 size_t size;
50 // Number of bytes really read/written.
51 size_t io_nbytes;
52 // Error.
53 unsigned int error;
54 // Type of the request.
55 wxSocketBase::wxRequestNotify type;
56 // Timeout (in milliseconds).
57 unsigned int timeout;
58 // TRUE if the buffer has been processed.
59 bool done;
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.
62 bool wait;
63};
64
65class wxSocketInternal;
a50fb9c0
JS
66
67#if wxUSE_THREADS
a737331d
GL
68class SocketWaiter: public wxThread {
69 public:
70 SocketWaiter(wxSocketBase *socket, wxSocketInternal *internal);
71 ~SocketWaiter();
72
73 // Thread Entry point
74 // ---
75 virtual void *Entry();
76
77 protected:
78 void ProcessReadEvent();
79 void ProcessWriteEvent();
80
81 public:
82 wxSocketBase *m_socket;
83 wxSocketInternal *m_internal;
84 int m_fd;
85};
fae05df5 86#endif
a737331d 87
062c4861
GL
88class SocketRequester
89#if wxUSE_THREADS
90 : public wxThread
91#endif
92 {
a737331d
GL
93 public:
94 SocketRequester(wxSocketBase *socket, wxSocketInternal *internal);
95 ~SocketRequester();
96
97 void ProcessWaitEvent(SockRequest *req);
98 void ProcessReadEvent(SockRequest *req);
99 void ProcessWriteEvent(SockRequest *req);
100
101 bool WaitFor(wxSocketBase::wxRequestNotify req, int millisec);
102
fae05df5 103#if wxUSE_THREADS
a737331d
GL
104 // Thread Entry point
105 // ---
106 virtual void *Entry();
fae05df5 107#endif
a737331d
GL
108
109 public:
110 wxSocketBase *m_socket;
111 wxSocketInternal *m_internal;
112 int m_fd;
113};
114
115class wxSocketInternal {
116 public:
117 wxSocketInternal(wxSocketBase *socket);
118 ~wxSocketInternal();
119
120 // wxSocket thread manager
121 // -----------------------
122 void AcquireData();
123 void ReleaseData();
124 void AcquireFD();
125 void ReleaseFD();
126
127 int GetFD() { return m_fd; }
9111db68 128 void SetFD(int fd) { m_fd = fd; }
a737331d 129
2a4f27f2
GL
130 void ResumeWaiter();
131 void StopWaiter();
132 void ResumeRequester();
133 void StopRequester();
a737331d
GL
134
135 void QueueRequest(SockRequest *request, bool async);
136 void WaitForEnd(SockRequest *request);
137
fae05df5 138 // Used by SocketRequester
a737331d
GL
139 SockRequest *WaitForReq();
140 void EndRequest(SockRequest *req);
141 public:
a50fb9c0
JS
142 wxSocketBase *m_socket;
143#if wxUSE_THREADS
63496c98 144 wxMutex m_socket_locker, m_fd_locker, m_request_locker, m_end_requester;
a737331d 145 wxCondition m_socket_cond;
a737331d 146 SocketWaiter *m_thread_waiter;
a50fb9c0 147#endif
062c4861 148 SocketRequester *m_thread_requester;
a737331d
GL
149 wxList m_requests;
150 int m_fd;
63496c98 151 bool m_invalid_requester;
a737331d
GL
152};
153
154#endif
155 // wxUSE_SOCKETS
156
157#endif
158 // _WX_NETWORK_SOCKET_INT_H