WEB开发网
开发学院服务器FTP服务器 ProFTPD和WU-FTP的BANDWIDTH控制 阅读

ProFTPD和WU-FTP的BANDWIDTH控制

 2007-06-12 00:00:00 来源:WEB开发网   
核心提示: + /* record transfer start time */ + if(cur_rate > 0L) { + gettimeofday(&last_time, (struct timezone *) 0); + } + len □ta_xfer(lbuf,len); if(len

+ /* record transfer start time */ + if(cur_rate > 0L) { + gettimeofday(&last_time, (struct timezone *) 0); + } + len □ta_xfer(lbuf,len); if(len < 0) { _retr_abort(); @@ -450,6 +668,21 @@ log_add_run(mpid,NULL,session.user,NULL,0,session.xfer.file_ size,cnt,NULL); } } + + /* calculate spent time and set up timer */ + if((cur_rate > 0L) && (session.xfer.file_size > cur_rate)) { + gettimeofday(&now, (struct timezone *) 0); + timespent imediff(&now, &last_time); + timeout imediff(&opt_time, ×pent); + log_debug(DEBUG5, "bandwidth : Sleep : %ld/%ld (Op time : %ld /%ld Spent : %ld/%ld)", + timeout.tv_sec, timeout.tv_usec, opt_time.tv_sec, opt_time.tv_usec, + timespent.tv_sec, timespent.tv_usec); + /* We sleep... */ + sleep_msec(&timeout); + if(TimeoutIdle) + reset_timer(TIMER_IDLE,ANY_MODULE); + } + }

if(XFER_ABORTED) { @@ -519,6 +752,57 @@ return DECLINED(cmd); }

+MODRET set_bandwidth(cmd_rec *cmd) +{ + long s_cur_rate + + CHECK_ARGS(cmd,1); + CHECK_CONF(cmd,CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); + + s_cur_rate □oi(cmd->argv[1]); + + if(s_cur_rate < 0) + CONF_ERROR(cmd,"value must be lager then 0"); + + add_config_param_set(&cmd->server->conf,"Bandwidth",1,(void*)s_cur_ rate); + + return HANDLED(cmd); +} + +MODRET set_maximumbandwidth(cmd_rec *cmd) +{ + long s_cur_rate + + CHECK_ARGS(cmd,1); + CHECK_CONF(cmd,CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); + + s_cur_rate □oi(cmd->argv[1]); + + if(s_cur_rate < 0) + CONF_ERROR(cmd,"value must be lager then 0"); + + add_config_param_set(&cmd->server->conf,"MaxBandwidth",1,(void*)s_c ur_rate); + + return HANDLED(cmd); +} + +MODRET set_minimumbandwidth(cmd_rec *cmd) +{ + long s_cur_rate + + CHECK_ARGS(cmd,1); + CHECK_CONF(cmd,CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); + + s_cur_rate □oi(cmd->argv[1]); + + if(s_cur_rate < 0) + CONF_ERROR(cmd,"value must be lager then 0"); + + add_config_param_set(&cmd->server->conf,"MinBandwidth",1,(void*)s_c ur_rate); + + return HANDLED(cmd); +} + static int _noxfer_timeout(CALLBACK_FRAME) { if(session.flags & SF_XFER) @@ -542,6 +826,13 @@ return 0; }

+static conftable xfer_config[] + { "BandWidth", set_bandwidth, NULL } , + { "MaxBandWidth", set_maximumbandwidth, NULL } , + { "MinBandWidth", set_minimumbandwidth, NULL } , + { NULL, NULL, NULL }

+}; + cmdtable xfer_commands[] { CMD, C_TYPE, G_NONE, cmd_type, TRUE, FALSE, CL_MISC }, { PRE_CMD, C_RETR, G_READ, pre_cmd_retr, TRUE, FALSE }, @@ -562,7 +853,7 @@ NULL,NULL, /* Always NULL */ 0x20, /* API Version */ "xfer", /* Module name */ - NULL, /* No config */ + xfer_config, /* Config name */ xfer_commands, NULL, NULL,xfer_init_child

--- end proftpd-1.2.0pre2-bandwidth.patch ---

上一页  1 2 3 4 5 6 

Tags:ProFTPD WU FTP

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接