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

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

async wsock fixes

File size: 8.1 KB
Line 
1/* $Id: relaywin.cpp,v 1.4 1999-12-02 15:22:05 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 if (pHM->ulRequestType == ASYNCREQUEST_GETHOSTBYNAME)
207 {
208 dprintf(("WSOCK32:RelayWindowProc, Converting hostent for WSAAyncGetHostByName\n"));
209 /* we need to convert the hostent structure here */
210 Whostent *WinHostent = (Whostent*)pHM->pvUserData1;
211 hostent *OS2Hostent = (hostent*)pHM->pvUserData2;
212 WinHostent->h_name = OS2Hostent->h_name;
213 WinHostent->h_aliases = OS2Hostent->h_aliases;
214 WinHostent->h_addrtype = (short)OS2Hostent->h_addrtype;
215 WinHostent->h_length = (short)OS2Hostent->h_length;
216 WinHostent->h_addr_list = OS2Hostent->h_addr_list;
217 /* free our temporary OS2 hostent buffer */
218//TODO: how can we free this? we will end up with a memory leak :(
219// this memory block not only contains the hostent structure but also the strings it points to
220// free(pHM->pvUserData2);
221
222dprintf(("Size of Window hostent: %d, OS/2 hostent: %d, mp1: %d, mp2 %d\n", sizeof(Whostent), sizeof(hostent), mp1, mp2));
223
224 }
225
226 dprintf(("WSOCK32:RelayWinProc, Posting %d to %d\n", pHM->ulMsg, pHM->hwnd));
227 PostMessageA(pHM->hwnd,
228 pHM->ulMsg,
229 (ULONG)mp1,
230 (ULONG)mp2);
231
232 // if socket close, free entry
233 //@@@PH
234
235 return FALSE; // OK, message sent
236 }
237
238 // default message processing
239 return WinDefWindowProc( hwnd, ulMsg, mp1, mp2 );
240}
241
242
243/*****************************************************************************
244 * Name :
245 * Purpose :
246 * Parameters:
247 * Variables :
248 * Result :
249 * Remark :
250 * Status :
251 *
252 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
253 *****************************************************************************/
254
255HWND RelayInitialize(HWND hwndPost)
256{
257 BOOL fSuccess;
258 HAB hab;
259 HWND hwnd;
260
261
262 // thread initialization
263 hab = WinQueryAnchorBlock(hwndPost);
264 if (hab == NULLHANDLE)
265 return NULLHANDLE;
266
267 // register relay window class
268 fSuccess = WinRegisterClass(hab,
269 ODIN_WSOCK_RELAY_CLASS,
270 (PFNWP)RelayWindowProc,
271 0,
272 0);
273 if (fSuccess == FALSE)
274 return NULLHANDLE;
275
276 hwnd = WinCreateWindow(HWND_OBJECT,
277 ODIN_WSOCK_RELAY_CLASS,
278 "ODIN WSock Relay",
279 0, 0, 0, 0, 0,
280 HWND_OBJECT,
281 HWND_BOTTOM,
282 0,
283 NULL,
284 NULL );
285
286 //WinDestroyWindow( pg->hwndObject );
287 return hwnd;
288}
289
290
291/*****************************************************************************
292 * Name :
293 * Purpose :
294 * Parameters:
295 * Variables :
296 * Result :
297 * Remark :
298 * Status :
299 *
300 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
301 *****************************************************************************/
302
303BOOL RelayTerminate(HWND hwndRelay)
304{
305 return WinDestroyWindow(hwndRelay);
306}
307
Note: See TracBrowser for help on using the repository browser.