network.c
changeset 173 df7c566d219f
parent 172 8d8b3383470d
child 175 d6cccece959a
equal deleted inserted replaced
172:8d8b3383470d 173:df7c566d219f
    60 # define GET_LAST_ERROR() 							Errno()
    60 # define GET_LAST_ERROR() 							Errno()
    61 #	define ioctlsocket(s,request,status)  IoctlSocket((LONG)s,(ULONG)request,(char*)status)
    61 #	define ioctlsocket(s,request,status)  IoctlSocket((LONG)s,(ULONG)request,(char*)status)
    62 
    62 
    63 struct Library *SocketBase = NULL;
    63 struct Library *SocketBase = NULL;
    64 
    64 
       
    65 #if !defined(__MORPHOS__)
    65 // usleep() implementation
    66 // usleep() implementation
    66 #include <devices/timer.h>
    67 #include <devices/timer.h>
    67 #include <dos/dos.h>
    68 #include <dos/dos.h>
    68 
    69 
    69 struct Device       *TimerBase    = NULL;
    70 struct Device       *TimerBase    = NULL;
    70 struct MsgPort      *TimerPort    = NULL;
    71 struct MsgPort      *TimerPort    = NULL;
    71 struct timerequest  *TimerRequest = NULL;
    72 struct timerequest  *TimerRequest = NULL;
       
    73 #endif
    72 
    74 
    73 #endif /* __MORPHOS__ || __AMIGA__ */
    75 #endif /* __MORPHOS__ || __AMIGA__ */
    74 
    76 
    75 
    77 
    76 #define SEND_MTU 1460
    78 #define SEND_MTU 1460
   254 usleep(milliseconds*1000);
   256 usleep(milliseconds*1000);
   255 #endif
   257 #endif
   256 #ifdef __BEOS__
   258 #ifdef __BEOS__
   257 snooze(milliseconds*1000);
   259 snooze(milliseconds*1000);
   258 #endif
   260 #endif
   259 #if defined(__MORPHOS__) || defined(__AMIGAOS__)
   261 #if defined(__MORPHOS__) 
   260 {
   262 usleep(milliseconds*1000);
       
   263 #endif
       
   264 #if defined(__AMIGAOS__) && !defined(__MORPHOS__) 
       
   265 { 
   261 	ULONG signals;
   266 	ULONG signals;
   262 	ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
   267 	ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
   263 
   268 
   264 	// send IORequest
   269 	// send IORequest
   265 	TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
   270 	TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
   270 	if ( !((signals = Wait(TimerSigBit|SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
   275 	if ( !((signals = Wait(TimerSigBit|SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
   271 		AbortIO((struct IORequest *)TimerRequest);
   276 		AbortIO((struct IORequest *)TimerRequest);
   272 	}
   277 	}
   273 	WaitIO((struct IORequest *)TimerRequest);
   278 	WaitIO((struct IORequest *)TimerRequest);
   274 }
   279 }
   275 #endif // __MORPHOS__ || __AMIGAOS__
   280 #endif // __AMIGAOS__ && !__MORPHOS__
   276 #endif
   281 #endif
   277 }
   282 }
   278 
   283 
   279 //////////////////////////////////////////////////////////////////////
   284 //////////////////////////////////////////////////////////////////////
   280 
   285 
  1216 		};
  1221 		};
  1217 	}
  1222 	}
  1218 
  1223 
  1219 void NetworkUDPReceive(bool client) {
  1224 void NetworkUDPReceive(bool client) {
  1220 	struct sockaddr_in client_addr;
  1225 	struct sockaddr_in client_addr;
       
  1226 #ifndef __MORPHOS__
  1221 	int client_len;
  1227 	int client_len;
       
  1228 #else
       
  1229 	LONG client_len; // for some reason we need a 'LONG' under MorphOS
       
  1230 #endif
  1222 	int nbytes;
  1231 	int nbytes;
  1223 	struct UDPPacket packet;
  1232 	struct UDPPacket packet;
  1224 	int packet_len;
  1233 	int packet_len;
  1225 	
  1234 	
  1226 	SOCKET udp;
  1235 	SOCKET udp;
  1398 	if (!(SocketBase = OpenLibrary("bsdsocket.library", 4))) {
  1407 	if (!(SocketBase = OpenLibrary("bsdsocket.library", 4))) {
  1399 		DEBUG(misc,3) ("[NET][Core] Couldn't open bsdsocket.library version 4.");
  1408 		DEBUG(misc,3) ("[NET][Core] Couldn't open bsdsocket.library version 4.");
  1400 		_network_available=false;
  1409 		_network_available=false;
  1401 		}
  1410 		}
  1402 
  1411 
  1403 	// for usleep() implementation
  1412 	#if !defined(__MORPHOS__)
       
  1413 	// for usleep() implementation (only required for legacy AmigaOS builds)
  1404 	if ( (TimerPort = CreateMsgPort()) ) {
  1414 	if ( (TimerPort = CreateMsgPort()) ) {
  1405 		if ( (TimerRequest = (struct timerequest *) CreateIORequest(TimerPort, sizeof(struct timerequest))) ) {
  1415 		if ( (TimerRequest = (struct timerequest *) CreateIORequest(TimerPort, sizeof(struct timerequest))) ) {
  1406 			if ( OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *) TimerRequest, 0) == 0 ) {
  1416 			if ( OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *) TimerRequest, 0) == 0 ) {
  1407 				if ( !(TimerBase = TimerRequest->tr_node.io_Device) ) {
  1417 				if ( !(TimerBase = TimerRequest->tr_node.io_Device) ) {
  1408 					// free ressources... 
  1418 					// free ressources... 
  1410 					_network_available=false;
  1420 					_network_available=false;
  1411 				}
  1421 				}
  1412 			}
  1422 			}
  1413 		}
  1423 		}
  1414 	}
  1424 	}
       
  1425 	#endif 
       
  1426 
  1415 }
  1427 }
  1416 #else
  1428 #else
  1417 
  1429 
  1418 // [linux/macos] unix-socket startup
  1430 // [linux/macos] unix-socket startup
  1419 
  1431 
  1441 DEBUG(misc,3) ("[NET][Core] shutdown()");
  1453 DEBUG(misc,3) ("[NET][Core] shutdown()");
  1442 
  1454 
  1443 #if defined(__MORPHOS__) || defined(__AMIGA__)
  1455 #if defined(__MORPHOS__) || defined(__AMIGA__)
  1444 {	
  1456 {	
  1445 	// free allocated ressources
  1457 	// free allocated ressources
       
  1458 	#if !defined(__MORPHOS__) 
  1446   if (TimerBase)    { CloseDevice((struct IORequest *) TimerRequest); }
  1459   if (TimerBase)    { CloseDevice((struct IORequest *) TimerRequest); }
  1447   if (TimerRequest) { DeleteIORequest(TimerRequest); }
  1460   if (TimerRequest) { DeleteIORequest(TimerRequest); }
  1448   if (TimerPort)    { DeleteMsgPort(TimerPort); }
  1461   if (TimerPort)    { DeleteMsgPort(TimerPort); }
       
  1462 	#endif
  1449 
  1463 
  1450 	if (SocketBase) {
  1464 	if (SocketBase) {
  1451 		CloseLibrary(SocketBase);
  1465 		CloseLibrary(SocketBase);
  1452 	}
  1466 	}
  1453 }
  1467 }