X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FApplications%2Faxwin3_src%2Flibaxwin3.so_src%2Fmsg.c;h=6c134a315d978c8e4f5c5903d952367f179ee53e;hb=f194730e75d6d3681e5f99a4efed1616fd1ea738;hp=76b38c2d7f8c772736999f7c8d0e81b0ca6c6a0c;hpb=184cdb36faa9cdf7e71af47a49c140b6fc4cebef;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c index 76b38c2d..6c134a31 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -9,12 +9,14 @@ #include #include #include -#include "include/ipc.h" +#include // AxWin3 common #include "include/internal.h" +#include "include/ipc.h" // === CONSTANTS === enum eConnectionType { + CONNTYPE_NONE, CONNTYPE_SENDMESSAGE, CONNTYPE_UDP, CONNTYPE_TCP @@ -31,9 +33,8 @@ tAxWin3_MessageCallback gAxWin3_MessageCallback; // === CODE === void AxWin3_Connect(const char *ServerDesc) { - _SysDebug("ServerDesc = %s", ServerDesc); - if( !ServerDesc ) - { + _SysDebug("ServerDesc (argument) = %s", ServerDesc); + if( !ServerDesc ) { ServerDesc = gsAxWin3_int_ServerDesc; } _SysDebug("ServerDesc = %s", ServerDesc); @@ -48,6 +49,10 @@ void AxWin3_Connect(const char *ServerDesc) case '6': case '7': case '8': case '9': case '0': giConnectionType = CONNTYPE_SENDMESSAGE; giConnectionNum = atoi(ServerDesc); + if( giConnectionNum == 0 ) { + _SysDebug("Invalid server PID"); + exit(-1); + } break; case 'u': while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; @@ -69,6 +74,14 @@ tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callba return old; } +uint32_t AxWin3_int_GetWindowID(tHWND Window) +{ + if(Window) + return Window->ServerID; + else + return -1; +} + tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes) { tAxWin_IPCMessage *ret; @@ -76,10 +89,7 @@ tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int ret = malloc( sizeof(tAxWin_IPCMessage) + ExtraBytes ); ret->Flags = Flags; ret->ID = Message; - if(Window) - ret->Window = Window->ServerID; - else - ret->Window = -1; + ret->Window = AxWin3_int_GetWindowID(Window); ret->Size = ExtraBytes; return ret; } @@ -108,49 +118,55 @@ 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: - // TODO: Less hack, I need a version of select for GetMessage etc - if(SysGetMessage(NULL, NULL) == 0) sleep(); - while(SysGetMessage(NULL, NULL)) + if( giConnectionType != CONNTYPE_SENDMESSAGE || tid != giConnectionNum ) { - pid_t tid; - len = SysGetMessage(&tid, NULL); - // Check if the message came from the server - if(tid != giConnectionNum) - { - // If not, pass the buck (or ignore) - if( gAxWin3_MessageCallback ) - gAxWin3_MessageCallback(tid, len); - else - SysGetMessage(NULL, GETMSG_IGNORE); - continue ; - } - - // If it's from the server, allocate a buffer and return it - ret = malloc(len); - if(ret == NULL) return NULL; - SysGetMessage(NULL, ret); - break; + _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 ; } - 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; } +tAxWin_IPCMessage *AxWin3_int_WaitIPCMessage(int WantedID) +{ + tAxWin_IPCMessage *msg; + for(;;) + { + msg = AxWin3_int_GetIPCMessage(0, NULL); + if(msg->ID == WantedID) return msg; + AxWin3_int_HandleMessage( msg ); + } +} +