diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index f1999292..792ca84a 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -193,9 +193,7 @@ typedef void* uv_lib_t; int mode; #define UV_STREAM_INFO_PRIVATE_FIELDS \ - union { \ - int fd; \ - }; + int fd; /* UV_FS_EVENT_PRIVATE_FIELDS */ #if defined(__linux__) diff --git a/src/unix/stream.c b/src/unix/stream.c index e831b24b..9e58fc53 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -967,12 +967,39 @@ int uv_read_stop(uv_stream_t* stream) { int uv_export(uv_stream_t* stream, uv_stream_info_t* info) { - /* Implement me */ - return uv__new_artificial_error(UV_ENOSYS); + int fd; + + if (stream->type != UV_TCP) { + uv__set_artificial_error(stream->loop, UV_EINVAL); + return -1; + } + + fd = uv__dup(stream->fd); + + if (fd == -1) { + uv__set_sys_error(stream->loop, errno); + return -1; + } + + info->type = stream->type; + info->fd = fd; + + return 0; } int uv_import(uv_stream_t* stream, uv_stream_info_t* info) { - /* Implement me */ - return uv__new_artificial_error(UV_ENOSYS); + if (info->type != UV_TCP) { + uv__set_artificial_error(stream->loop, UV_EINVAL); + return -1; + } + + if (stream->fd != -1) { + uv__set_artificial_error(stream->loop, UV_EALREADY); + return -1; + } + + stream->fd = info->fd; + + return 0; }