raindrops 0.17.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,173 +0,0 @@
1
- #if defined(__linux__) && defined(HAVE_LINUX_TCP_H)
2
- #include <ruby.h>
3
- #include <sys/socket.h>
4
- #include <netinet/in.h>
5
- #include <linux/tcp.h>
6
- #ifdef TCP_INFO
7
- #include "my_fileno.h"
8
-
9
- #define TCPI_ATTR_READER(x) \
10
- static VALUE tcp_info_##x(VALUE self) \
11
- { \
12
- struct tcp_info *info = DATA_PTR(self); \
13
- return UINT2NUM((uint32_t)info->tcpi_##x); \
14
- }
15
-
16
- TCPI_ATTR_READER(state)
17
- TCPI_ATTR_READER(ca_state)
18
- TCPI_ATTR_READER(retransmits)
19
- TCPI_ATTR_READER(probes)
20
- TCPI_ATTR_READER(backoff)
21
- TCPI_ATTR_READER(options)
22
- TCPI_ATTR_READER(snd_wscale)
23
- TCPI_ATTR_READER(rcv_wscale)
24
- TCPI_ATTR_READER(rto)
25
- TCPI_ATTR_READER(ato)
26
- TCPI_ATTR_READER(snd_mss)
27
- TCPI_ATTR_READER(rcv_mss)
28
- TCPI_ATTR_READER(unacked)
29
- TCPI_ATTR_READER(sacked)
30
- TCPI_ATTR_READER(lost)
31
- TCPI_ATTR_READER(retrans)
32
- TCPI_ATTR_READER(fackets)
33
- TCPI_ATTR_READER(last_data_sent)
34
- TCPI_ATTR_READER(last_ack_sent)
35
- TCPI_ATTR_READER(last_data_recv)
36
- TCPI_ATTR_READER(last_ack_recv)
37
- TCPI_ATTR_READER(pmtu)
38
- TCPI_ATTR_READER(rcv_ssthresh)
39
- TCPI_ATTR_READER(rtt)
40
- TCPI_ATTR_READER(rttvar)
41
- TCPI_ATTR_READER(snd_ssthresh)
42
- TCPI_ATTR_READER(snd_cwnd)
43
- TCPI_ATTR_READER(advmss)
44
- TCPI_ATTR_READER(reordering)
45
- TCPI_ATTR_READER(rcv_rtt)
46
- TCPI_ATTR_READER(rcv_space)
47
- TCPI_ATTR_READER(total_retrans)
48
-
49
- static VALUE alloc(VALUE klass)
50
- {
51
- struct tcp_info *info = xmalloc(sizeof(struct tcp_info));
52
-
53
- /* Data_Make_Struct has an extra memset 0 which is so wasteful */
54
- return Data_Wrap_Struct(klass, NULL, -1, info);
55
- }
56
-
57
- /*
58
- * call-seq:
59
- *
60
- * Raindrops::TCP_Info.new(tcp_socket) -> TCP_Info object
61
- *
62
- * Reads a TCP_Info object from any given +tcp_socket+. See the tcp(7)
63
- * manpage and /usr/include/linux/tcp.h for more details.
64
- */
65
- static VALUE init(VALUE self, VALUE io)
66
- {
67
- int fd = my_fileno(io);
68
- struct tcp_info *info = DATA_PTR(self);
69
- socklen_t len = (socklen_t)sizeof(struct tcp_info);
70
- int rc = getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &len);
71
-
72
- if (rc != 0)
73
- rb_sys_fail("getsockopt");
74
-
75
- return self;
76
- }
77
-
78
- void Init_raindrops_linux_tcp_info(void)
79
- {
80
- VALUE cRaindrops = rb_const_get(rb_cObject, rb_intern("Raindrops"));
81
- VALUE cTCP_Info;
82
-
83
- /*
84
- * Document-class: Raindrops::TCP_Info
85
- *
86
- * This is used to wrap "struct tcp_info" as described in tcp(7)
87
- * and /usr/include/linux/tcp.h. The following readers methods
88
- * are defined corresponding to the "tcpi_" fields in the
89
- * tcp_info struct.
90
- *
91
- * In particular, the +last_data_recv+ field is useful for measuring
92
- * the amount of time a client spent in the listen queue before
93
- * +accept()+, but only if +TCP_DEFER_ACCEPT+ is used with the
94
- * listen socket (it is on by default in Unicorn).
95
- *
96
- * - state
97
- * - ca_state
98
- * - retransmits
99
- * - probes
100
- * - backoff
101
- * - options
102
- * - snd_wscale
103
- * - rcv_wscale
104
- * - rto
105
- * - ato
106
- * - snd_mss
107
- * - rcv_mss
108
- * - unacked
109
- * - sacked
110
- * - lost
111
- * - retrans
112
- * - fackets
113
- * - last_data_sent
114
- * - last_ack_sent
115
- * - last_data_recv
116
- * - last_ack_recv
117
- * - pmtu
118
- * - rcv_ssthresh
119
- * - rtt
120
- * - rttvar
121
- * - snd_ssthresh
122
- * - snd_cwnd
123
- * - advmss
124
- * - reordering
125
- * - rcv_rtt
126
- * - rcv_space
127
- * - total_retrans
128
- *
129
- * https://kernel.org/doc/man-pages/online/pages/man7/tcp.7.html
130
- */
131
- cTCP_Info = rb_define_class_under(cRaindrops, "TCP_Info", rb_cObject);
132
- rb_define_alloc_func(cTCP_Info, alloc);
133
- rb_define_private_method(cTCP_Info, "initialize", init, 1);
134
- rb_define_method(cTCP_Info, "get!", init, 1);
135
-
136
- #define TCPI_DEFINE_METHOD(x) \
137
- rb_define_method(cTCP_Info, #x, tcp_info_##x, 0)
138
-
139
- TCPI_DEFINE_METHOD(state);
140
- TCPI_DEFINE_METHOD(ca_state);
141
- TCPI_DEFINE_METHOD(retransmits);
142
- TCPI_DEFINE_METHOD(probes);
143
- TCPI_DEFINE_METHOD(backoff);
144
- TCPI_DEFINE_METHOD(options);
145
- TCPI_DEFINE_METHOD(snd_wscale);
146
- TCPI_DEFINE_METHOD(rcv_wscale);
147
- TCPI_DEFINE_METHOD(rto);
148
- TCPI_DEFINE_METHOD(ato);
149
- TCPI_DEFINE_METHOD(snd_mss);
150
- TCPI_DEFINE_METHOD(rcv_mss);
151
- TCPI_DEFINE_METHOD(unacked);
152
- TCPI_DEFINE_METHOD(sacked);
153
- TCPI_DEFINE_METHOD(lost);
154
- TCPI_DEFINE_METHOD(retrans);
155
- TCPI_DEFINE_METHOD(fackets);
156
- TCPI_DEFINE_METHOD(last_data_sent);
157
- TCPI_DEFINE_METHOD(last_ack_sent);
158
- TCPI_DEFINE_METHOD(last_data_recv);
159
- TCPI_DEFINE_METHOD(last_ack_recv);
160
- TCPI_DEFINE_METHOD(pmtu);
161
- TCPI_DEFINE_METHOD(rcv_ssthresh);
162
- TCPI_DEFINE_METHOD(rtt);
163
- TCPI_DEFINE_METHOD(rttvar);
164
- TCPI_DEFINE_METHOD(snd_ssthresh);
165
- TCPI_DEFINE_METHOD(snd_cwnd);
166
- TCPI_DEFINE_METHOD(advmss);
167
- TCPI_DEFINE_METHOD(reordering);
168
- TCPI_DEFINE_METHOD(rcv_rtt);
169
- TCPI_DEFINE_METHOD(rcv_space);
170
- TCPI_DEFINE_METHOD(total_retrans);
171
- }
172
- #endif /* TCP_INFO */
173
- #endif /* defined(__linux__) && defined(HAVE_LINUX_TCP_H) */