Exemplo n.º 1
0
int work::socket_recv(int st)
{
	struct msg_t msg;
	memset(&msg,0,sizeof(msg));
	ssize_t rc = recv(st,(char*)&msg,sizeof(msg),0);
	if(rc <= 0)
	{
	    if(rc < 0)
	    {
		 printf("recv failed %s\n",strerror(errno));  
	     }
	}
	else 
	{ 
	  switch(msg.head[0])
	 {
	    case 0: sendmsg(&msg,rc);
	    break;
	    case 1: loginmsg(st,msg.head[1],msg.body);break;
	    default :
	     printf("login fail,it's not login message,%s\n",(const char*)&msg);
	     msg.head[0] = 2;
	     msg.head[1] = 0;
	     msg.head[2] = 0;
	     msg.head[3] = 0;
	     send(st,(const char*)&msg,sizeof(msg.head),0);
	     return 0;
	  }
	}
	return rc;	
}
Exemplo n.º 2
0
//=============================================================================
// METHOD: SPELLserverCif::login
//=============================================================================
SPELLipcMessage* SPELLserverCif::login()
{
    DEBUG("[CIF] Sending login message");

    // Create the login message
    SPELLipcMessage loginmsg( ExecutorMessages::REQ_NOTIF_EXEC_OPEN);
    loginmsg.setType(MSG_TYPE_REQUEST);
    loginmsg.setSender(getProcId());
    loginmsg.setReceiver("CTX");
    loginmsg.set( MessageField::FIELD_PROC_ID, getProcId());
    loginmsg.set( MessageField::FIELD_CSP, getProcId());

    // status loaded is not correct if the procedure did not compile, but the error will be
    // notified afterwards anyhow.
    loginmsg.set( MessageField::FIELD_EXEC_STATUS, StatusToString(STATUS_LOADED));
    loginmsg.set( MessageField::FIELD_ASRUN_NAME, getAsRunName() );
    loginmsg.set( MessageField::FIELD_LOG_NAME, SPELLlog::instance().getLogFile() );
    loginmsg.set( MessageField::FIELD_EXEC_PORT, "0" ); /** \todo Remove this, is deprecated */

    LOG_INFO("Login information:")
    LOG_INFO("Proc  : " + getProcId() )
    LOG_INFO("Status: LOADED")
    LOG_INFO("AsRun : " + getAsRunName() )
    LOG_INFO("Log   : " + SPELLlog::instance().getLogFile() )

    // Send the login message.
    // ERRORS: if there is a timeout in this request, an SPELLipcError exception will
    // be thrown and will make the executor die
    SPELLipcMessage* response = m_ifc->sendRequest(&loginmsg, SPELL_CIF_LOGIN_TIMEOUT_SEC);

    DEBUG("[CIF] Login done");
    return response;
}
Exemplo n.º 3
0
int work::socket_recv(int st)
{
	struct msg_t msg;
	memset(&msg, 0, sizeof(msg));

	ssize_t rc = recv(st, (char *) &msg, sizeof(msg), 0);//接收来自client socket发送来的消息
	if (rc <= 0)//接收失败
	{
		if (rc < 0)
			printf("recv failed %s\n", strerror(errno));
	} else//接收成功
	{
		switch (msg.head[0])
		{
		case 0: //send消息
			sendmsg(&msg, rc);
			break;
		case 1: //login消息
			loginmsg(st, msg.head[1], msg.body);
			break;
		default: //无法识别的消息
			printf("login fail, it's not login message,%s\n",
					(const char *) &msg);
			msg.head[0] = 2; //系统消息
			msg.head[1] = 0; //无法识别的消息
			msg.head[2] = 0; //暂时保留,填0
			msg.head[3] = 0; //暂时保留,填0
			send(st, (const char *) &msg, sizeof(msg.head), 0);//给client端socket下发系统消息
			return 0;
		}
	}
	return rc;
}