Skip to content

Commit 56dc96a

Browse files
committed
---
yaml --- r: 61289 b: refs/heads/try c: 91ca3a9 h: refs/heads/master i: 61287: 00b2497 v: v3
1 parent e3357cf commit 56dc96a

File tree

2 files changed

+116
-115
lines changed

2 files changed

+116
-115
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
5-
refs/heads/try: 6ab02c03da1e610f9c2f4c9a185a74f37f6195f2
5+
refs/heads/try: 91ca3a9b295404e6dc36677d415573935a9989db
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/rt/uv/mod.rs

Lines changed: 115 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -178,111 +178,6 @@ impl NativeHandle<*uvll::uv_idle_t> for IdleWatcher {
178178
}
179179
}
180180

181-
// XXX: Need to define the error constants like EOF so they can be
182-
// compared to the UvError type
183-
184-
pub struct UvError(uvll::uv_err_t);
185-
186-
pub impl UvError {
187-
188-
fn name(&self) -> ~str {
189-
unsafe {
190-
let inner = match self { &UvError(ref a) => a };
191-
let name_str = uvll::err_name(inner);
192-
assert!(name_str.is_not_null());
193-
from_c_str(name_str)
194-
}
195-
}
196-
197-
fn desc(&self) -> ~str {
198-
unsafe {
199-
let inner = match self { &UvError(ref a) => a };
200-
let desc_str = uvll::strerror(inner);
201-
assert!(desc_str.is_not_null());
202-
from_c_str(desc_str)
203-
}
204-
}
205-
}
206-
207-
impl ToStr for UvError {
208-
fn to_str(&self) -> ~str {
209-
fmt!("%s: %s", self.name(), self.desc())
210-
}
211-
}
212-
213-
#[test]
214-
fn error_smoke_test() {
215-
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
216-
let err: UvError = UvError(err);
217-
assert!(err.to_str() == ~"EOF: end of file");
218-
}
219-
220-
pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
221-
unsafe {
222-
let loop_ = watcher.event_loop();
223-
UvError(uvll::last_error(loop_.native_handle()))
224-
}
225-
}
226-
227-
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
228-
229-
// XXX: Could go in str::raw
230-
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
231-
let s = s as *u8;
232-
let mut curr = s, len = 0u;
233-
while *curr != 0u8 {
234-
len += 1u;
235-
curr = ptr::offset(s, len);
236-
}
237-
238-
str::raw::buf_as_slice(s, len, |d| cast::transmute(d))
239-
}
240-
241-
242-
unsafe {
243-
// Importing error constants
244-
use rt::uv::uvll::*;
245-
use rt::io::*;
246-
247-
// uv error descriptions are static
248-
let c_desc = uvll::strerror(&*uverr);
249-
let desc = c_str_to_static_slice(c_desc);
250-
251-
let kind = match uverr.code {
252-
UNKNOWN => OtherIoError,
253-
OK => OtherIoError,
254-
EOF => EndOfFile,
255-
EACCES => PermissionDenied,
256-
ECONNREFUSED => ConnectionRefused,
257-
e => {
258-
abort!("unknown uv error code: %u", e as uint);
259-
}
260-
};
261-
262-
IoError {
263-
kind: kind,
264-
desc: desc,
265-
detail: None
266-
}
267-
}
268-
}
269-
270-
/// Given a uv handle, convert a callback status to a UvError
271-
// XXX: Follow the pattern below by parameterizing over T: Watcher, not T
272-
pub fn status_to_maybe_uv_error<T>(handle: *T, status: c_int) -> Option<UvError> {
273-
if status != -1 {
274-
None
275-
} else {
276-
unsafe {
277-
rtdebug!("handle: %x", handle as uint);
278-
let loop_ = uvll::get_loop_for_uv_handle(handle);
279-
rtdebug!("loop: %x", loop_ as uint);
280-
let err = uvll::last_error(loop_);
281-
Some(UvError(err))
282-
}
283-
}
284-
}
285-
286181
/// Callbacks used by StreamWatchers, set as custom data on the foreign handle
287182
struct WatcherData {
288183
read_cb: Option<ReadCallback>,
@@ -383,21 +278,109 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
383278
}
384279
}
385280

