Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Add interfaces for uv_pipe_open, uv_tty_init, uv_tty_set_mode
Browse files Browse the repository at this point in the history
Nothing works - no tests. This is just to coordinate efforts between Bert
and I.
  • Loading branch information
ry committed Sep 12, 2011
1 parent 9bd8bd7 commit 4484d61
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions config-unix.mk
Expand Up @@ -37,6 +37,7 @@ OBJS += src/unix/error.o
OBJS += src/unix/process.o
OBJS += src/unix/tcp.o
OBJS += src/unix/pipe.o
OBJS += src/unix/tty.o
OBJS += src/unix/stream.o

ifeq (SunOS,$(uname_S))
Expand Down
2 changes: 2 additions & 0 deletions include/uv-private/uv-unix.h
Expand Up @@ -173,4 +173,6 @@ typedef int uv_file;
#define UV_WORK_PRIVATE_FIELDS \
eio_req* eio;

#define UV_TTY_PRIVATE_FIELDS /* empty */

#endif /* UV_UNIX_H */
3 changes: 3 additions & 0 deletions include/uv-private/uv-win.h
Expand Up @@ -261,6 +261,9 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_WORK_PRIVATE_FIELDS \


#define UV_TTY_PRIVATE_FIELDS /* empty */

int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer,
Expand Down
28 changes: 27 additions & 1 deletion include/uv.h
Expand Up @@ -49,6 +49,7 @@ typedef struct uv_stream_s uv_stream_t;
typedef struct uv_tcp_s uv_tcp_t;
typedef struct uv_udp_s uv_udp_t;
typedef struct uv_pipe_s uv_pipe_t;
typedef struct uv_tty_s uv_tty_t;
typedef struct uv_timer_s uv_timer_t;
typedef struct uv_prepare_s uv_prepare_t;
typedef struct uv_check_s uv_check_t;
Expand Down Expand Up @@ -324,7 +325,7 @@ uv_buf_t uv_buf_init(char* base, size_t len);
*
* uv_stream is an abstract class.
*
* uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t
* uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t
* and soon uv_file_t.
*/
struct uv_stream_s {
Expand Down Expand Up @@ -587,6 +588,25 @@ int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
int uv_udp_recv_stop(uv_udp_t* handle);


/*
* uv_tty_t is a subclass of uv_stream_t
*
* Representing a stream for the console.
*/
struct uv_tty_s {
UV_HANDLE_FIELDS
UV_STREAM_FIELDS
UV_TTY_PRIVATE_FIELDS
};

int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd);

/*
* Set mode. 0 for normal, 1 for raw.
*/
int uv_tty_set_mode(uv_tty_t*, int mode);


/*
* uv_pipe_t is a subclass of uv_stream_t
*
Expand All @@ -601,6 +621,11 @@ struct uv_pipe_s {

int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle);

/*
* Opens an existing file descriptor or HANDLE as a pipe.
*/
void uv_pipe_open(uv_pipe_t*, uv_file file);

int uv_pipe_bind(uv_pipe_t* handle, const char* name);

int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
Expand Down Expand Up @@ -1026,6 +1051,7 @@ struct uv_counters_s {
uint64_t tcp_init;
uint64_t udp_init;
uint64_t pipe_init;
uint64_t tty_init;
uint64_t prepare_init;
uint64_t check_init;
uint64_t idle_init;
Expand Down
5 changes: 5 additions & 0 deletions src/unix/pipe.c
Expand Up @@ -170,6 +170,11 @@ int uv_pipe_cleanup(uv_pipe_t* handle) {
}


void uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
uv__stream_open((uv_stream_t*)handle, fd, UV_READABLE | UV_WRITABLE);
}


int uv_pipe_connect(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
Expand Down
39 changes: 39 additions & 0 deletions src/unix/tty.c
@@ -0,0 +1,39 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "internal.h"

#include <assert.h>


int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) {
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE | UV_WRITABLE);
loop->counters.tty_init++;
return 0;
}


int uv_tty_set_mode(uv_tty_t* tty, int mode) {
assert(0 && "implement me");
return -1;
}
6 changes: 6 additions & 0 deletions src/win/pipe.c
Expand Up @@ -1059,3 +1059,9 @@ static void eof_timer_close_cb(uv_handle_t* handle) {
assert(handle->type == UV_TIMER);
free(handle);
}


void uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
assert(0 && "implement me");
}

37 changes: 37 additions & 0 deletions src/win/tty.c
@@ -0,0 +1,37 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "internal.h"

#include <assert.h>


int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) {
assert(0 && "implement me");
return -1;
}


int uv_tty_set_mode(uv_tty_t* tty, int mode) {
assert(0 && "implement me");
return -1;
}
2 changes: 2 additions & 0 deletions uv.gyp
Expand Up @@ -113,6 +113,7 @@
'src/win/stdio.c',
'src/win/stream.c',
'src/win/tcp.c',
'src/win/tty.c',
'src/win/threadpool.c',
'src/win/threads.c',
'src/win/timer.c',
Expand Down Expand Up @@ -149,6 +150,7 @@
'src/unix/udp.c',
'src/unix/tcp.c',
'src/unix/pipe.c',
'src/unix/tty.c',
'src/unix/stream.c',
'src/unix/cares.c',
'src/unix/error.c',
Expand Down

0 comments on commit 4484d61

Please sign in to comment.