Mercurial > hg > nginx-tests
annotate stream_tcp_nodelay.t @ 711:824754da4afc
Tests: adjusted socket read timeout in stream tests.
Read timeout was increased to prevent situation when data is delayed with
more than 3 seconds. In this case, part of the response could be cut off.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 23 Sep 2015 18:29:34 +0300 |
parents | 555e718a70a5 |
children | acec03d44976 |
rev | line source |
---|---|
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Sergey Kandaurov |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Stream tests for tcp_nodelay. |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 use IO::Select; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use lib 'lib'; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream/); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 plan(skip_all => 'no tcp_nodelay') unless $t->has_version('1.9.4'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 $t->plan(2)->write_file_expand('nginx.conf', <<'EOF'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 daemon off; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 events { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 stream { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 proxy_buffer_size 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 tcp_nodelay off; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8081; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_pass 127.0.0.1:8080; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 server { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 tcp_nodelay on; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8082; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass 127.0.0.1:8080; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 EOF |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 $t->run_daemon(\&stream_daemon); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 $t->run()->waitforsocket('127.0.0.1:8080'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 my $str = '1234567890' x 10; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 is(stream_get($str, '127.0.0.1:8081'), $str, 'tcp_nodelay off'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 is(stream_get($str, '127.0.0.1:8082'), $str, 'tcp_nodelay on'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 sub stream_get { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my ($data, $peer) = @_; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 my $data_length = length $data; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 my $s = stream_connect($peer); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 stream_write($s, $data); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 $data = ''; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 while (length $data < $data_length) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 my $buf = stream_read($s); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 $data .= $buf; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 return $data; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 sub stream_connect { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 my $peer = shift; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 my $s = IO::Socket::INET->new( |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 Proto => 'tcp', |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 PeerAddr => $peer || '127.0.0.1:8080' |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 ) |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 or die "Can't connect to nginx: $!\n"; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 return $s; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 sub stream_write { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my ($s, $message) = @_; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 local $SIG{PIPE} = 'IGNORE'; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 $s->blocking(0); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 while (IO::Select->new($s)->can_write(1.5)) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 my $n = $s->syswrite($message); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 last unless $n; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 $message = substr($message, $n); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 last unless length $message; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 if (length $message) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $s->close(); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 sub stream_read { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 my ($s) = @_; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 my ($buf); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 $s->blocking(0); |
711
824754da4afc
Tests: adjusted socket read timeout in stream tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
642
diff
changeset
|
120 if (IO::Select->new($s)->can_read(5)) { |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 $s->sysread($buf, 1024); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 }; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 log_in($buf); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 return $buf; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 sub stream_daemon { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 my $server = IO::Socket::INET->new( |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 Proto => 'tcp', |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 LocalAddr => '127.0.0.1:8080', |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 Listen => 5, |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 Reuse => 1 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 ) |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 or die "Can't create listening socket: $!\n"; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 my $sel = IO::Select->new($server); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 local $SIG{PIPE} = 'IGNORE'; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 while (my @ready = $sel->can_read) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 foreach my $fh (@ready) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 if ($server == $fh) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 my $new = $fh->accept; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 $new->autoflush(1); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 $sel->add($new); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 } elsif (stream_handle_client($fh)) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $sel->remove($fh); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $fh->close; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 sub stream_handle_client { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 my ($client) = @_; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 log2c("(new connection $client)"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $client->sysread(my $buffer, 65536) or return 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 log2i("$client $buffer"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 log2o("$client $buffer"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 $client->syswrite($buffer); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 return 0; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 sub log2c { Test::Nginx::log_core('||', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 ############################################################################### |