ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/80_ssltest.t
(Generate patch)

Comparing AnyEvent/t/80_ssltest.t (file contents):
Revision 1.5 by root, Sat Jul 18 00:05:29 2009 UTC vs.
Revision 1.6 by root, Fri Jul 24 22:47:04 2009 UTC

80 80
81 }, sub { 81 }, sub {
82 $server_port->send ($_[2]); 82 $server_port->send ($_[2]);
83 }; 83 };
84 84
85 my $hd; $hd = new AnyEvent::Handle
85 tcp_connect "localhost", $server_port->recv, sub { 86 connect => ["localhost", $server_port->recv],
86 my ($fh) = @_; 87 tls => "connect",
88 tls_ctx => $ctx,
89 timeout => 8,
90 on_connect => sub {
91 ok (1, "client_connect $mode");
92 },
93 on_error => sub {
94 ok (0, "client_error <$!>");
95 $client_done->send; undef $hd;
96 },
97 on_eof => sub {
98 ok (1, "client_eof");
99 $client_done->send; undef $hd;
100 };
87 101
88 ok (1, "client_connect $mode"); 102 if ($mode == 1) {
89 103 $hd->push_write ("1\n");
90 my $hd; $hd = new AnyEvent::Handle 104 $hd->on_drain (sub {
91 tls => "connect",
92 tls_ctx => $ctx,
93 fh => $fh,
94 timeout => 8,
95 on_error => sub {
96 ok (0, "client_error <$!>"); 105 ok (1, "client_drain");
97 $client_done->send; undef $hd; 106 $client_done->send; undef $hd;
98 },
99 on_eof => sub {
100 ok (1, "client_eof");
101 $client_done->send; undef $hd;
102 }; 107 });
103
104 if ($mode == 1) { 108 } elsif ($mode == 2) {
109 $hd->push_read (line => sub {
110 ok ($_[1] eq "2", "line 2 <$_[1]>");
111 });
112 } elsif ($mode == 3) {
113 $hd->push_write ("3\n");
114 $hd->push_read (line => sub {
115 ok ($_[1] eq "4", "line 4 <$_[1]>");
116 });
117 } elsif ($mode == 4) {
118 $hd->push_read (line => sub {
119 ok ($_[1] eq "5", "line 5 <$_[1]>");
105 $hd->push_write ("1\n"); 120 $hd->push_write ("6\n");
106 $hd->on_drain (sub { 121 $hd->on_drain (sub {
107 ok (1, "client_drain"); 122 ok (1, "client_drain");
108 $client_done->send; undef $hd; 123 $client_done->send; undef $hd;
109 }); 124 });
125 });
110 } elsif ($mode == 2) { 126 } elsif ($mode == 5) {
127 # some randomly-sized blocks
128 srand 0;
129 my $cnt = 64;
130 my $block; $block = sub {
131 my $len = (16 << int rand 14) - 16 + int rand 32;
132 ok (1, "write $len");
133 $hd->push_write ("$len\n");
134 $hd->push_write (packstring => "N", "\x00" x $len);
135 };
136
137 for my $i (1..$cnt) {
111 $hd->push_read (line => sub { 138 $hd->push_read (line => sub {
112 ok ($_[1] eq "2", "line 2 <$_[1]>"); 139 my $len = $_[1];
113 }); 140 ok (1, "client block $len/1");
114 } elsif ($mode == 3) {
115 $hd->push_write ("3\n");
116 $hd->push_read (line => sub { 141 $hd->unshift_read (packstring => "N", sub {
117 ok ($_[1] eq "4", "line 4 <$_[1]>"); 142 ok ($len == length $_[1], "client block $len/2");
118 }); 143
119 } elsif ($mode == 4) { 144 if ($i != $cnt) {
120 $hd->push_read (line => sub { 145 $block->();
121 ok ($_[1] eq "5", "line 5 <$_[1]>"); 146 } else {
122 $hd->push_write ("6\n");
123 $hd->on_drain (sub {
124 ok (1, "client_drain"); 147 ok (1, "client_drain");
125 $client_done->send; undef $hd; 148 $client_done->send; undef $hd;
149 }
126 }); 150 });
127 }); 151 });
128 } elsif ($mode == 5) {
129 # some randomly-sized blocks
130 srand 0;
131 my $cnt = 64;
132 my $block; $block = sub {
133 my $len = (16 << int rand 14) - 16 + int rand 32;
134 ok (1, "write $len");
135 $hd->push_write ("$len\n");
136 $hd->push_write (packstring => "N", "\x00" x $len);
137 }; 152 }
138 153
139 for my $i (1..$cnt) {
140 $hd->push_read (line => sub {
141 my $len = $_[1];
142 ok (1, "client block $len/1");
143 $hd->unshift_read (packstring => "N", sub {
144 ok ($len == length $_[1], "client block $len/2");
145
146 if ($i != $cnt) {
147 $block->();
148 } else {
149 ok (1, "client_drain");
150 $client_done->send; undef $hd;
151 }
152 });
153 });
154 }
155
156 $block->(); 154 $block->();
157 }
158 }; 155 }
159 156
160 $server_done->recv; 157 $server_done->recv;
161 $client_done->recv; 158 $client_done->recv;
162} 159}
163 160

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines