Beispiel #1
0
void CServerMsg::AccedeProcess(CConnection *pCon, CMessage *pMsg)
{
	if ( !pCon->CheckActiveSocket() )	return ;
	char buf[1024]; 

	pMsg->SetIndex( );
	switch( pMsg->GetPtcl() )
	{
	case	CLIENT_DISCONNECT:
			sprintf( buf ,  "ip %s  socket %d Connection lost" ,pCon->GetIP(), pCon->GetSocket()  );
			ReleaseClient( pCon );
			LOG( buf  );
			break;
	case	CLIENT_GRACEFUL_DISCONNECT:
			ReleaseClient( pCon );
			LOG(" ReleaseConnection" );
			break;
	case	TEST_MSG_SPEEP:
			pMsg->GetBufferFromcharArray(buf,1024);
			long lVal = pMsg->GetObjDataFromcharArray<long>();
			LOG(" buf %s : %d ", buf , lVal);

			CMessage	msg(TEST_MSG_SPEEP);
			msg.AddtocharArray( "this is  test");
			msg.AddtocharArray(lVal);
			msg.BuildPacketHeader();
			msg.SendPlayer<CConnection>( pCon , true );
			break;
	}
}
Beispiel #2
0
static void
InputHandler(Widget W, int *Fd, XtInputId *Id)
{
    int i;
    int BytesRead;
    static char *ReadBuffer = NULL;
    static int BufferSize = 0;

#ifdef DEBUG
    printf("InputHandler(%s)\n", XtName(W));
#endif
    if (ReadBuffer == NULL)
    {
	BufferSize = 1;
	ReadBuffer = XtMalloc(BufferSize);
    }
    if (XtAppPending(XtWidgetToApplicationContext(W)) & XtIMAlternateInput)
    {
	fd_set rfds;
	struct timeval tv;

	FD_ZERO(&rfds);
	FD_SET(*Fd, &rfds);
	tv.tv_sec = 0;
	tv.tv_usec = 0;
	if (select(*Fd + 1, SELECT_TYPE_ARG234(&rfds), NULL, NULL, &tv))
	{
	    BytesRead = read(*Fd, ReadBuffer, BufferSize);
	    if (BytesRead == BufferSize)
	    {
		BufferSize++;
		ReadBuffer = XtRealloc(ReadBuffer, BufferSize);
	    }
	    switch (BytesRead)
	    {
	    case 0:
		fprintf(stderr, "InputHandler(%s) - EOF while reading device\n", XtName(W));
		switch (Host_Type(W))
		{
		case XltHOST_CLIENT:
		    Disconnect(W);
		    break;
		case XltHOST_SERVER:
		    ReleaseClient(W, *Fd);
		    break;
		default:
		    break;
		}
		break;
	    case -1:
		perror("InputHandler");
		Disconnect(W);
		break;
	    default:
		if (Host_InputCallback(W))
		{
		    _XltHostCallbackStruct tmp;

		    tmp.reason = XltCR_INPUT;
		    tmp.len = BytesRead;
		    tmp.data = XtMalloc(tmp.len);
		    memcpy(tmp.data, ReadBuffer, tmp.len);
		    tmp.input_size = Host_InputSize(W);
		    tmp.input_need = Host_InputNeed(W);
		    XtCallCallbackList(W, Host_InputCallback(W), &tmp);
		    if (tmp.len > BufferSize)
		    {
			ReadBuffer = XtRealloc(ReadBuffer, tmp.len);
			BufferSize = tmp.len;
		    }
		    memcpy(ReadBuffer, tmp.data, tmp.len);
		    BytesRead = tmp.len;
		    XtFree(tmp.data);
		}
		for (i = 0; i < BytesRead; i++)
		{
		    ProcessByte(W, ReadBuffer[i]);
		}
		break;
	    }
	    while (XtAppPending(XtWidgetToApplicationContext(W)) & ~XtIMAlternateInput)
	    {
		XtAppProcessEvent(XtWidgetToApplicationContext(W), ~XtIMAlternateInput);
	    }
	}
    }
}