int Trick::VariableServerThread::transmit_file(std::string sie_file) {
    const unsigned int packet_size = 4095 ;
    FILE * fp ;
    unsigned int file_size ;
    unsigned int current_size = 0 ;
    unsigned int bytes_read ;
    char buffer[packet_size] ;
    int ret ;

    if (debug >= 2) {
        message_publish(MSG_DEBUG,"%p tag=<%s> var_server opening %s.\n", &connection, connection.client_tag, sie_file.c_str()) ;
    }

    if ((fp = fopen(sie_file.c_str() , "r")) == NULL ) {
        message_publish(MSG_ERROR,"Variable Server Error: Cannot open %s.\n", sie_file.c_str()) ;
        sprintf(buffer, "%d\t-1\n", VS_SIE_RESOURCE) ;
        tc_write(&connection , buffer , strlen(buffer)) ;
        return(-1) ;
    }

    fseek(fp , 0L, SEEK_END) ;
    file_size = ftell(fp) ;

    sprintf(buffer, "%d\t%d\n" , VS_SIE_RESOURCE, file_size) ;
    tc_write(&connection , buffer , strlen(buffer)) ;
    rewind(fp) ;

    // Switch to blocking writes since this could be a large transfer.
    if (tc_blockio(&connection, TC_COMM_BLOCKIO)) {
        message_publish(MSG_DEBUG,"Variable Server Error: Failed to set TCDevice to TC_COMM_BLOCKIO.\n");
    }

    while ( current_size < file_size ) {
        bytes_read = fread(buffer , 1 , packet_size , fp) ;
        ret = tc_write(&connection , buffer , bytes_read ) ;
        if (ret != (int)bytes_read) {
            message_publish(MSG_ERROR,"Variable Server Error: Failed to send SIE file.\n", sie_file.c_str()) ;
            return(-1);
        }
        current_size += bytes_read ;
    }

    // Switch back to non-blocking writes.
    if (tc_blockio(&connection, TC_COMM_NOBLOCKIO)) {
        message_publish(MSG_ERROR,"Variable Server Error: Failed to set TCDevice to TC_COMM_NOBLOCKIO.\n");
        return(-1);
    }

    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
TEST_F( TCBlockioTest, testTC_COMM_ALL_OR_NOTHING ) {

   (void) tc_blockio( device, TC_COMM_ALL_OR_NOTHING );
   EXPECT_EQ( TC_COMM_ALL_OR_NOTHING, device->blockio_type );
} 
예제 #4
0
TEST_F( TCBlockioTest, testTC_COMM_TIMED_BLOCKIO ) {

   (void) tc_blockio( device, TC_COMM_TIMED_BLOCKIO );
   EXPECT_EQ( TC_COMM_TIMED_BLOCKIO, device->blockio_type );
} 
예제 #5
0
TEST_F( TCBlockioTest, testNullDevice ) {

   int blockio_status = tc_blockio( NULL, TC_COMM_ALL_OR_NOTHING );

   EXPECT_EQ( TC_EWOULDBLOCK, blockio_status );
}