Beispiel #1
0
int ndSendMsg(netObject netObj,struct ndMsgData *data, int flag)
{
	int ret ;
    data->reserved = 0 ;
    ret = nd_connector_send((nd_handle) netObj, (nd_packhdr_t *)data, flag) ;
	if (-1 == ret && NDERR_WOULD_BLOCK != nd_object_lasterror((nd_handle)netObj)) {
		tryto_terminate(netObj) ;
	}
	return ret ;
}
Beispiel #2
0
int ndSendData(netObject netObj, char *data, int dataLen, int flag)
{
    int ret = 0 ;
    nd_packhdr_t *msghdr = (nd_packhdr_t *) data ;
	
	ND_USERMSG_SYS_RESERVED(msghdr) = 0 ;
    packet_ntoh(&msghdr) ;
    ret = nd_connector_send((nd_handle) netObj, (nd_packhdr_t *)data, flag) ;
    packet_hton(&msghdr) ;
	if (-1 == ret && NDERR_WOULD_BLOCK != nd_object_lasterror((nd_handle)netObj)) {
		tryto_terminate(netObj) ;
	}
    return ret ;
}
Beispiel #3
0
int ndSendAndWaitMessage(nd_handle nethandle, nd_usermsgbuf_t *sendBuf, nd_usermsgbuf_t* recvBuf, ndmsgid_t waitMaxid, ndmsgid_t waitMinid, int sendFlag, int timeout)
{
	if (nd_connector_send(nethandle, (nd_packhdr_t*)sendBuf, sendFlag) <= 0) {
		nd_object_seterror(nethandle, NDERR_WRITE);
		nd_logerror("send data error: NDERR_WRITE\n");
		return -1;
	}
	ndtime_t start_tm = nd_time();
RE_RECV:

	if (-1 == nd_connector_waitmsg(nethandle, (nd_packetbuf_t *)recvBuf, timeout)) {
		nd_object_seterror(nethandle, NDERR_TIMEOUT);
		nd_logerror("wait message timeout\n");
		return -1;
	}
	else if (recvBuf->msg_hdr.packet_hdr.ndsys_msg){
		if (-1 == nd_net_sysmsg_hander((nd_netui_handle)nethandle, (nd_sysresv_pack_t *)recvBuf)){
			nd_logerror("receive system mesaage and handler error \n");
			return -1;
		}
	}
	else if (nd_checkErrorMsg(nethandle, (struct ndMsgData*)recvBuf)) {
		nd_logerror("receive error message \n");
		return -1;
	}
	else if (ND_USERMSG_MAXID(recvBuf) != waitMaxid || ND_USERMSG_MINID(recvBuf) != waitMinid) {
		if ((nd_time() - start_tm) >= timeout) {
			nd_object_seterror(nethandle, NDERR_TIMEOUT);
			nd_logerror("wait message(%d,%d) timeout\n", waitMaxid, waitMinid);
			return -1;
		}
		if (((nd_netui_handle)nethandle)->msg_handle) {
			//int ret = nd_translate_message(nethandle, (nd_packhdr_t*)recvBuf, NULL);
			int ret = _packet_handler((nd_netui_handle)nethandle, &recvBuf->msg_hdr.packet_hdr, NULL);
			if (ret == -1){
				nd_logerror("wait message(%d,%d) error ,recvd(%d,%d)\n", waitMaxid, waitMinid, ND_USERMSG_MAXID(recvBuf), ND_USERMSG_MINID(recvBuf));
				return ret;
			}
		}
		goto RE_RECV;
	}
	return 0;
}
Beispiel #4
0
RESULT_T apoCli_sendMsg(int messageId, void *messageBody, int bodySize)
{
	NDOStreamMsg omsg((NDUINT16) messageId);
	if (messageBody && bodySize > 0) {
		if (-1 == omsg.WriteStream((char*)messageBody, bodySize)) {
			return NDSYS_ERR_INVALID_INPUT;
		}
	}
	
	ApoClient *apoCli = ApoClient::getInstant();
	if (apoCli)	{
		if (!apoCli->IsInConnect())	{
			nd_logerror("can not send data, MUST LOGIN \n") ;
			return NDSYS_ERR_NEED_LOGIN;
		}

		nd_connector_send(apoCli->getConn(), &(omsg.GetMsgAddr()->msg_hdr.packet_hdr), 0);
		return ESERVER_ERR_SUCCESS;
	}
	return NDSYS_ERR_NOT_INIT;
}