X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin3_src%2Flibaxwin3.so_src%2Fmsg.c;h=bb09a36d68099f4dd61126a1a5c83fbaeecf609b;hb=32637a3bcd6e38425272f901745a76efa301afd5;hp=a9a79a30a72170d88a357820695a815aee4e44f3;hpb=479d0634670b58da044bc58149662adba0ad1d0b;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 a9a79a30..bb09a36d 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -12,12 +12,18 @@ #include // AxWin3 common #include "include/internal.h" #include "include/ipc.h" +#include + +#define assert(cnd) do{if(!(cnd)){_SysDebug("Assertion failed: %s", #cnd);}}while(0) + +#define STATICBUF_SIZE 0x1000 // === CONSTANTS === enum eConnectionType { CONNTYPE_NONE, CONNTYPE_SENDMESSAGE, + CONNTYPE_IPCPIPE, CONNTYPE_UDP, CONNTYPE_TCP }; @@ -33,7 +39,6 @@ tAxWin3_MessageCallback gAxWin3_MessageCallback; // === CODE === void AxWin3_Connect(const char *ServerDesc) { - _SysDebug("ServerDesc (argument) = %s", ServerDesc); if( !ServerDesc ) { ServerDesc = gsAxWin3_int_ServerDesc; } @@ -55,15 +60,31 @@ void AxWin3_Connect(const char *ServerDesc) } break; case 'u': - while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; - ServerDesc ++; + assert( strncmp(ServerDesc, "udp:", 4) == 0 ); + ServerDesc += 4; + _SysDebug("TODO: UDP connection to '%s'", ServerDesc); // TODO: Open socket and create UDP header break; case 't': - while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; - ServerDesc ++; + assert( strncmp(ServerDesc, "tcp:", 4) == 0 ); + ServerDesc += 4; + _SysDebug("TODO: TCP connection to '%s'", ServerDesc); // TODO: Open socket break; + case 'p': + assert( strncmp(ServerDesc, "pipe:", 5) == 0 ); + ServerDesc += 5; + giConnectionType = CONNTYPE_IPCPIPE; + giConnectionNum = _SysOpen(ServerDesc, OPENFLAG_READ|OPENFLAG_WRITE); + if( giConnectionNum == -1 ) { + _SysDebug("Cannot open IPC Pipe '%s'", ServerDesc); + exit(-1); + } + break; + default: + _SysDebug("Unknown server desc format '%s'", ServerDesc); + exit(-1); + break; } } @@ -107,11 +128,22 @@ void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) char tmpbuf[giAxWin3_int_UDPHeaderLen + size]; memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen); memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size); - _SysWrite(giConnectionNum, tmpbuf, sizeof(tmpbuf)); + size_t rv = _SysWrite(giConnectionNum, tmpbuf, sizeof(tmpbuf)); + if( rv == -1 ) { + _SysDebug("AxWin3 SendIPCMessage: UDP Write Failed %s", strerror(errno)); + exit(1); + } } break; - case CONNTYPE_TCP: - _SysWrite(giConnectionNum, Msg, size); + case CONNTYPE_IPCPIPE: + case CONNTYPE_TCP: { + size_t rv = _SysWrite(giConnectionNum, Msg, size); + if( rv != size ) { + _SysDebug("AxWin3 SendIPCMessage: Write Failed %s - sent %i want %i", + strerror(errno), rv, size); + exit(1); + } + } break; default: break; @@ -123,6 +155,17 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) int len; tAxWin_IPCMessage *ret = NULL; int tid; + fd_set local_set; + + if(!fds) + fds = &local_set; + + if( giConnectionType != CONNTYPE_SENDMESSAGE ) + { + if(nFD <= giConnectionNum) + nFD = giConnectionNum+1; + FD_SET(giConnectionNum, fds); + } _SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG); @@ -151,9 +194,24 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds) break; } - if( giConnectionType == CONNTYPE_TCP || giConnectionType == CONNTYPE_UDP ) + if( giConnectionType != CONNTYPE_SENDMESSAGE ) { - // Check fds + if( FD_ISSET(giConnectionNum, fds) ) + { + char tmpbuf[STATICBUF_SIZE]; + char *data = tmpbuf; + size_t len = _SysRead(giConnectionNum, tmpbuf, sizeof(tmpbuf)); + + if( giConnectionType == CONNTYPE_UDP ) + { + assert(len > giAxWin3_int_UDPHeaderLen); + len -= giAxWin3_int_UDPHeaderLen; + data += giAxWin3_int_UDPHeaderLen; + } + assert(len >= sizeof(tAxWin_IPCMessage)); + ret = malloc(len); + memcpy(ret, data, len); + } } return ret;