/* kechosvr.c * エコーバックのサーバ */ #define USAGE "Usage: kechosvr " #define D 1 #include "mysvr_stab.h" #include "apr_strings.h" int my_service_init ( int ac , char **av , my_server_info *svr_info ) { if (ac < 3) { apr_file_printf(svr_info->err, "%s\n", USAGE); return 0; } svr_info->hostname = av[1]; if (!strcmp(svr_info->hostname, "NULL")) { svr_info->hostname = NULL; } if ((svr_info->port = atoi(av[2])) <= 0) { apr_file_printf(svr_info->err, "ERROR: port_num=[%s]\n", av[1]); return 0; } svr_info->timeout_sec = 10; /* 10秒でタイムアウト */ return 1; } void my_service_finally ( int error_flag , my_server_info *svr_info ) { if(D)apr_file_printf(svr_info->out, "error_flag=[%d]\n", error_flag); } int my_service_main( apr_pool_t *pool , apr_socket_t *socket , my_server_info *svr_info ) { apr_status_t rv = APR_SUCCESS; while (socket) { char buf[1024]; apr_size_t len = 1024; if(D)apr_file_printf(svr_info->out, "#wait.\n"); rv = apr_socket_recv(socket, buf, &len); if (rv != APR_SUCCESS) { break; } if(D)apr_file_printf(svr_info->out, "#received:[%s]\n", apr_pmemdup(pool, buf, len)); rv = apr_socket_send(socket, buf, &len); if (rv != APR_SUCCESS) { break; } } if(D)apr_file_printf(svr_info->out, "#end.\n"); return 1; }