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

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

async gethostbyname fixes

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