示例#1
0
int HttpConnector::Create(const char *host, int port)
{
	if (m_conn) {
		nd_object_destroy(m_conn, 0) ;
		//DestroyConnectorObj(m_conn) ;
		m_conn = 0 ;
	}
	
	m_conn = nd_object_create("tcp-connector"  ) ;
	
	if(!m_conn){
		nd_logerror((char*)"connect error :%s!" , nd_last_error()) ;
		return -1;
	}
	((nd_netui_handle)m_conn)->user_data =(void*) this ;
	
	int ret = nd_connector_open(m_conn,host, port, NULL);
	
	if(ret == 0 ) {
		m_host = host ;
		m_port = port ;
	}
	else {
		nd_object_destroy(m_conn, 0) ;
		m_conn = 0 ;
		return -1;
	}
	
	return 0 ;
	
}
示例#2
0
netObject ndOpenConnect(const char *host, int port)
{
    nd_handle handle = 0 ;
    
    ndInitNet() ;
    
    handle = nd_object_create("tcp-connector"  ) ;
    
    if(!handle){
        nd_logerror((char*)"connect error :%s!" AND nd_last_error()) ;
        return NULL;
    }
    if(-1==nd_msgtable_open(handle, 16) ) {
        nd_object_destroy(handle, 0) ;
        return NULL ;
    }
	
    //open
    if(-1==nd_connector_open( handle, (char*)host,  port,NULL ) ){
        nd_logerror("connect error :%s!" AND nd_last_error()) ;
        nd_object_destroy(handle,1) ;
        return NULL;
    }
    
    nd_hook_packet((netObject) handle,(net_msg_entry )_translate_message);
    ndMsgfuncInit( (netObject) handle ) ;

    return (netObject) handle;
}
示例#3
0
void ProxySession::Shutdown() 
{
	Close(0) ;
	nd_object_destroy(m_remote_handle,0) ;
	m_remote_handle = NULL;
	//m_remote_connector.Close(0) ;
	//m_remote_connector.Destroy() ;
}
示例#4
0
int ProxySession::ConnectRemote(char *host, short port, int isudp) 
{
	int sock_len = sizeof(SOCKADDR_IN);
	m_is_udp = isudp;
	if (isudp) {
		m_remote_handle = nd_object_create("udp-node") ;
		if(!m_remote_handle)
			return -1 ;
		//bind 
		if (-1==nd_net_bind(0,0, m_remote_handle)) {
			nd_object_destroy(m_remote_handle,1) ;
			m_remote_handle = 0 ;
			return -1;
		}
		::getsockname(nd_connector_fd(GetSessionHandle()),(struct sockaddr *)&m_client_addr,(socklen_t*)&sock_len) ;
		m_client_addr.sin_port = htons(port) ;
		m_client_addr.sin_family = AF_INET ;

		sock_len = sizeof(SOCKADDR_IN);
		::getsockname(nd_connector_fd(m_remote_handle),(struct sockaddr *)&m_remote_addr,(socklen_t*)&sock_len) ;
		m_remote_addr.sin_addr.s_addr = m_client_addr.sin_addr.s_addr;
		m_remote_addr.sin_family = AF_INET ;
		//m_remote_addr.sin_port = htons()

	}
	else {
		m_remote_handle = nd_object_create("tcp-connector") ;
		if(!m_remote_handle)
			return -1 ;
		//bind 
		if (-1==nd_connector_open(m_remote_handle, host, port,NULL) ) {
			nd_object_destroy(m_remote_handle,1) ;
			m_remote_handle = 0 ;
			return -1;
		}
		::getsockname(nd_connector_fd(GetSessionHandle()),(struct sockaddr *)&m_client_addr,(socklen_t*)&sock_len) ;
		m_client_addr.sin_family = AF_INET ;

		sock_len = sizeof(SOCKADDR_IN);
		::getsockname(nd_connector_fd(m_remote_handle),(struct sockaddr *)&m_remote_addr,(socklen_t*)&sock_len) ;
		m_remote_addr.sin_family = AF_INET ;
	}

	return 0 ;
	
}
示例#5
0
void HttpConnector::Destroy()
{
	
	if (m_conn) {
		nd_object_destroy(m_conn, 0) ;
		//DestroyConnectorObj(m_conn) ;
		m_conn = 0 ;
	}

}