#include <stdlib.h>
#include <ipcmessages.h> // AxWin3 common
#include "include/internal.h"
+#include "include/ipc.h"
// === CONSTANTS ===
enum eConnectionType
{
+ CONNTYPE_NONE,
CONNTYPE_SENDMESSAGE,
CONNTYPE_UDP,
CONNTYPE_TCP
switch(giConnectionType)
{
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))
+ for( ;; )
{
pid_t tid;
- len = SysGetMessage(&tid, NULL);
+
+ // Wait for a message to arrive
+ while( !(len = SysGetMessage(&tid, 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);
// If it's from the server, allocate a buffer and return it
ret = malloc(len);
- if(ret == NULL) return NULL;
+ if(ret == NULL) {
+ _SysDebug("malloc() failed, ignoring message");
+ SysGetMessage(NULL, GETMSG_IGNORE);
+ return NULL;
+ }
SysGetMessage(NULL, ret);
break;
}
return ret;
}
+tAxWin_IPCMessage *AxWin3_int_WaitIPCMessage(int WantedID)
+{
+ tAxWin_IPCMessage *msg;
+ for(;;)
+ {
+ msg = AxWin3_int_GetIPCMessage();
+ if(msg->ID == WantedID) return msg;
+ AxWin3_int_HandleMessage( msg );
+ free(msg);
+ }
+}
+