Example #1
0
string Server::RecibirDatos()
{
	string resultado;

	bzero(client_message, 2000);
	read_size = recv(client_sock , client_message , 2000 , 0);

	if(read_size == 0)
	{
		puts("Client disconnected");
		this->estado_cliente = "desconectado";
		resultado = "salir";
		fflush(stdout);
	}
	else if(read_size == -1)
	{
		perror("recv failed");
	}
	else
		resultado = Array2String(client_message, read_size);

	SendReady();

	return resultado;
}
Example #2
0
unsigned int NetworkSink::TimedFlush(unsigned long maxTime)
{
	if (m_buffer.IsEmpty())
		return 0;

	bool forever = maxTime == INFINITE_TIME;
	Timer timer(Timer::MILLISECONDS);
	unsigned long elapsed, timeout;
	unsigned int totalFlushSize = 0;

	while (true)
	{
		if (m_needSendResult)
		{
			if (forever)
				timeout = INFINITE_TIME;
			else if ((elapsed = timer.ElapsedTime()) <= maxTime)
				timeout = maxTime - elapsed;
			else
				timeout = 0;

			if (!SendResultReady(timeout))
				break;

			unsigned int sendResult = GetSendResult();
			m_buffer.Skip(sendResult);
			totalFlushSize += sendResult;
			m_needSendResult = false;

			if (m_buffer.IsEmpty())
				break;
		}

		if (forever)
			timeout = INFINITE_TIME;
		else if ((elapsed = timer.ElapsedTime()) <= maxTime)
			timeout = maxTime - elapsed;
		else
			break;

		if (!SendReady(timeout))
			break;

		unsigned int contiguousSize = 0;
		const byte *block = m_buffer.Spy(contiguousSize);

		Send(block, contiguousSize);
		m_needSendResult = true;
	}

	return totalFlushSize;
}
Example #3
0
void NetworkSink::Put(const byte *str, unsigned int bc)
{
	LazyPutter lp(m_buffer, str, bc);

	while (m_buffer.CurrentSize() > m_maxBufferSize)
	{
		if (m_needSendResult)
			SendResultReady(INFINITE_TIME);
		else
			SendReady(INFINITE_TIME);

		Flush(0);
	}

	if (m_autoFlush)
		Flush(0);
}