Usermode/AxWin3 - Updated clientside IPC code to allow select() usage by client
authorJohn Hodge (sonata) <[email protected]>
Wed, 17 Oct 2012 03:53:45 +0000 (11:53 +0800)
committerJohn Hodge (sonata) <[email protected]>
Wed, 17 Oct 2012 03:53:45 +0000 (11:53 +0800)
Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h
Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c
Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/axwin.h

index 82f76c6..6457c97 100644 (file)
@@ -14,7 +14,7 @@ extern const char     *gsAxWin3_int_ServerDesc;
 
 extern tAxWin_IPCMessage       *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes);
 extern void    AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg);
-extern tAxWin_IPCMessage       *AxWin3_int_GetIPCMessage(void);
+extern tAxWin_IPCMessage       *AxWin3_int_GetIPCMessage(int nFD, fd_set *FDs);
 extern tAxWin_IPCMessage       *AxWin3_int_WaitIPCMessage(int WantedID);
 extern void    AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg);
 
index 0c641cd..453d4ba 100644 (file)
@@ -25,15 +25,21 @@ void AxWin3_MainLoop(void)
 
        while(!bExit)
        {
-               msg = AxWin3_int_GetIPCMessage();
+               msg = AxWin3_int_GetIPCMessage(0, NULL);
                if(!msg)        continue;       
 
                _SysDebug("AxWin3_MainLoop - Message (Type=%i, Window=%i, Len=%i)",
                        msg->ID, msg->Window, msg->Size);
 
                AxWin3_int_HandleMessage( msg );
-               
-               free(msg);
        }
 }
 
+void AxWin3_MessageSelect(int nFD, fd_set *FDs)
+{
+       tAxWin_IPCMessage *msg;
+       msg = AxWin3_int_GetIPCMessage(nFD, FDs);
+       if( msg )
+               AxWin3_int_HandleMessage( msg );
+}
+
index ac51e27..e9003e1 100644 (file)
@@ -115,57 +115,43 @@ void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg)
        }
 }
 
-tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void)
+tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds)
 {
         int    len;
        tAxWin_IPCMessage       *ret = NULL;
-       switch(giConnectionType)
+       pid_t   tid;
+
+       _SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG);
+       
+       // Clear out IPC messages
+       while( (len = SysGetMessage(&tid, 0, NULL)) )
        {
-       case CONNTYPE_SENDMESSAGE:
-               for( ;; )
+               if( giConnectionType != CONNTYPE_SENDMESSAGE || tid != giConnectionNum )
                {
-                       pid_t   tid;
-               
-                       // Wait for a message to arrive 
-                       while( !(len = SysGetMessage(&tid, 0, NULL)) )
-                       {
-                               _SysWaitEvent(THREAD_EVENT_IPCMSG);
-                       }
-                       
-                       // Check if the message came from the server
-                       if(tid != giConnectionNum)
-                       {
-                               _SysDebug("%i byte message from %i", len, tid);
-                               // If not, pass the buck (or ignore)
-                               if( gAxWin3_MessageCallback )
-                                       gAxWin3_MessageCallback(tid, len);
-                               else
-                                       SysGetMessage(NULL, 0, GETMSG_IGNORE);
-                               continue ;
-                       }
-                       
-                       // If it's from the server, allocate a buffer and return it
-                       ret = malloc(len);
-                       if(ret == NULL) {
-                               _SysDebug("malloc() failed, ignoring message");
+                       _SysDebug("%i byte message from %i", len, tid);
+                       // If not, pass the buck (or ignore)
+                       if( gAxWin3_MessageCallback )
+                               gAxWin3_MessageCallback(tid, len);
+                       else
                                SysGetMessage(NULL, 0, GETMSG_IGNORE);
-                               return NULL;
-                       }
-                       SysGetMessage(NULL, len, ret);
-                       break;
+                       continue ;
                }
-               break;
-       default:
-               // TODO: Implement
-               _SysDebug("TODO: Implement AxWin3_int_GetIPCMessage for TCP/UDP");
+               
+               // Using CONNTYPE_SENDMESSAGE and server message has arrived
+               ret = malloc(len);
+               if(ret == NULL) {
+                       _SysDebug("malloc() failed, ignoring message");
+                       SysGetMessage(NULL, 0, GETMSG_IGNORE);
+                       return NULL;
+               }
+               SysGetMessage(NULL, len, ret);
                break;
        }
 
-       // No message?
-       if( ret == NULL )
-               return NULL;
-
-       // TODO: Sanity checks, so a stupid server can't crash us
+       if( giConnectionType == CONNTYPE_TCP || giConnectionType == CONNTYPE_UDP )
+       {
+               // Check fds
+       }
 
        return ret;
 }
@@ -175,10 +161,9 @@ tAxWin_IPCMessage *AxWin3_int_WaitIPCMessage(int WantedID)
        tAxWin_IPCMessage       *msg;
        for(;;)
        {
-               msg = AxWin3_int_GetIPCMessage();
+               msg = AxWin3_int_GetIPCMessage(0, NULL);
                if(msg->ID == WantedID) return msg;
                AxWin3_int_HandleMessage( msg );
-               free(msg);
        }
 }
 
index 4a6d8d3..412f583 100644 (file)
@@ -226,6 +226,8 @@ void AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg)
                _SysDebug("Unknow message ID %i", Msg->ID);
                break;
        }
+       
+       free(Msg);
 }
 
 void AxWin3_SetWindowTitle(tHWND Window, const char *Title)
index 8d91173..04abfaf 100644 (file)
@@ -9,6 +9,7 @@
 #define _AXWIN3_AXWIN_H_
 
 #include <stddef.h>    // size_t
+#include <unistd.h>
 
 // === CONSTANTS ===
 
@@ -25,6 +26,7 @@ typedef int   (*tAxWin3_WindowMessageHandler)(tHWND Window, int Message, int Lengt
 extern void    AxWin3_Connect(const char *ServerDesc);
 extern tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback);
 extern void    AxWin3_MainLoop(void);
+extern void    AxWin3_MessageSelect(int nFD, fd_set *FDs);
 
 // --- Non-Window based functions
 extern int     AxWin3_GetDisplayCount(void);

UCC git Repository :: git.ucc.asn.au