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

Last change on this file since 1933 was 1933, checked in by phaller, 26 years ago

Fix: WSOCK32 finally working!

File size: 6.9 KB
Line 
1/* $Id: relaywin.cpp,v 1.3 1999-12-02 07:47:26 phaller 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
40ODINDEBUGCHANNEL(WSOCK32-RELAYWIN)
41
42
43/*****************************************************************************
44 * Structures *
45 *****************************************************************************/
46
47#define MAX_ASYNC_SOCKETS 64
48
49// static table for id / hwnd-msg translation
50static HWNDMSGPAIR arrHwndMsgPair[MAX_ASYNC_SOCKETS];
51static char* ODIN_WSOCK_RELAY_CLASS = "ODIN_WSOCK_RELAY";
52
53
54// prototype for PostMessageA
55//BOOL _Stdcall PostMessageA(HWND,UINT,WPARAM,LPARAM);
56BOOL __stdcall PostMessageA(HWND,UINT,ULONG,ULONG);
57
58
59/*****************************************************************************
60 * Name :
61 * Purpose :
62 * Parameters:
63 * Variables :
64 * Result :
65 * Remark :
66 * Status :
67 *
68 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
69 *****************************************************************************/
70
71ULONG RelayAlloc(HWND hwnd, ULONG ulMsg)
72{
73 ULONG ulCounter;
74
75 for (ulCounter = 0;
76 ulCounter < MAX_ASYNC_SOCKETS;
77 ulCounter++)
78 if ( (arrHwndMsgPair[ulCounter].hwnd == 0) || // slot free?
79 (arrHwndMsgPair[ulCounter].hwnd == hwnd) ) // same window?
80 {
81 // occupy slot
82 arrHwndMsgPair[ulCounter].hwnd = hwnd;
83 arrHwndMsgPair[ulCounter].ulMsg = ulMsg;
84 return ulCounter; // return "id"
85 }
86
87 return -1; // not found
88}
89
90
91/*****************************************************************************
92 * Name :
93 * Purpose :
94 * Parameters:
95 * Variables :
96 * Result :
97 * Remark :
98 * Status :
99 *
100 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
101 *****************************************************************************/
102
103ULONG RelayFree(ULONG ulID)
104{
105 if ( (ulID < 0) || // check range
106 (ulID >= MAX_ASYNC_SOCKETS) )
107 return -1; // error
108
109 arrHwndMsgPair[ulID].hwnd = 0; // mark free
110
111 return 0; // OK
112}
113
114
115/*****************************************************************************
116 * Name :
117 * Purpose :
118 * Parameters:
119 * Variables :
120 * Result :
121 * Remark :
122 * Status :
123 *
124 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
125 *****************************************************************************/
126
127ULONG RelayFreeByHwnd(HWND hwnd)
128{
129 ULONG ulCounter;
130
131 for (ulCounter = 0;
132 ulCounter < MAX_ASYNC_SOCKETS;
133 ulCounter++)
134 if ( arrHwndMsgPair[ulCounter].hwnd == hwnd ) // same window?
135 {
136 arrHwndMsgPair[ulCounter].hwnd = 0; // free slot
137 return 0; // OK
138 }
139
140 return -1; // not found
141}
142
143
144/*****************************************************************************
145 * Name :
146 * Purpose :
147 * Parameters:
148 * Variables :
149 * Result :
150 * Remark :
151 * Status :
152 *
153 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
154 *****************************************************************************/
155
156PHWNDMSGPAIR RelayQuery(ULONG ulID)
157{
158 if ( (ulID < 0) || // check range
159 (ulID >= MAX_ASYNC_SOCKETS) )
160 return NULL; // error
161
162 if (arrHwndMsgPair[ulID].hwnd == 0)
163 return NULL; // error, free entry
164 else
165 return (&arrHwndMsgPair[ulID]);
166}
167
168
169/*****************************************************************************
170 * Name :
171 * Purpose :
172 * Parameters:
173 * Variables :
174 * Result :
175 * Remark :
176 * Status :
177 *
178 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
179 *****************************************************************************/
180
181MRESULT EXPENTRY RelayWindowProc(HWND hwnd,
182 ULONG ulMsg,
183 MPARAM mp1,
184 MPARAM mp2)
185{
186 PHWNDMSGPAIR pHM;
187
188 // termination flag handling?
189 // if (fTerminate)
190 // WinDefWindowProc()
191
192 //@@@PH: 1999/11/31 PROBLEM
193 // hwnd and ulMsg passed in have been converted by our USER32 code
194 // here, we ultimatively need to translate it back.
195 // under the debugger, things WORK now !:)
196
197 pHM = RelayQuery(ulMsg); // find registered message
198 if (pHM != NULL) // message pair found
199 {
200 PostMessageA(pHM->hwnd,
201 pHM->ulMsg,
202 (ULONG)mp1,
203 (ULONG)mp2);
204
205 // if socket close, free entry
206 //@@@PH
207
208 return FALSE; // OK, message sent
209 }
210
211 // default message processing
212 return WinDefWindowProc( hwnd, ulMsg, mp1, mp2 );
213}
214
215
216/*****************************************************************************
217 * Name :
218 * Purpose :
219 * Parameters:
220 * Variables :
221 * Result :
222 * Remark :
223 * Status :
224 *
225 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
226 *****************************************************************************/
227
228HWND RelayInitialize(HWND hwndPost)
229{
230 BOOL fSuccess;
231 HAB hab;
232 HWND hwnd;
233
234
235 // thread initialization
236 hab = WinQueryAnchorBlock(hwndPost);
237 if (hab == NULLHANDLE)
238 return NULLHANDLE;
239
240 // register relay window class
241 fSuccess = WinRegisterClass(hab,
242 ODIN_WSOCK_RELAY_CLASS,
243 (PFNWP)RelayWindowProc,
244 0,
245 0);
246 if (fSuccess == FALSE)
247 return NULLHANDLE;
248
249 hwnd = WinCreateWindow(HWND_OBJECT,
250 ODIN_WSOCK_RELAY_CLASS,
251 "ODIN WSock Relay",
252 0, 0, 0, 0, 0,
253 HWND_OBJECT,
254 HWND_BOTTOM,
255 0,
256 NULL,
257 NULL );
258
259 //WinDestroyWindow( pg->hwndObject );
260 return hwnd;
261}
262
263
264/*****************************************************************************
265 * Name :
266 * Purpose :
267 * Parameters:
268 * Variables :
269 * Result :
270 * Remark :
271 * Status :
272 *
273 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
274 *****************************************************************************/
275
276BOOL RelayTerminate(HWND hwndRelay)
277{
278 return WinDestroyWindow(hwndRelay);
279}
280
Note: See TracBrowser for help on using the repository browser.