ライブラリの使用例題
使用例題として,登録済みの伝送カード(伝送カード名:CARD1〜3)を使用して,非同期の伝送要求の登録と,終了結果の取得をするサンプルプログラムを次に示します。
|
/********************************************************************/ /* Sample program: program to register an asynchronous transmission */ /* request and obtain the transmission termination flags */ /* (This example uses a registered card) */ /********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <apihead.h> #define CARD1 "card1" #define CARD2 "card2" #define CARD3 "card3" #define FTS_EXECUTION 0 #define FTS_SUCCESS 1 #define FTS_FAILURE 2 #define FTS_MAX_RETRY 3 int main() { FTS_FTP_API_CONN_DATA api_conn_data; /* Connect information structure */ FTS_FTP_API_DATA_EX data1, data2, data3; /* Transmission information structure */ FTS_FTP_API_RETDATA_EX ret_data; /* End of transmission information structure */ int sock; unsigned long trno1, trno2, trno3; int flag1, flag2, flag3; int i; flag1 = FTS_EXECUTION; flag2 = FTS_EXECUTION; flag3 = FTS_EXECUTION; for( i = 0; i <= FTS_MAX_RETRY; i++ ) { if( i == 0 ) { printf( "Transmission is executed. \n" ); } else { printf( "Transmission is executed again.\n" ); } memset( &data1, 0, sizeof(FTS_FTP_API_DATA_EX) ); memset( &data2, 0, sizeof(FTS_FTP_API_DATA_EX) ); memset( &data3, 0, sizeof(FTS_FTP_API_DATA_EX) ); /**************************************************/ /* Establish a connection with JP1/FTP */ /**************************************************/ memset( &api_conn_data, 0, sizeof( api_conn_data ) ); api_conn_data.priority = FTS_AF_INET; sock = fts_ftp_open_ex( &api_conn_data ); if( sock == INVALID_SOCKET ) { /* Error */ printf( "fts_ftp_open_ex() error!! error number = %ld\n", fts_errno ); exit(1); } /*************************************/ /* Register the transmission request */ /*************************************/ if( flag1 == FTS_EXECUTION ) { if( !fts_ftp_asyn_request_ex( sock, CARD1, &data1, &trno1, FTS_GET_RETURN ) ) { /* Error */ printf( "fts_ftp_request_ex(1) error!! error number = %ld\n", fts_errno ); } } if( flag2 == FTS_EXECUTION ) { if( !fts_ftp_asyn_request_ex( sock, CARD2, &data2, &trno2, FTS_GET_RETURN ) ) { /* Error */ printf( "fts_ftp_request_ex(2) error!! error number = %ld\n", fts_errno ); } } if( flag3 == FTS_EXECUTION ) { if( !fts_ftp_asyn_request_ex( sock, CARD3, &data3, &trno3, FTS_GET_RETURN ) ) { /* Error */ printf( "fts_ftp_request_ex(3) error!! error number = %ld\n", fts_errno ); } } /*********************************************/ /* Obtain the transmission termination flags */ /*********************************************/ while(1) { if( !fts_ftp_event_ex( sock, &ret_data ) ) { if( fts_errno == FTS_API_ERROR_NODATA ) { /* Obtained all the transmission termination flags */ break; } else { /* Error */ printf( "fts_ftp_event_ex error!! error number = %ld\n", fts_errno ); fts_ftp_close( sock ); exit(1); } } if( flag1 == FTS_EXECUTION ) { if( ret_data.trno == trno1 ) { /* Termination of CARD1 */ if( ret_data.trans_status == TRANS_SUCCESS ) { /* Transmission ends normally. */ printf( "CARD1 trnas success!!\n" ); flag1 = FTS_SUCCESS; } else { /* Transmission ends abnormally. */ printf( "CARD1 trnas failure!!\n" ); } continue; } } if( flag2 == FTS_EXECUTION ) { if( ret_data.trno == trno2 ) { /* Termination of CARD2 */ if( ret_data.trans_status == TRANS_SUCCESS ) { /* Transmission ends normally. */ printf( "CARD2 trnas success!!\n" ); flag2 = FTS_SUCCESS; } else { /* Transmission ends abnormally. */ printf( "CARD2 trnas failure!!\n" ); } continue; } } if( flag3 == FTS_EXECUTION ) { if( ret_data.trno == trno3 ) { /* Termination of CARD3 */ if( ret_data.trans_status == TRANS_SUCCESS ) { /* Transmission ends normally. */ printf( "CARD3 trnas success!!\n" ); flag3 = FTS_SUCCESS; } else { /* Transmission ends abnormally. */ printf( "CARD3 trnas failure!!\n" ); } continue; } } } /***************************************/ /* Release the connection with JP1/FTP */ /***************************************/ fts_ftp_close( sock ); if( flag1 == FTS_SUCCESS && flag2 == FTS_SUCCESS && flag3 == FTS_SUCCESS ) { break; } } printf( "Transmission is ended. \n" ); exit(0); }