zoukankan      html  css  js  c++  java
  • 打印输出tcp拥塞窗口

    打印输出tcp拥塞窗口

    在内核的函数tcp_getsockopt的代码中,可以看到这个选项TCP_INFO,返回了几乎所有的参数,同时还有其他的许多参数可以得到一些其他的信息。具体每个参数的含义可以参考内核中的注释。

    示例

    #include <string>
    #include <string.h>
    #include <cstdlib>
    #include <ctime>
    #include <unistd.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/tcp.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <unistd.h>
    #include <sys/time.h>
    #include <linux/ip.h>

    void read_cwnd(int tcp_socket)
    {
        struct tcp_info info;
        int length = sizeof(struct tcp_info);
       
        if (getsockopt( tcp_socket, IPPROTO_TCP, TCP_INFO, (void *)&info, (socklen_t *)&length ) == 0 )
        {
           printf("%u %u %u %u %u %u %u %u %u %u %u %u\n",
                info.tcpi_snd_cwnd,
                info.tcpi_snd_ssthresh,
                info.tcpi_rcv_ssthresh,
                info.tcpi_rtt,
                info.tcpi_rttvar,
                info.tcpi_unacked,
                info.tcpi_sacked,
                info.tcpi_lost,
                info.tcpi_retrans,
                info.tcpi_fackets,
                info.tcpi_ca_state,
                info.tcpi_reordering
               );  
       } 
    }

    int main()
    {
        sockaddr_in in;
        memset(&in,'\0',sizeof(in));
        in.sin_family=AF_INET;
        in.sin_port=htons(8888);
        in.sin_addr.s_addr=INADDR_ANY;
       
        int reuse0=1;
        int serv=socket(AF_INET, SOCK_STREAM, 0);
       
        read_cwnd(serv);
        return 1;
    }

    原文

    http://www.cnblogs.com/fll/archive/2009/03/20/1418091.html

  • 相关阅读:
    特效优化
    Jsp
    JRebel 热部署
    mysql
    行为树
    Medium | LeetCode 139. 单词拆分 | 动态规划
    Medium | LeetCode 31. 下一个排列
    Easy | LeetCode 27. 移除元素 | 快慢指针
    Medium | LeetCode 437. 路径总和 III | 树 + 回溯 + 前缀和
    Medium | LeetCode 337. 打家劫舍 III | 树后序遍历 + 动态规划
  • 原文地址:https://www.cnblogs.com/mydomain/p/3027664.html
Copyright © 2011-2022 走看看