千兆网路极限速度能有多少
你检查一下是不是整数溢出了,3M * 10000 \u0026gt; 2^32。if(now \u0026gt; seconds+1){ seconds = now;
看了你的代码,你的计时写错了,你测量的是每两秒钟的数据量,当作每秒数据量来显示了。
■网友
#include\u0026lt;sys/types.h\u0026gt;#include\u0026lt;sys/socket.h\u0026gt;#include\u0026lt;netinet/in.h\u0026gt;#include\u0026lt;arpa/inet.h\u0026gt;#include\u0026lt;unistd.h\u0026gt;#include \u0026lt;stdio.h\u0026gt;#include \u0026lt;stdlib.h\u0026gt;#include \u0026lt;strings.h\u0026gt;#include\u0026lt;sys/wait.h\u0026gt;#include \u0026lt;string.h\u0026gt;#include \u0026lt;sys/select.h\u0026gt; // for select #include \u0026lt;time.h\u0026gt;/********************************************************************* *filename: tcpserver.c *purpose:tcp·t????3ìDò ********************************************************************/int main(int argc, char ** argv) { int sockfd,new_fd;/* ?àìysocket: sock_fd,êy?Y??ê?socket: new_fd */ struct sockaddr_in my_addr; /* ±??úμ??·D??¢ */ struct sockaddr_in their_addr; /* ?í?§μ??·D??¢ */ unsigned int sin_size, myport, lisnum; struct timeval select_time={0,1000}; int snd_size = 0; int rcv_size = 0; socklen_t optlen; time_t seconds,now; fd_set readset; fd_set writeset; fd_set exceptset; int maxfd=-1; FD_ZERO(\u0026amp;readset); FD_ZERO(\u0026amp;writeset); FD_ZERO(\u0026amp;exceptset); if(argv) myport = atoi(argv); else myport = 8800; if(argv) lisnum = atoi(argv); else lisnum = 2; if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } optlen = sizeof(rcv_size); int err = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,\u0026amp;rcv_size, \u0026amp;optlen); if(err\u0026lt;0){ printf("err\"); } printf(" RCV_SIZE: %d Byte\",rcv_size); rcv_size = 64*1024; err = setsockopt(sockfd,SOL_SOCKET,SO_RCVBUF, (char *)\u0026amp;rcv_size, optlen); if(err\u0026lt;0){ printf("err\"); } printf("socket %d ok \",myport); my_addr.sin_family=PF_INET; my_addr.sin_port=htons(myport); my_addr.sin_addr.s_addr = INADDR_ANY; bzero(\u0026amp;(my_addr.sin_zero), 0); if (bind(sockfd, (struct sockaddr *)\u0026amp;my_addr, sizeof(struct sockaddr)) == -1) { perror("bind"); exit(1); } printf("bind ok \"); if (listen(sockfd, lisnum) == -1) { perror("listen"); exit(1); } printf("listen ok \"); /* while(1) { sin_size = sizeof(struct sockaddr_in); if ((new_fd = accept(sockfd, (struct sockaddr *)\u0026amp;their_addr, \u0026amp;sin_size)) == -1) { perror("accept"); continue; } printf("server: got connection from %s\",inet_ntoa(their_addr.sin_addr)); if (!fork()) { //×ó??3ì?ú???? if (send(new_fd, "Hello, world!\", 14, 0) == -1) { perror("send"); close(new_fd); exit(0); } } close(new_fd); //????3ì2??ùDèòa??socket waitpid(-1,NULL,WNOHANG);//μè?y×ó??3ì?áê?£???3y×ó??3ì?ù??ó?×ê?? } */ sin_size = sizeof(struct sockaddr_in); if ((new_fd = accept(sockfd, (struct sockaddr *)\u0026amp;their_addr, \u0026amp;sin_size)) == -1) { perror("accept"); exit(0); } printf("server: got connection from %s\",inet_ntoa(their_addr.sin_addr)); maxfd=new_fd+1; int step = 0; char rec_buff; char send_buff; for(step=14999;step\u0026gt;=0;step--) send_buff=\u0026#39;0\u0026#39;; int sent_time=0; seconds = time((time_t *)NULL); int rec_byte = 0; while(1) { char szSnd = {0}; char senddata; int datalen=0; FD_ZERO(\u0026amp;readset); FD_ZERO(\u0026amp;writeset); FD_ZERO(\u0026amp;exceptset); FD_SET(new_fd,\u0026amp;readset); FD_SET(new_fd,\u0026amp;writeset); FD_SET(new_fd,\u0026amp;exceptset); FD_SET(0,\u0026amp;readset); now = time((time_t *)NULL); switch(select(maxfd,\u0026amp;readset,\u0026amp;writeset,\u0026amp;exceptset,\u0026amp;select_time)) { case -1: exit(0); case 0: break; default: if(FD_ISSET(new_fd,\u0026amp;exceptset)) { perror("Except error:"); close(new_fd); break; }\tif(FD_ISSET(0,\u0026amp;readset))\t{\t datalen=read(0,senddata,20);\t senddata = https://www.zhihu.com/u0026#39;//0/u0026#39;;/t} if(FD_ISSET(new_fd,/u0026amp;writeset)) {
推荐阅读
- 戒烟|一天内抽多少支烟,是人体能承受的极限?医生给个数,要心里有底
- 谈车工坊|在“中国之最”赛道挑战双擎混动的性能极限
- |老烟枪注意:每天抽多少根烟,就是肺的极限了?抽几根最合适?
- 请问计算器求积分,求导,求极限怎样实现
- 移动通信发展下去会到极限么当传输信息越来越大需要带宽越来越大以后咋办顺便求说说以后的发展趋势
- 续航|宝路达《探路中国第二季》—“云端天路极限挑战”拉开帷幕
- 熬夜|经常熬夜的人,身体若出现这3种变化,恐是身体已达到极限
- 有那些好的网站可以观看极限运动的视频
- 续航|真实续航惊人 皓影/奥德赛极限挑战1000公里
- 车毂辘|躁梦无极限“广汽本田的造梦之旅