281+
// XXX: Need to define the error constants like EOF so they can be
282+
// compared to the UvError type
283+
284+
pub struct UvError(uvll::uv_err_t);
285+
286+
pub impl UvError {
287+
288+
fn name(&self) -> ~str {
289+
unsafe {
290+
let inner = match self { &UvError(ref a) => a };
291+
let name_str = uvll::err_name(inner);
292+
assert!(name_str.is_not_null());
293+
from_c_str(name_str)
294+
}
295+
}
296+
297+
fn desc(&self) -> ~str {
298+
unsafe {
299+
let inner = match self { &UvError(ref a) => a };
300+
let desc_str = uvll::strerror(inner);
301+
assert!(desc_str.is_not_null());
302+
from_c_str(desc_str)
303+
}
304+
}
305+
}
306+
307+
impl ToStr for UvError {
308+
fn to_str(&self) -> ~str {
309+
fmt!("%s: %s", self.name(), self.desc())
310+
}
311+
}
312+
386313
#[test]
387-
fn test_slice_to_uv_buf() {
388-
let slice = [0, .. 20];
389-
let buf = slice_to_uv_buf(slice);
314+
fn error_smoke_test() {
315+
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
316+
let err: UvError = UvError(err);
317+
assert!(err.to_str() == ~"EOF: end of file");
318+
}
319+
320+
pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
321+
unsafe {
322+
let loop_ = watcher.event_loop();
323+
UvError(uvll::last_error(loop_.native_handle()))
324+
}
325+
}
326+
327+
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
328+
329+
// XXX: Could go in str::raw
330+
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
331+
let s = s as *u8;
332+
let mut curr = s, len = 0u;
333+
while *curr != 0u8 {
334+
len += 1u;
335+
curr = ptr::offset(s, len);
336+
}
337+
338+
str::raw::buf_as_slice(s, len, |d| cast::transmute(d))
339+
}
390340
391-
assert!(buf.len == 20);
392341
393342
unsafe {
394-
let base = transmute::<*u8, *mut u8>(buf.base);
395-
(*base) = 1;
396-
(*ptr::mut_offset(base, 1)) = 2;
343+
// Importing error constants
344+
use rt::uv::uvll::*;
345+
use rt::io::*;
346+
347+
// uv error descriptions are static
348+
let c_desc = uvll::strerror(&*uverr);
349+
let desc = c_str_to_static_slice(c_desc);
350+
351+
let kind = match uverr.code {
352+
UNKNOWN => OtherIoError,
353+
OK => OtherIoError,
354+
EOF => EndOfFile,
355+
EACCES => PermissionDenied,
356+
ECONNREFUSED => ConnectionRefused,
357+
e => {
358+
abort!("unknown uv error code: %u", e as uint);
359+
}
360+
};
361+
362+
IoError {
363+
kind: kind,
364+
desc: desc,
365+
detail: None
366+
}
397367
}
368+
}
398369
399-
assert!(slice[0] == 1);
400-
assert!(slice[1] == 2);
370+
/// Given a uv handle, convert a callback status to a UvError
371+
// XXX: Follow the pattern below by parameterizing over T: Watcher, not T
372+
pub fn status_to_maybe_uv_error<T>(handle: *T, status: c_int) -> Option<UvError> {
373+
if status != -1 {
374+
None
375+
} else {
376+
unsafe {
377+
rtdebug!("handle: %x", handle as uint);
378+
let loop_ = uvll::get_loop_for_uv_handle(handle);
379+
rtdebug!("loop: %x", loop_ as uint);
380+
let err = uvll::last_error(loop_);
381+
Some(UvError(err))
382+
}
383+
}
401384
}
402385
403386
/// The uv buffer type
@@ -437,6 +420,24 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
437420
}
438421
}
439422
423+
#[test]
424+
fn test_slice_to_uv_buf() {
425+
let slice = [0, .. 20];
426+
let buf = slice_to_uv_buf(slice);
427+
428+
assert!(buf.len == 20);
429+
430+
unsafe {
431+
let base = transmute::<*u8, *mut u8>(buf.base);
432+
(*base) = 1;
433+
(*ptr::mut_offset(base, 1)) = 2;
434+
}
435+
436+
assert!(slice[0] == 1);
437+
assert!(slice[1] == 2);
438+
}
439+
440+
440441
#[test]
441442
fn loop_smoke_test() {
442443
do run_in_bare_thread {

0 commit comments

Comments
 (0)