Skip to content

Commit

Permalink
Add TTY(RawFD) for non-STDIO tty's
Browse files Browse the repository at this point in the history
Also add the necessary c functions to extract the FD/Handle from a pipe object. These aren't used anywhere, but will be helpful for #3823
  • Loading branch information
Keno committed Jul 24, 2013
1 parent 5975d23 commit da00fa4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ type TTY <: AsyncStream
false,Condition())
end

function TTY(fd::RawFD; readable::Bool = false)
handle = c_malloc(_sizeof_uv_tty)
uv_error("TTY",ccall(:uv_tty_init,Int32,(Ptr{Void},Ptr{Void},Int32,Int32),eventloop(),handle,fd.fd,readable) == -1)
ret = TTY(handle)
associate_julia_struct(handle,ret)
ret.status = StatusOpen
ret.line_buffered = false
ret
end

show(io::IO,stream::TTY) = print(io,"TTY(",uv_status_string(stream),", ",
nb_available(stream.buffer)," bytes waiting)")

Expand Down
17 changes: 17 additions & 0 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,23 @@ DLLEXPORT void *jl_uv_handle_data(uv_handle_t *handle)
return handle->data;
}

#ifndef _OS_WINDOWS_
#if defined(__APPLE__)
int uv___stream_fd(uv_stream_t* handle);
#define uv__stream_fd(handle) (uv___stream_fd((uv_stream_t*) (handle)))
#else
#define uv__stream_fd(handle) ((handle)->io_watcher.fd)
#endif /* defined(__APPLE__) */
DLLEXPORT int jl_uv_pipe_fd(uv_pipe_t *handle)
{
return uv__stream_fd((uv_stream_t*)handle);
}
#else
DLLEXPORT HANDLE jl_uv_pipe_handle(uv_pipe_t *handle)
{
return uv_get_pipe_handle(handle);
}
#endif
#ifdef __cplusplus
}
#endif

0 comments on commit da00fa4

Please sign in to comment.