/* setvbuf example */ #include <stdio.h> char sBuf[1024]; int main () { FILE *pFile; pFile=fopen ("myfile.txt","w"); setvbuf ( pFile , sBuf, _IOFBF , 1024 ); // File operations here fclose (pFile); return 0; } 在这个例子中,每次写1024字节,所以只有缓冲区满了(有1024字节),才往文件写入数据,可以减少IO次数
~/gcyin/study/php/test/discuz/webbench-1.5/webbench.c:
f=fdopen(mypipe[0],"r");
if(f==NULL)
{
perror("open pipe for reading failed.");
return 3;
}
setvbuf(f,NULL,_IONBF,0);
http://baike.baidu.com/view/906700.htm?fr=aladdin
http://blog.csdn.net/realduke2000/article/details/1812126
static const struct option long_options[]= { {"force",no_argument,&force,1}, {"reload",no_argument,&force_reload,1}, {"time",required_argument,NULL,‘t‘}, {"help",no_argument,NULL,‘?‘}, {"http09",no_argument,NULL,‘9‘}, {"http10",no_argument,NULL,‘1‘}, {"http11",no_argument,NULL,‘2‘}, {"get",no_argument,&method,METHOD_GET}, {"head",no_argument,&method,METHOD_HEAD}, {"options",no_argument,&method,METHOD_OPTIONS}, {"trace",no_argument,&method,METHOD_TRACE}, {"version",no_argument,NULL,‘V‘}, {"proxy",required_argument,NULL,‘p‘}, {"clients",required_argument,NULL,‘c‘}, {NULL,0,NULL,0} }; static void usage(void) { fprintf(stderr, "webbench [option]... URL\n" " -f|--force Don‘t wait for reply from server.\n" " -r|--reload Send reload request - Pragma: no-cache.\n" " -t|--time <sec> Run benchmark for <sec> seconds. Default 30.\n" " -p|--proxy <server:port> Use proxy server for request.\n" " -c|--clients <n> Run <n> HTTP clients at once. Default one.\n" " -9|--http09 Use HTTP/0.9 style requests.\n" " -1|--http10 Use HTTP/1.0 protocol.\n" " -2|--http11 Use HTTP/1.1 protocol.\n" " --get Use GET request method.\n" " --head Use HEAD request method.\n" " --options Use OPTIONS request method.\n" " --trace Use TRACE request method.\n" " -?|-h|--help This information.\n" " -V|--version Display program version.\n" ); }; int main(int argc, char *argv[]) { int opt=0; int options_index=0; char *tmp=NULL; if(argc==1) { usage(); return 2; } while((opt=getopt_long(argc,argv,"912Vfrt:p:c:?h",long_options,&options_index))!=EOF ) { switch(opt) { case 0 : break; case ‘f‘: force=1;break; case ‘r‘: force_reload=1;break; case ‘9‘: http10=0;break; case ‘1‘: http10=1;break; case ‘2‘: http10=2;break; case ‘V‘: printf(PROGRAM_VERSION"\n");exit(0); case ‘t‘: benchtime=atoi(optarg);break; case ‘p‘: /* proxy server parsing server:port */ tmp=strrchr(optarg,‘:‘); proxyhost=optarg; if(tmp==NULL) { break; } if(tmp==optarg) { fprintf(stderr,"Error in option --proxy %s: Missing hostname.\n",optarg); return 2; } if(tmp==optarg+strlen(optarg)-1) { fprintf(stderr,"Error in option --proxy %s Port number is missing.\n",optarg); return 2; } *tmp=‘\0‘; proxyport=atoi(tmp+1);break; case ‘:‘: case ‘h‘: case ‘?‘: usage();return 2;break; case ‘c‘: clients=atoi(optarg);break; } } }
原文:http://www.cnblogs.com/jingzhishen/p/3995358.html