Skip to content

Commit

Permalink
unix: implement uv_import() and uv_export()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jan 30, 2012
1 parent abdc3ef commit e34dc13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
4 changes: 1 addition & 3 deletions include/uv-private/uv-unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
35 changes: 31 additions & 4 deletions src/unix/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e34dc13

Please sign in to comment.