unix: implement uv_import() and uv_export()

This commit is contained in:
Ben Noordhuis 2012-01-21 04:31:25 +01:00
parent abdc3efffe
commit e34dc13496
2 changed files with 32 additions and 7 deletions

View File

@ -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__)

View File

@ -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;
}