源码分析共享地址:https://github.com/fivezh/WebBenchhtml
下载源码后编译源程序后便可执行:node
sudo make cleanlinux
sudo make & make installgit
five@master:~/github/OpenCCode/WebBench$ ./webbench webbench [option]... URL -f|--force Don't wait for reply from server. -r|--reload Send reload request - Pragma: no-cache. -t|--time <sec> Run benchmark for <sec> seconds. Default 30. -p|--proxy <server:port> Use proxy server for request. -c|--clients <n> Run <n> HTTP clients at once. Default one. -9|--http09 Use HTTP/0.9 style requests. -1|--http10 Use HTTP/1.0 protocol. -2|--http11 Use HTTP/1.1 protocol. --get Use GET request method. --head Use HEAD request method. --options Use OPTIONS request method. --trace Use TRACE request method. -?|-h|--help This information. -V|--version Display program version.
实例:./webbench -t 10 -c 50 http://www.baidu.com/github
five@master:~/github/OpenCCode/WebBench$ ./webbench -t 10 -c 50 http://www.baidu.com/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://www.baidu.com/ 50 clients, running 10 sec. Speed=492 pages/min, 918494 bytes/sec. Requests: 82 susceed, 0 failed.
volatile用法总结:(不但愿编译器优化、多任务程序可能随时更改、设计硬件寄存器时)web
volatile的使用的场合大体有如下几点:app
一、中断服务程序中修改的供其它程序检测的变量须要加volatile;函数
二、多任务环境下各任务间共享的标志应该加volatile;源码分析
三、存储器映射的硬件寄存器一般也要加volatile说明,由于每次对它的读写均可能有不一样意义。post
参考:[1] C语言的那些小秘密之volatile [2] C中的volatile用法
两者都可用于判断是否已进行宏定义,区别之处在于后者更适用于多重判别条件的情形。
如: #if defined(UNIX) && !defined(AIX)
参考:[3] stackoverflow:difference-between-ifndef-and-if-defined-in-c
除getopt()提供的短选项(short options, 好比-s)解析外,还提供长选项(long options,好比--name)解析,参数原型为:
#include <unistd.h>
int getopt(int argc, char * const argv[],
const char *optstring);
extern char *optarg;
#include <getopt.h> int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex);
getopt_long() and getopt_long_only()
The getopt_long() function works like getopt() except that it also
accepts long options, started with two dashes. (If the program accepts
only long options, then optstring should be specified as an empty
string (""), not NULL.) Long option names may be abbreviated if the
abbreviation is unique or is an exact match for some defined option. A
long option may take a parameter, of the form --arg=param or --arg
param.
参考:[4] linux 中解析命令行参数 (getopt_long用法) [5]Wikipedia getopt() [6] IBM 使用 getopt() 进行命令行处理【推荐阅读】
注意:注意的是默认状况下getopt会从新排列命令行参数的顺序,因此到最后全部不包含选项的命令行参数都排到最后(参考)。
几个重要全局变量:
optarg:处理带输入参数的选项时,选项参数保存至char *optarg中。
optind:下一个处理的选项在argv中的地址,全部选项处理完后,optind指向未识别的项。
optopt:最后一个已知项。
问题1:该函数的实现是如何作的?
答:getopt()的GNU实现,getopt_long()的NetBSD实现 ,一种getopt_long()的简单实现。
问题2:当短参数做为输入时,该函数如何返回?
答:getopt_long()是同时支持长选项和短选项的getopt()实现。