All pastes #991809 Raw Edit

Stuff

public text v1 · immutable
#991809 ·published 2008-04-21 12:01 UTC
rendered paste body
static void io_handle(int fd, short EventCode, void *arg)
{
	if(!arg)
	{
		sLog.outError("<Socket unknown> Bad (null) param in read callback.");
		return;
	}

	SocketBase* pSocket = (SocketBase*)arg;
	if(fd != pSocket->GetSocket())
	{
		sLog.outError("Catastrophic: event fd [%u] doesn't match conn fd [%u] while reading!", 
			fd, pSocket->GetSocket());
		pSocket->Disconnect(true);
		return;
	}

	if(!pSocket->IsConnected())
		return;

	if(pSocket->IsMarkedAsDisconnected())
	{
		pSocket->Disconnect();
		return;
	}

	switch(EventCode)
	{
	case EV_TIMEOUT:
		pSocket->OnTimeoutEvent();
		break;
	case EV_READ:
		pSocket->OnReadEvent();
		break;
	case EV_WRITE:
		pSocket->OnWriteEvent();
		break;
	default:
		sLog.outError("<Socket %u> Unknown event [%u]", fd, EventCode);
	}

	if(pSocket->IsMarkedAsDisconnected())
	{
		pSocket->Disconnect();
		return;
	}
}