Example #1
0
RESULT_T apoCli_close()
{
	ApoClient *apoCli = ApoClient::getInstant();
	if (!apoCli)	{
		return NDSYS_ERR_NOT_INIT;
	}

	apoCli->Close();
	nd_logdebug("net closed\n");
	return ESERVER_ERR_SUCCESS;
}
Example #2
0
RESULT_T apoCli_open(const char *host, int port)
{
	ApoClient *apoCli = ApoClient::getInstant();
	if (!apoCli)	{
		
		nd_logerror("open net, MUST INIT before open\n") ;
		
		return NDSYS_ERR_NOT_INIT;
	}
	if (!host || !*host) {
		
		nd_logerror("open net error aim address is NULL\n") ;
		return NDSYS_ERR_INVALID_INPUT;
	}
	RESULT_T res = apoCli->Open(host, port);
	nd_logdebug("open net %s code = %d\n", res ? "success":"error", res) ;
	return  res ;
}
Example #3
0
bool NDInstanceBase::CheckReliableHost(ndip_t peerip) 
{
	ND_TRACE_FUNC();
	for(int i=0; i<m_config.reliable_num; i++) {
		if (0 == nd_sock_cmp_ip(m_config.reliable_hosts[i], peerip, m_config.reliable_ipmask[i])){
#ifdef ND_DEBUG
			char reliable_buf[20],peer_buf[20], mask_buf[20];
			nd_inet_ntoa(m_config.reliable_hosts[i], reliable_buf);
			nd_inet_ntoa(peerip, peer_buf);
			nd_inet_ntoa(m_config.reliable_ipmask[i], mask_buf);

			nd_logdebug("check ip success reliable=%s peer=%s mask=%s\n", reliable_buf, peer_buf, mask_buf);

#endif
			return true;
		}
	}
	return false ;
}
Example #4
0
//read udp socket data
int nd_udp_read(struct nd_udp_node*node , char *buf, size_t buf_size, ndtime_t outval) 
{

	int ret ;
	int readlen = 0;

	nd_assert(buf && buf_size>0);

	TCPNODE_READ_AGAIN(node) = 0;

	if(outval ) {
		ret = nd_socket_wait_read(node->fd, outval) ;
		if(ret <= 0) {
			node->myerrno = (ret == 0) ? NDERR_WOULD_BLOCK: NDERR_IO;
			return ret  ;
		}
	}

	readlen = nd_socket_udp_read(node->fd, buf, (int)buf_size, &node->last_read);

	if (-1 == readlen) {
		node->sys_error = nd_socket_last_error();
		if (node->sys_error == ESOCKETTIMEOUT) {
			node->myerrno = NDERR_WOULD_BLOCK;
			return 0;
		}
		else {
			node->myerrno = NDERR_READ;
			nd_logdebug("recvfrom : %s\n", nd_last_error());
			return -1;
		}
	}
	TCPNODE_READ_AGAIN(node) = 1;
	node->last_recv = nd_time();
	node->recv_len += readlen;

	return readlen ;
}