Skip to content

Commit 3d8f7d6

Browse files
olsonjefferybrson
authored andcommitted
std: no longer return uv::ll::err_data records from net::tcp
they're changed into a net::tcp::tcp_err_data record, for now. once the scope of possible tcp errors, from libuv, is established ill create an err type for each one and return those where they might occur
1 parent 565c5d6 commit 3d8f7d6

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/libstd/net_tcp.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ High-level interface to libuv's TCP functionality
44

55
import ip = net_ip;
66

7-
export tcp_connect_result, tcp_write_result, tcp_read_start_result;
7+
export tcp_err_data, tcp_connect_result, tcp_write_result, tcp_read_start_result;
88
export connect, write;
99

1010
resource tcp_socket(socket_data: @tcp_socket_data) unsafe {
@@ -26,25 +26,40 @@ resource tcp_socket(socket_data: @tcp_socket_data) unsafe {
2626
log(debug, "exiting dtor for tcp_socket");
2727
}
2828

29+
type tcp_err_data = {
30+
err_name: str,
31+
err_msg: str
32+
};
33+
34+
iface to_tcp_err_iface {
35+
fn to_tcp_err() -> tcp_err_data;
36+
}
37+
38+
impl of to_tcp_err_iface for uv::ll::uv_err_data {
39+
fn to_tcp_err() -> tcp_err_data {
40+
{ err_name: self.err_name, err_msg: self.err_msg }
41+
}
42+
}
43+
2944
enum tcp_connect_result {
3045
tcp_connected(tcp_socket),
31-
tcp_connect_error(uv::ll::uv_err_data)
46+
tcp_connect_error(tcp_err_data)
3247
}
3348

3449
enum tcp_write_result {
3550
tcp_write_success,
36-
tcp_write_error(uv::ll::uv_err_data)
51+
tcp_write_error(tcp_err_data)
3752
}
3853

3954
enum tcp_read_start_result {
4055
tcp_read_start_success(comm::port<tcp_read_result>),
41-
tcp_read_start_error(uv::ll::uv_err_data)
56+
tcp_read_start_error(tcp_err_data)
4257
}
4358

4459
enum tcp_read_result {
4560
tcp_read_data([u8]),
4661
tcp_read_done,
47-
tcp_read_err(uv::ll::uv_err_data)
62+
tcp_read_err(tcp_err_data)
4863
}
4964

5065
#[doc="
@@ -126,7 +141,7 @@ fn connect(input_ip: ip::ip_addr, port: uint) -> tcp_connect_result unsafe {
126141
// ip or somesuch
127142
let err_data = uv::ll::get_last_err_data(loop_ptr);
128143
comm::send((*conn_data_ptr).result_ch,
129-
conn_failure(err_data));
144+
conn_failure(err_data.to_tcp_err()));
130145
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
131146
conn_data_ptr);
132147
uv::ll::close(stream_handle_ptr, stream_error_close_cb);
@@ -139,7 +154,7 @@ fn connect(input_ip: ip::ip_addr, port: uint) -> tcp_connect_result unsafe {
139154
// failure to create a tcp handle
140155
let err_data = uv::ll::get_last_err_data(loop_ptr);
141156
comm::send((*conn_data_ptr).result_ch,
142-
conn_failure(err_data));
157+
conn_failure(err_data.to_tcp_err()));
143158
}
144159
}
145160
};
@@ -151,7 +166,7 @@ fn connect(input_ip: ip::ip_addr, port: uint) -> tcp_connect_result unsafe {
151166
conn_failure(err_data) {
152167
comm::recv(closed_signal_po);
153168
log(debug, "tcp::connect - received failure on result_po");
154-
tcp_connect_error(err_data)
169+
tcp_connect_error(err_data.to_tcp_err())
155170
}
156171
}
157172
}
@@ -189,7 +204,7 @@ fn write(sock: tcp_socket, raw_write_data: [[u8]]) -> tcp_write_result
189204
log(debug, "error invoking uv_write()");
190205
let err_data = uv::ll::get_last_err_data(loop_ptr);
191206
comm::send((*write_data_ptr).result_ch,
192-
tcp_write_error(err_data));
207+
tcp_write_error(err_data.to_tcp_err()));
193208
}
194209
}
195210
};
@@ -220,7 +235,7 @@ fn read_start(sock: tcp_socket) -> tcp_read_start_result unsafe {
220235
};
221236
alt comm::recv(start_po) {
222237
some(err_data) {
223-
tcp_read_start_error(err_data)
238+
tcp_read_start_error(err_data.to_tcp_err())
224239
}
225240
none {
226241
tcp_read_start_success((**sock).reader_po)
@@ -230,7 +245,7 @@ fn read_start(sock: tcp_socket) -> tcp_read_start_result unsafe {
230245

231246
fn read_stop(sock: tcp_socket) -> option<uv::ll::uv_err_data> unsafe {
232247
let stream_handle_ptr = ptr::addr_of((**sock).stream_handle);
233-
let stop_po = comm::port::<option<uv::ll::uv_err_data>>();
248+
let stop_po = comm::port::<option<tcp_err_data>>();
234249
let stop_ch = comm::chan(stop_po);
235250
uv::hl::interact((**sock).hl_loop) {|loop_ptr|
236251
log(debug, "in interact cb for tcp::read_stop");
@@ -242,7 +257,7 @@ fn read_stop(sock: tcp_socket) -> option<uv::ll::uv_err_data> unsafe {
242257
_ {
243258
log(debug, "failure in calling uv_read_stop");
244259
let err_data = uv::ll::get_last_err_data(loop_ptr);
245-
comm::send(stop_ch, some(err_data));
260+
comm::send(stop_ch, some(err_data.to_tcp_err()));
246261
}
247262
}
248263
};

0 commit comments

Comments
 (0)