예제 #1
0
/*
@details
-# If the user specified an address and port
 -# disconnect the current listen port
 -# initialize listen port to new address and port
-# else print message of current port number of listen device
*/
int Trick::JSONVariableServer::restart() {

    int ret ;

    if ( user_port_requested ) {
        char hname[80];
        static struct sockaddr_in s_in;
        gethostname(hname, (size_t) 80);
        // Test to see if the restart address is on this machine.  If it is not, it's not an error, clear source address
        if ( strcmp( source_address.c_str(), hname )) {
            if (! inet_pton(AF_INET, source_address.c_str(), (struct in_addr *)&s_in.sin_addr.s_addr) ) {
                //printf("clearing source_address\n") ;
                source_address.clear() ;
            }
        }

        printf("JSON variable server restart user_port requested set %d\n", port) ;

        tc_disconnect(&listen_dev) ;
        ret = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, source_address.c_str(), port) ;
        if (ret != TC_SUCCESS) {
            message_publish(MSG_ERROR, "ERROR: Could not establish listen port %d for JSON Variable Server. Aborting.\n", port);
            return (-1);
        }
    } else {
        struct sockaddr_in s_in;
        int s_in_size =  sizeof(s_in) ;
        getsockname( listen_dev.socket , (struct sockaddr *)&s_in, (socklen_t *)&s_in_size) ;
        printf("restart JSON variable server message port = %d\n" , ntohs(s_in.sin_port)) ;
        port = listen_dev.port = ntohs(s_in.sin_port);
    }

    return 0 ;
}
int Trick::VariableServerThread::create_udp_socket(const char * address, unsigned short in_port) {
    listen_dev = &connection ;
    tc_init_with_connection_info(&connection, AF_INET, SOCK_DGRAM, address, in_port) ;
    message_publish(MSG_INFO, "Created udp variable server %s:%d\n", listen_dev->hostname, listen_dev->port) ;
    tc_blockio( &connection , TC_COMM_NOBLOCKIO ) ;
    conn_type = UDP ;
    return 0 ;
}
예제 #3
0
/*
@details
-# If the source address or port number does not match the current listen device
 -# disconnect current listen device
 -# initialize listen device with new source address and port
*/
int Trick::JSONVariableServer::check_and_move_listen_device() {
    int ret ;

    if ( source_address.compare(listen_dev.hostname) or port != listen_dev.port ) {
        /* The user has requested a different source address or port in the input file */
        tc_disconnect(&listen_dev) ;
        ret = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, source_address.c_str(), port) ;
        if (ret != TC_SUCCESS) {
            message_publish(MSG_ERROR, "ERROR: Could not establish variable server source_address %s: port %d. Aborting.\n",
             source_address.c_str(), port);
            return -1 ;
        }
    }
    return 0 ;
}
예제 #4
0
/*
@details
-# If the user specified an address and port
 -# disconnect the current listen port
 -# initialize listen port to new address and port
-# else print message of current port number of listen device
*/
int Trick::JSONVariableServer::restart() {

    int ret ;

    if ( user_port_requested ) {
        printf("user_port_requested set %d", port) ;
        tc_disconnect(&listen_dev) ;
        ret = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, source_address.c_str(), port) ;
        if (ret != TC_SUCCESS) {
            message_publish(MSG_ERROR, "ERROR: Could not establish listen port %d for Variable Server. Aborting.\n", port);
            return (-1);
        }
    } else {
        struct sockaddr_in s_in;
        int s_in_size =  sizeof(s_in) ;
        getsockname( listen_dev.socket , (struct sockaddr *)&s_in, (socklen_t *)&s_in_size) ;
        printf("restart JSON variable server message port = %d\n" , ntohs(s_in.sin_port)) ;
        port = listen_dev.port = ntohs(s_in.sin_port);
    }

    return 0 ;
}