Example #1
0
int
main(int argc, char *argv[])
{
	options_init();
	options_deal(argc, argv);
	video_init();
	screen_init();
	screen_mainloop();
	screen_quit();
	video_quit();
	exit(EXIT_SUCCESS);
}
Example #2
0
/*********************************************************************
 Callback from client listening to server in its own thread
 Only used for data transfers
 *********************************************************************/
static int async_data_recv(void * p_pData)
{
	context_t * l_pContext = (context_t *) p_pData;

	while (true)
	{
		uint32_t l_FrameSize = 0U;

		if (network_read_bytes(l_pContext->socket_data, (char *) &l_FrameSize,
				sizeof(uint32_t)) == RET_NOK)
		{
			break;
		}

		{
			l_FrameSize = ntohl(l_FrameSize);
			wlog(LOGDEVELOPER, "received on data %u bytes long frame on socket %u",
					l_FrameSize, l_pContext->socket_data);

			NetworkFrame l_Frame(l_FrameSize);

			if (network_read_bytes(l_pContext->socket_data,
					(char *) l_Frame.getFrame(), l_FrameSize) == RET_NOK)
			{
				break;
			}
			if (parse_incoming_data(l_pContext, l_Frame) == RET_NOK)
			{
				break;
			}
		}
	}

	werr(LOGUSER, "Socket closed on server side.");

	context_set_connected(l_pContext, false);
	SDLNet_TCP_Close(l_pContext->socket);
	SDLNet_TCP_Close(l_pContext->socket_data);
	context_set_socket(l_pContext, 0);
	context_set_socket_data(l_pContext, 0);

	screen_quit();

	return 0;
}