-void IPC_Init(void)
-{
- int tmp;
- // TODO: Check this
- giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ);
- if( giNetworkFileHandle != -1 )
- {
- tmp = AXWIN_PORT;
- ioctl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number
- }
-}
-
-void IPC_FillSelect(int *nfds, fd_set *set)
-{
- if( giNetworkFileHandle != -1 )
- {
- if( giNetworkFileHandle > *nfds ) *nfds = giNetworkFileHandle;
- FD_SET(giNetworkFileHandle, set);
- }
-}
-
-void IPC_HandleSelect(fd_set *set)
-{
- if( giNetworkFileHandle != -1 )
- {
- if( FD_ISSET(giNetworkFileHandle, set) )
- {
- char staticBuf[STATICBUF_SIZE];
- int readlen, identlen;
- char *msg;
-
- readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
-
- identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
- msg = staticBuf + identlen;
-
- IPC_Handle(&gIPC_Type_Datagram, staticBuf, readlen - identlen, (void*)msg);
-// _SysDebug("IPC_HandleSelect: UDP handled");
- }
- }
-
- size_t len;
- pid_t tid;
- while( (len = SysGetMessage(&tid, 0, NULL)) )
- {
- char data[len];
- SysGetMessage(NULL, len, data);
-
- IPC_Handle(&gIPC_Type_SysMessage, &tid, len, (void*)data);
-// _SysDebug("IPC_HandleSelect: Message handled");
- }
-}
-
-int IPC_Type_Datagram_GetSize(const void *Ident)
-{
- return 4 + Net_GetAddressSize( ((const uint16_t*)Ident)[1] );
-}
-
-int IPC_Type_Datagram_Compare(const void *Ident1, const void *Ident2)
-{
- // Pass the buck :)
- // - No need to worry about mis-matching sizes, as the size is computed
- // from the 3rd/4th bytes, hence it will differ before the size is hit.
- return memcmp(Ident1, Ident2, IPC_Type_Datagram_GetSize(Ident1));
-}
-
-void IPC_Type_Datagram_Send(const void *Ident, size_t Length, const void *Data)
-{
- int identlen = IPC_Type_Datagram_GetSize(Ident);
- char tmpbuf[ identlen + Length ];
- memcpy(tmpbuf, Ident, identlen); // Header
- memcpy(tmpbuf + identlen, Data, Length); // Data
- // TODO: Handle fragmented packets
- write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
-}
-
-int IPC_Type_Sys_GetSize(const void *Ident)
-{
- return sizeof(pid_t);
-}
-
-int IPC_Type_Sys_Compare(const void *Ident1, const void *Ident2)
-{
- return *(const tid_t*)Ident1 - *(const tid_t*)Ident2;
-}
-
-void IPC_Type_Sys_Send(const void *Ident, size_t Length, const void *Data)
-{
- SysSendMessage( *(const tid_t*)Ident, Length, Data );
-}
-