- int len;
- pid_t tid = 0;
- char staticBuf[STATICBUF_SIZE];
- tAxWin_Message *msg;
-
- // Wait for a message
- while( (len = SysGetMessage(&tid, NULL)) == 0 )
- sleep();
-
- // Allocate the space for it
- if( len <= STATICBUF_SIZE )
- msg = (void*)staticBuf;
- else {
- msg = malloc( len );
- if(!msg) {
- fprintf(
- stderr,
- "ERROR - Unable to allocate message buffer, ignoring message from %i\n",
- tid);
- SysGetMessage(NULL, GETMSG_IGNORE);
- return ;
- }
+ int tmp;
+ // TODO: Check this
+ giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ);
+ tmp = AXWIN_PORT; ioctl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number
+}
+
+void IPC_FillSelect(int *nfds, fd_set *set)
+{
+ if( giNetworkFileHandle > *nfds ) *nfds = giNetworkFileHandle;
+ FD_SET(giNetworkFileHandle, set);
+}
+
+void IPC_HandleSelect(fd_set *set)
+{
+ if( FD_ISSET(giNetworkFileHandle, set) )
+ {
+ char staticBuf[STATICBUF_SIZE];
+ int readlen, identlen;
+ char *msg;
+
+ readlen = read(giNetworkFileHandle, sizeof(staticBuf), staticBuf);
+
+ // Assume that all connections are from localhost
+ identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
+ msg = staticBuf + identlen;
+
+ Messages_Handle(identlen, staticBuf, readlen - identlen, (void*)msg, Messages_RespondDatagram);
+ }
+
+ while(SysGetMessage(NULL, NULL))
+ {
+ pid_t tid;
+ int len = SysGetMessage(&tid, NULL);
+ char data[len];
+ SysGetMessage(NULL, data);
+
+ Messages_Handle(sizeof(tid), &tid, len, (void*)data, Messages_RespondIPC);