source: trunk/src/wsock32/new/relaywin.cpp@ 1945

Last change on this file since 1945 was 1945, checked in by achimha, 26 years ago

async relay window proc fixes

File size: 8.0 KB
Line 
1/* $Id: relaywin.cpp,v 1.7 1999-12-02 16:39:46 achimha Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 * Win32 SOCK32 for OS/2
8 *
9 * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
10 *
11 */
12
13/* Remark:
14 * - this is an object window that acts as "relay", this is
15 * it receives WSAAsyncSelect()'s messages and redirects
16 * them to the appropriate PostMessageA function of USER32.
17 */
18
19
20/*****************************************************************************
21 * Includes *
22 *****************************************************************************/
23
24/* object.c: the object window procedure on thread 2 */
25// os2 includes
26#define INCL_DOSPROCESS
27#define INCL_WIN
28#include <os2.h>
29// crt includes
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#include <odin.h>
35#include <odinwrap.h>
36#include <misc.h>
37
38#include "relaywin.h"
39
40#include <pmwsock.h>
41#include <os2sel.h>
42#include <wprocess.h>
43#include <heapstring.h>
44#include <win32wnd.h>
45#include "wsock32.h"
46
47ODINDEBUGCHANNEL(WSOCK32-RELAYWIN)
48
49
50/*****************************************************************************
51 * Structures *
52 *****************************************************************************/
53
54#define MAX_ASYNC_SOCKETS 64
55
56// static table for id / hwnd-msg translation
57static HWNDMSGPAIR arrHwndMsgPair[MAX_ASYNC_SOCKETS];
58static char* ODIN_WSOCK_RELAY_CLASS = "ODIN_WSOCK_RELAY";
59
60
61// prototype for PostMessageA
62BOOL __stdcall PostMessageA(HWND,UINT,ULONG,ULONG);
63
64
65/*****************************************************************************
66 * Name :
67 * Purpose :
68 * Parameters:
69 * Variables :
70 * Result :
71 * Remark :
72 * Status :
73 *
74 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
75 *****************************************************************************/
76
77ULONG RelayAlloc(HWND hwnd, ULONG ulMsg, ULONG ulRequestType,
78 PVOID pvUserData1, PVOID pvUserData2)
79{
80 ULONG ulCounter;
81
82 for (ulCounter = 0;
83 ulCounter < MAX_ASYNC_SOCKETS;
84 ulCounter++)
85 if ( (arrHwndMsgPair[ulCounter].hwnd == 0) || // slot free?
86 (arrHwndMsgPair[ulCounter].hwnd == hwnd) ) // same window?
87 {
88 // occupy slot
89 arrHwndMsgPair[ulCounter].hwnd = hwnd;
90 arrHwndMsgPair[ulCounter].ulMsg = ulMsg;
91 arrHwndMsgPair[ulCounter].ulRequestType = ulRequestType;
92 arrHwndMsgPair[ulCounter].pvUserData1 = pvUserData1;
93 arrHwndMsgPair[ulCounter].pvUserData2 = pvUserData2;
94 return ulCounter; // return "id"
95 }
96
97 return -1; // not found
98}
99
100
101/*****************************************************************************
102 * Name :
103 * Purpose :
104 * Parameters:
105 * Variables :
106 * Result :
107 * Remark :
108 * Status :
109 *
110 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
111 *****************************************************************************/
112
113ULONG RelayFree(ULONG ulID)
114{
115 if ( (ulID < 0) || // check range
116 (ulID >= MAX_ASYNC_SOCKETS) )
117 return -1; // error
118
119 arrHwndMsgPair[ulID].hwnd = 0; // mark free
120
121 return 0; // OK
122}
123
124
125/*****************************************************************************
126 * Name :
127 * Purpose :
128 * Parameters:
129 * Variables :
130 * Result :
131 * Remark :
132 * Status :
133 *
134 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
135 *****************************************************************************/
136
137ULONG RelayFreeByHwnd(HWND hwnd)
138{
139 ULONG ulCounter;
140
141 for (ulCounter = 0;
142 ulCounter < MAX_ASYNC_SOCKETS;
143 ulCounter++)
144 if ( arrHwndMsgPair[ulCounter].hwnd == hwnd ) // same window?
145 {
146 arrHwndMsgPair[ulCounter].hwnd = 0; // free slot
147 return 0; // OK
148 }
149
150 return -1; // not found
151}
152
153
154/*****************************************************************************
155 * Name :
156 * Purpose :
157 * Parameters:
158 * Variables :
159 * Result :
160 * Remark :
161 * Status :
162 *
163 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
164 *****************************************************************************/
165
166PHWNDMSGPAIR RelayQuery(ULONG ulID)
167{
168 if ( (ulID < 0) || // check range
169 (ulID >= MAX_ASYNC_SOCKETS) )
170 return NULL; // error
171
172 if (arrHwndMsgPair[ulID].hwnd == 0)
173 return NULL; // error, free entry
174 else
175 return (&arrHwndMsgPair[ulID]);
176}
177
178
179/*****************************************************************************
180 * Name :
181 * Purpose :
182 * Parameters:
183 * Variables :
184 * Result :
185 * Remark :
186 * Status :
187 *
188 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
189 *****************************************************************************/
190
191MRESULT EXPENTRY RelayWindowProc(HWND hwnd,
192 ULONG ulMsg,
193 MPARAM mp1,
194 MPARAM mp2)
195{
196 PHWNDMSGPAIR pHM;
197
198 // termination flag handling?
199 // if (fTerminate)
200 // WinDefWindowProc()
201
202 pHM = RelayQuery(ulMsg); // find registered message
203 if (pHM != NULL) // message pair found
204 {
205 /* check request type for special handling */
206 switch (pHM->ulRequestType)
207 {
208 case ASYNCREQUEST_SELECT:
209 {
210 dprintf(("WSOCK32:RelayWindowProc, AsyncSelect notification\n"));
211 break;
212 }
213 case ASYNCREQUEST_GETHOSTBYNAME:
214 {
215 dprintf(("WSOCK32:RelayWindowProc, Converting hostent for "
216 "WSAAyncGetHostByName\n"));
217 /* we need to convert the hostent structure here */
218 Whostent *WinHostent = (Whostent*)pHM->pvUserData1;
219 hostent *OS2Hostent = (hostent*)pHM->pvUserData1;
220 short h_addrtype = (short)OS2Hostent->h_addrtype;
221 WinHostent->h_addrtype = h_addrtype;
222 short h_length = (short)OS2Hostent->h_length;
223 WinHostent->h_length = h_length;
224 char **h_addr_list = OS2Hostent->h_addr_list;
225 WinHostent->h_addr_list = h_addr_list;
226 //TODO: the size of OS/2 hostent is 4 bytes bigger so the original buffer *might* be too small
227
228 break;
229 }
230 }
231
232 dprintf(("WSOCK32:RelayWinProc, Posting %d to %d\n", pHM->ulMsg, pHM->hwnd));
233 PostMessageA(pHM->hwnd,
234 pHM->ulMsg,
235 (ULONG)mp1,
236 (ULONG)mp2);
237
238 // if socket close, free entry
239 //@@@PH
240
241 return FALSE; // OK, message sent
242 }
243
244 // default message processing
245 return WinDefWindowProc( hwnd, ulMsg, mp1, mp2 );
246}
247
248
249/*****************************************************************************
250 * Name :
251 * Purpose :
252 * Parameters:
253 * Variables :
254 * Result :
255 * Remark :
256 * Status :
257 *
258 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
259 *****************************************************************************/
260
261HWND RelayInitialize(HWND hwndPost)
262{
263 BOOL fSuccess;
264 HAB hab;
265 HWND hwnd;
266
267
268 // thread initialization
269 hab = WinQueryAnchorBlock(hwndPost);
270 if (hab == NULLHANDLE)
271 return NULLHANDLE;
272
273 // register relay window class
274 fSuccess = WinRegisterClass(hab,
275 ODIN_WSOCK_RELAY_CLASS,
276 (PFNWP)RelayWindowProc,
277 0,
278 0);
279 if (fSuccess == FALSE)
280 return NULLHANDLE;
281
282 hwnd = WinCreateWindow(HWND_OBJECT,
283 ODIN_WSOCK_RELAY_CLASS,
284 "ODIN WSock Relay",
285 0, 0, 0, 0, 0,
286 HWND_OBJECT,
287 HWND_BOTTOM,
288 0,
289 NULL,
290 NULL );
291
292 //WinDestroyWindow( pg->hwndObject );
293 return hwnd;
294}
295
296
297/*****************************************************************************
298 * Name :
299 * Purpose :
300 * Parameters:
301 * Variables :
302 * Result :
303 * Remark :
304 * Status :
305 *
306 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
307 *****************************************************************************/
308
309BOOL RelayTerminate(HWND hwndRelay)
310{
311 return WinDestroyWindow(hwndRelay);
312}
313
Note: See TracBrowser for help on using the repository browser.