1
+ #[ doc="
2
+ High-level interface to libuv's TCP functionality
3
+ " ] ;
4
+
5
+ #[ cfg( ignore) ]
6
+ mod test {
7
+ #[ test]
8
+ fn test_gl_tcp_ipv4_request ( ) {
9
+ let ip = "127.0.0.1" ;
10
+ let port = 80 u;
11
+ let expected_read_msg = "foo" ;
12
+ let actual_write_msg = "bar" ;
13
+ let addr = ipv4:: address ( ip, port) ;
14
+
15
+ let data_po = comm:: port :: < [ u8 ] > ( ) ;
16
+ let data_ch = comm:: chan ( data_po) ;
17
+
18
+ alt connect( addr) {
19
+ tcp_connected ( tcp_stream) {
20
+ let write_data = str:: as_buf ( actual_write_msg) ;
21
+ alt write( tcp_stream, [ write_data] ) {
22
+ tcp_write_success {
23
+ let mut total_read_data : [ u8] = [ ]
24
+ let reader_po = read_start ( tcp_stream) ;
25
+ loop {
26
+ alt comm:: recv ( reader_po) {
27
+ new_read_data ( data) {
28
+ total_read_data += data;
29
+ // theoretically, we could keep iterating, here, if
30
+ // we expect the server on the other end to keep
31
+ // streaming/chunking data to us, but..
32
+ read_stop ( tcp_stream) ;
33
+ break ;
34
+ }
35
+ done_reading {
36
+ break;
37
+ }
38
+ error {
39
+ fail "erroring occured during read attempt.. FIXME need info" ;
40
+ }
41
+ }
42
+ }
43
+ comm:: send ( data_ch, total_read_data) ;
44
+ }
45
+ tcp_write_error {
46
+ fail "error during write attempt.. FIXME need err info" ;
47
+ }
48
+ }
49
+ }
50
+ tcp_connect_error {
51
+ fail "error during connection attempt.. FIXME need err info.." ;
52
+ }
53
+ }
54
+
55
+ let actual_data = comm:: recv ( data_po) ;
56
+ let resp = str:: from_bytes ( actual_data) ;
57
+ log ( debug, "DATA RECEIVED: " +resp) ;
58
+ }
59
+ }
0 commit comments