Example #1
0
File: queue.c Project: exeasy/tcm2
char	*GetQueueLast( MyQueue *p )
{
	int	queue_num = 0;
	char	*element = NULL;

	queue_num = GetQueueNum( p );

	element = GetQueueElem( p, queue_num );

	return element;
}
Example #2
0
static int ClientSendCommand(EmCmdCode emCmdCode, void *pDataBuf,
                             unsigned int u32DataSize, int s32LoginID,
                             bool boIsRespond,  bool boIsEcho, bool boIsReturnSock)
{
    int ret, sock;
    StMsgPkg stMsg, stEchoMsg;
    stLoginInfo Login;
    unsigned short port;

    ret = GetQueueElem(&s_UserLoginInfoQueue, s32LoginID, &Login);
    if (ret < 0)
    {
        LOGERR("please login\n");
        return -1;
    }

    memset(&stMsg, 0, sizeof(StMsgPkg));
    stMsg.stAccount = Login.stUserAccount;

    //给u8DataBuffer字段复制,并计算校验值
    BuildMsg(&stMsg, emCmdCode, pDataBuf, u32DataSize);

    if (emCmdCode == _CmdPlayCtrl)
    {
        port = STREAM_SERVER_DEFAULT_PORT;
    }
    else
    {
        port = Login.u16DevPort;
    }

    //发送数据到服务器,并接收服务器返回的数据
    sock = TcpClientCommServer(Login.pDevIP, port, (char *)&stMsg,
                               sizeof(StMsgPkg), 3000000, boIsRespond,
                               (char *)&stEchoMsg, sizeof(StMsgPkg));
    if (sock < 0)
    {
        LOGERR("TcpClientCommServer error\n");
        return -1;
    }


    if (boIsRespond == TRUE)
    {
        //判断echo是否正确
        if(CheckEcho(&stEchoMsg, emCmdCode))
        {
            LOGERR("CheckEcho error\n");
            return -1;
        }

        if (boIsEcho == TRUE)
        {
            if(u32DataSize == stEchoMsg.u32DataLength)
            {
                memcpy(pDataBuf, stEchoMsg.uoData.u8DataBuffer, u32DataSize);
            }
            else
            {
                LOGERR("receive message data length error\n");
                return -1;
            }
        }
    }

    if (boIsReturnSock == TRUE)
    {
        return sock;
    }
    else
    {
        close(sock);
        return 0;
    }
}