lib/dgr.c
/** Receives DGR data from the network.
 *
 * @param timeout If timeout > 0, dgr_receive() will block for at most
 * 'timeout' milliseconds. If a timeout occurs, DGR will exit. If
 * timeout==0, dgr_receive() not block and will read whatever
 * information is available to read. If timeout==0, we still might
 * exit if we haven't received information for a while (and we have
 * received information successfully in the past). */
Receives DGR data from the network.
@param timeout If timeout > 0, dgr_receive() will block for at most
'timeout' milliseconds. If a timeout occurs, DGR will exit. If
timeout==0, dgr_receive() not block and will read whatever
information is available to read. If timeout==0, we still might
exit if we haven't received information for a while (and we have
received information successfully in the past).
Receives DGR data from the network . @param timeout If timeout > 0 dgr_receive () will block for at most ' timeout ' milliseconds . If a timeout occurs DGR will exit . If timeout == 0 dgr_receive () not block and will read whatever information is available to read . If timeout == 0 we still might exit if we haven ' t received information for a while ( and we have received information successfully in the past ) .
static void dgr_receive(int timeout)
{
#if !defined __MINGW32__ && !defined _WIN32
	if(dgr_disabled)
		return;
	if(dgr_time_lastreceive != 0) 
	{
		int seconds = 15;
		if(time(NULL) - dgr_time_lastreceive >= seconds)
		{
			msg(MSG_FATAL, "DGR Slave: dgr_receive() hasn't received packets within %d seconds. We did receive one or more packets earlier. Did the master die? Exiting...\n", seconds);
			exit(EXIT_FAILURE);
		}
	}
	struct pollfd fds;
	fds.fd = dgr_socket;
	fds.events = POLLIN;
	int retval = poll(&fds, 1, timeout);
	if(retval == -1)
	{
		msg(MSG_FATAL, "poll(): %s", strerror(errno));
		exit(EXIT_FAILURE);
	}
	else if(retval == 0) 
	{
		if(timeout > 0)
		{
			msg(MSG_FATAL, "DGR Slave: dgr_receive() never received anything and timed out (%f second timeout). Exiting...\n", timeout/1000.0);
			exit(EXIT_FAILURE);
		}
		return;
	}
	struct sockaddr_storage their_addr;
	socklen_t addr_len = sizeof their_addr;
	char serialized[1024*1024];
	int numbytes;
	while(1)
	{
		if ((numbytes = recvfrom(dgr_socket, serialized, 1024*1024, 0,
		                         (struct sockaddr *)&their_addr, &addr_len)) == -1) {
			msg(MSG_FATAL, "recvfrom: %s", strerror(errno));
			exit(EXIT_FAILURE);
		}
		struct pollfd fds;
		fds.fd = dgr_socket;
		fds.events = POLLIN;
		int retval = poll(&fds, 1, 0);
		if(retval == 0)
			break;
	}
	dgr_time_lastreceive = time(NULL);
	dgr_unserialize(numbytes, serialized);
	int died = 0;
	if(dgr_get("!!!dgr_died!!!", &died, sizeof(int)) >= 0 &&
	   died == 1)
	{
		msg(MSG_DEBUG, "The master told slaves to exit. Exiting...\n");
		exit(EXIT_SUCCESS);
	}
#endif 
}
static void dgr_receive ( int timeout ) { #if ! defined __MINGW32__ && ! defined _WIN32 if ( dgr_disabled ) return ; if ( dgr_time_lastreceive != 0 ) { int seconds = 15 ; if ( time ( NULL ) - dgr_time_lastreceive >= seconds ) { msg ( MSG_FATAL , " \n " , seconds ) ; exit ( EXIT_FAILURE ) ; } } struct pollfd fds ; fds . fd = dgr_socket ; fds . events = POLLIN ; int retval = poll ( & fds , 1 , timeout ) ; if ( retval == -1 ) { msg ( MSG_FATAL , " " , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } else if ( retval == 0 ) { if ( timeout > 0 ) { msg ( MSG_FATAL , " \n " , timeout / 1000.0 ) ; exit ( EXIT_FAILURE ) ; } return ; } struct sockaddr_storage their_addr ; socklen_t addr_len = sizeof their_addr ; char serialized [ 1024 * 1024 ] ; int numbytes ; while ( 1 ) { if ( ( numbytes = recvfrom ( dgr_socket , serialized , 1024 * 1024 , 0 , ( struct sockaddr * ) & their_addr , & addr_len ) ) == -1 ) { msg ( MSG_FATAL , " " , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } struct pollfd fds ; fds . fd = dgr_socket ; fds . events = POLLIN ; int retval = poll ( & fds , 1 , 0 ) ; if ( retval == 0 ) break ; } dgr_time_lastreceive = time ( NULL ) ; dgr_unserialize ( numbytes , serialized ) ; int died = 0 ; if ( dgr_get ( " " , & died , sizeof ( int ) ) >= 0 && died == 1 ) { msg ( MSG_DEBUG , " \n " ) ; exit ( EXIT_SUCCESS ) ; } #endif }
Receives DGR data from the network.
Receives DGR data from the network .
/* If too much time has elapsed since the last packet that we received, exit. */ // if we have received a packet previously /* Use poll to wait for up to timeout seconds. */ // nothing to read within timeout value /* If a non-zero timeout value was specified and we timed out, exit() */ /* Read packets until there are no more to read. This ensures that
	 * we are always using the newest packet. For example, 5 packets
	 * might arrive while the slave is rendering a scene. We want to
	 * make sure that we use the newest packet. */ // if there is nothing to read anymore from the socket, break out of loop. /* If the packet we received indicates that dgr has died. */ // __MINGW32__