Index: trunk/src/wsock32/new/makefile
===================================================================
--- trunk/src/wsock32/new/makefile	(revision 1906)
+++ trunk/src/wsock32/new/makefile	(revision 1908)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.4 1999-11-29 22:31:50 phaller Exp $
+# $Id: makefile,v 1.5 1999-12-01 01:10:54 phaller Exp $
 
 #
@@ -21,5 +21,5 @@
 TARGET = wsock32
 
-OBJS =  wsock32.obj initterm.obj unknown.obj
+OBJS =  wsock32.obj initterm.obj unknown.obj relaywin.obj
 
 all: $(TARGET).dll $(TARGET).lib
@@ -43,4 +43,5 @@
 unknown.obj: unknown.cpp
 initterm.obj: initterm.cpp
+relaywin.obj: relaywin.cpp
 
 
Index: trunk/src/wsock32/new/relaywin.cpp
===================================================================
--- trunk/src/wsock32/new/relaywin.cpp	(revision 1908)
+++ trunk/src/wsock32/new/relaywin.cpp	(revision 1908)
@@ -0,0 +1,277 @@
+/* $Id: relaywin.cpp,v 1.1 1999-12-01 01:10:55 phaller Exp $ */
+
+/*
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ * Win32 SOCK32 for OS/2
+ *
+ * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
+ *
+ */
+
+/* Remark:
+ * - this is an object window that acts as "relay", this is
+ *   it receives WSAAsyncSelect()'s messages and redirects
+ *   them to the appropriate PostMessageA function of USER32.
+ */
+
+
+/*****************************************************************************
+ * Includes                                                                  *
+ *****************************************************************************/
+
+/* object.c: the object window procedure on thread 2  */
+// os2 includes
+#define INCL_DOSPROCESS
+#define INCL_WIN
+#include <os2.h>
+// crt includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <odin.h>
+#include <odinwrap.h>
+#include <misc.h>
+
+#include "relaywin.h"
+
+ODINDEBUGCHANNEL(WSOCK32-RELAYWIN)
+
+
+/*****************************************************************************
+ * Structures                                                                *
+ *****************************************************************************/
+
+#define MAX_ASYNC_SOCKETS 64
+
+// static table for id / hwnd-msg translation
+static HWNDMSGPAIR arrHwndMsgPair[MAX_ASYNC_SOCKETS];
+static char*       ODIN_WSOCK_RELAY_CLASS = "ODIN_WSOCK_RELAY";
+
+
+// prototype for PostMessageA
+//BOOL _Stdcall PostMessageA(HWND,UINT,WPARAM,LPARAM);
+BOOL _System PostMessageA(HWND,UINT,ULONG,ULONG);
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+ULONG RelayAlloc(HWND hwnd, ULONG ulMsg)
+{
+  ULONG ulCounter;
+
+  for (ulCounter = 0;
+       ulCounter < MAX_ASYNC_SOCKETS;
+       ulCounter++)
+    if ( (arrHwndMsgPair[ulCounter].hwnd == 0) ||    // slot free?
+         (arrHwndMsgPair[ulCounter].hwnd == hwnd) )  // same window?
+    {
+      // occupy slot
+      arrHwndMsgPair[ulCounter].hwnd  = hwnd;
+      arrHwndMsgPair[ulCounter].ulMsg = ulMsg;
+      return ulCounter; // return "id"
+    }
+
+  return -1; // not found
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+ULONG RelayFree(ULONG ulID)
+{
+  if ( (ulID < 0) ||  // check range
+       (ulID >= MAX_ASYNC_SOCKETS) )
+    return -1; // error
+
+  arrHwndMsgPair[ulID].hwnd = 0; // mark free
+
+  return 0; // OK
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+ULONG RelayFreeByHwnd(HWND hwnd)
+{
+  ULONG ulCounter;
+
+  for (ulCounter = 0;
+       ulCounter < MAX_ASYNC_SOCKETS;
+       ulCounter++)
+    if ( arrHwndMsgPair[ulCounter].hwnd == hwnd )  // same window?
+    {
+      arrHwndMsgPair[ulCounter].hwnd  = 0; // free slot
+      return 0; // OK
+    }
+
+  return -1; // not found
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+PHWNDMSGPAIR RelayQuery(ULONG ulID)
+{
+  if ( (ulID < 0) ||  // check range
+       (ulID >= MAX_ASYNC_SOCKETS) )
+    return NULL; // error
+
+  return (&arrHwndMsgPair[ulID]);
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+MRESULT RelayWindowProc(HWND   hwnd,
+                        ULONG  ulMsg,
+                        MPARAM mp1,
+                        MPARAM mp2)
+{
+  PHWNDMSGPAIR pHM;
+
+  // termination flag handling?
+  // if (fTerminate)
+  //   WinDefWindowProc()
+  
+  //@@@PH: 1999/11/31 PROBLEM
+  // hwnd and ulMsg passed in have been converted by our USER32 code
+  // here, we ultimatively need to translate it back.
+  // under the debugger, things WORK now !:)
+  
+  pHM = RelayQuery(ulMsg);                          // find registered message
+  if (pHM != NULL)                                  // message pair found
+  {
+    PostMessageA(pHM->hwnd,
+                 pHM->ulMsg,
+                 (ULONG)mp1,
+                 (ULONG)mp2);
+
+    // if socket close, free entry
+    //@@@PH
+
+    return FALSE;                                   // OK, message sent
+  }
+
+  // default message processing
+  return WinDefWindowProc( hwnd, ulMsg, mp1, mp2 );
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+HWND RelayInitialize(HWND hwndPost)
+{
+  BOOL       fSuccess;
+  HAB        hab;
+  HWND       hwnd;
+
+
+  // thread initialization
+  hab = WinQueryAnchorBlock(hwndPost);
+  if (hab == NULLHANDLE)
+    return NULLHANDLE;
+
+  // register relay window class
+  fSuccess = WinRegisterClass(hab,
+                              ODIN_WSOCK_RELAY_CLASS,
+                              (PFNWP)RelayWindowProc,
+                              0,
+                              0);
+  if (fSuccess == FALSE)
+    return NULLHANDLE;
+
+  hwnd = WinCreateWindow(HWND_OBJECT,
+                         ODIN_WSOCK_RELAY_CLASS,
+                         "ODIN WSock Relay",
+                         0, 0, 0, 0, 0,
+                         HWND_OBJECT,
+                         HWND_BOTTOM,
+                         0,
+                         NULL,
+                         NULL );
+
+  //WinDestroyWindow( pg->hwndObject );
+  return hwnd;
+}
+
+
+/*****************************************************************************
+ * Name      :
+ * Purpose   :
+ * Parameters:
+ * Variables :
+ * Result    :
+ * Remark    :
+ * Status    :
+ *
+ * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
+ *****************************************************************************/
+
+BOOL RelayTerminate(HWND hwndRelay)
+{
+  return WinDestroyWindow(hwndRelay);
+}
+
Index: trunk/src/wsock32/new/relaywin.h
===================================================================
--- trunk/src/wsock32/new/relaywin.h	(revision 1908)
+++ trunk/src/wsock32/new/relaywin.h	(revision 1908)
@@ -0,0 +1,58 @@
+/* $Id: relaywin.h,v 1.1 1999-12-01 01:12:54 phaller Exp $ */
+
+/*
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ * Win32 SOCK32 for OS/2
+ *
+ * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
+ *
+ */
+
+/* Remark:
+ * - this is an object window that acts as "relay", this is
+ *   it receives WSAAsyncSelect()'s messages and redirects
+ *   them to the appropriate PostMessageA function of USER32.
+ */
+
+
+#ifndef _RELAYWIN_H_
+#define _RELAYWIN_H_
+
+
+/*****************************************************************************
+ * Includes                                                                  *
+ *****************************************************************************/
+
+/* object.c: the object window procedure on thread 2  */
+// os2 includes
+#define INCL_DOSPROCESS
+#define INCL_WIN
+#include <os2.h>
+
+/*****************************************************************************
+ * Structures                                                                *
+ *****************************************************************************/
+
+typedef struct tagHwndMsgPair
+{
+  HWND  hwnd;  /* target window            */
+  ULONG ulMsg; /* the message code to send */
+} HWNDMSGPAIR, *PHWNDMSGPAIR;
+
+/*****************************************************************************
+ * Prototypes                                                                *
+ *****************************************************************************/
+
+ULONG        RelayAlloc     (HWND  hwnd, ULONG ulMsg);
+ULONG        RelayFree      (ULONG ulID);
+ULONG        RelayFreeByHwnd(HWND  hwnd);
+PHWNDMSGPAIR RelayQuery     (ULONG ulID);
+MRESULT      RelayWindowProc(HWND  hwnd, ULONG  ulMsg, MPARAM mp1, MPARAM mp2);
+HWND         RelayInitialize(HWND  hwndPost);
+BOOL         RelayTerminate (HWND  hwndRelay);
+
+
+#endif /* _RELAYWIN_H_ */
+
Index: trunk/src/wsock32/new/wsock32.cpp
===================================================================
--- trunk/src/wsock32/new/wsock32.cpp	(revision 1906)
+++ trunk/src/wsock32/new/wsock32.cpp	(revision 1908)
@@ -1,3 +1,3 @@
-/* $Id: wsock32.cpp,v 1.5 1999-11-29 22:23:07 phaller Exp $ */
+/* $Id: wsock32.cpp,v 1.6 1999-12-01 01:10:55 phaller Exp $ */
 
 /*
@@ -46,4 +46,5 @@
 
 #include "wsock32.h"
+#include "relaywin.h"
 
 
@@ -590,5 +591,5 @@
               int *,fromlen)
 {
-  
+
   return(recvfrom(s,
                 buf,
@@ -795,5 +796,5 @@
   xx = gethostbyaddr((char *)addr,len,type);
   //PH: we assume PMWSOCK sets WSASetLastError correctly!
-  
+
   if(xx == NULL)
      return (WHOSTENT *)NULL;
@@ -834,5 +835,5 @@
   xx = gethostbyname((char *)name);
   //PH: we assume PMWSOCK sets WSASetLastError correctly!
-  
+
   if(xx == NULL)
     return (WHOSTENT *)NULL;
@@ -1341,25 +1342,45 @@
               long,lEvent)
 {
-  int rc;
-  int iError;
-  HWND hwndOS2;
-  
+  int   rc;
+  int   iError;
+  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
+  ULONG ulNewID;
+
+  static HWND hwndRelay; // handle to our relay window
+
+  if (hwndRelay == NULL) // already initialized ?
+    hwndRelay = RelayInitialize(hwndOS2);
+
   /* @@@PH: our source window doesn't seem to have an anchor block.
             Docs suggest we've missed to call WinInitialize on the
             caller thread.
-            
+
             Cause however is the Open32 handle is (of course!) invalid
             in plain PM Window Manager! -> use DAPWSOCK
-            
+
             Unfortunately, DAPWSOCK calls WinQueryAnchorBlock(hOpen32), too.
             So, we're stuck until I resolve hWnd to it's valid PM
             counterpart.
+
+            new problem: we've ultimately got to use PostMessageA instead
+            anything else. => create invisible msg relay window:
+            - hMsg = registerMessage(hWnd, wMsg)
+            - call WSAAsyncSelect with object window handle
+            - overwrite hWnd relay for "same handles"
    */
-  
-  hwndOS2 = Win32ToOS2Handle(hWnd);
-  
+
+  // add event to list or remove any list entry in case of WSAAsyncSelect(hwnd,0,0)
+  if ( (wMsg == 0) && (lEvent == 0) )
+  {
+    // remove entry from list
+    RelayFreeByHwnd(hWnd);
+  }
+  else
+    // add entry to list
+    ulNewID = RelayAlloc(hWnd, wMsg);
+
   rc = WSAAsyncSelect(s,
-                      hwndOS2,
-                      wMsg,
+                      hwndRelay,
+                      ulNewID,
                       lEvent);
 
