~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to base/stream.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-11-17 19:32:52 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20131117193252-tkrpclguqqebqa35
Tags: 0.2.0+dfsg-3
testsuite-i386.patch: loosen the numerical precision for yet another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
end
129
129
 
130
130
function init_pipe!(pipe::Union(Pipe,PipeServer);readable::Bool=false,writable=false,julia_only=true)
131
 
    if pipe.handle == C_NULL || pipe.status != StatusUninit
132
 
        error("Failed to initialize pipe")
 
131
    if pipe.handle == C_NULL 
 
132
        error("Cannot initialize pipe. UV object not allocated!")
 
133
    elseif pipe.status != StatusUninit
 
134
        error("Pipe is already initialized!")
133
135
    end
134
136
    uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), pipe.handle, writable,readable,julia_only,pipe))
135
137
    pipe.status = StatusInit
206
208
disassociate_julia_struct(handle::Ptr{Void}) = 
207
209
    ccall(:jl_uv_disassociate_julia_struct,Void,(Ptr{Void},),handle)
208
210
 
209
 
function init_stdio(handle,fd)
 
211
function init_stdio(handle)
210
212
    t = ccall(:jl_uv_handle_type,Int32,(Ptr{Void},),handle)
211
213
    if t == UV_FILE
212
 
        return fdio(fd)
 
214
        return fdio(ccall(:jl_uv_file_handle,Int32,(Ptr{Void},),handle))
213
215
    else
214
216
        if t == UV_TTY
215
217
            ret = TTY(handle)
234
236
    global uv_jl_writecb = cglobal(:jl_uv_writecb)
235
237
    global uv_jl_writecb_task = cglobal(:jl_uv_writecb_task)
236
238
    global uv_eventloop = ccall(:jl_global_event_loop, Ptr{Void}, ())
237
 
    global STDIN = init_stdio(ccall(:jl_stdin_stream ,Ptr{Void},()),0)
238
 
    global STDOUT = init_stdio(ccall(:jl_stdout_stream,Ptr{Void},()),1)
239
 
    global STDERR = init_stdio(ccall(:jl_stderr_stream,Ptr{Void},()),2)
 
239
    global STDIN = init_stdio(ccall(:jl_stdin_stream ,Ptr{Void},()))
 
240
    global STDOUT = init_stdio(ccall(:jl_stdout_stream,Ptr{Void},()))
 
241
    global STDERR = init_stdio(ccall(:jl_stderr_stream,Ptr{Void},()))
240
242
    reinit_displays() # since Multimedia.displays uses STDOUT as fallback
241
243
end
242
244
 
513
515
 
514
516
## pipe functions ##
515
517
malloc_pipe() = c_malloc(_sizeof_uv_named_pipe)
 
518
 
 
519
_link_pipe(read_end::Ptr{Void},write_end::Ptr{Void}) = uv_error("pipe_link",ccall(:uv_pipe_link, Int32, (Ptr{Void}, Ptr{Void}), read_end, write_end))
 
520
 
516
521
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool,readpipe::AsyncStream,writepipe::AsyncStream)
517
522
    #make the pipe an unbuffered stream for now
518
523
    #TODO: this is probably not freeing memory properly after errors
519
524
    uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), read_end, 0, 1, readable_julia_only, readpipe))
520
525
    uv_error("init_pipe(2)",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), write_end, 1, 0, writable_julia_only, writepipe))
521
 
    uv_error("pipe_link",ccall(:uv_pipe_link, Int32, (Ptr{Void}, Ptr{Void}), read_end, write_end))
 
526
    _link_pipe(read_end,write_end)
522
527
end
523
528
 
524
529
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool)
525
530
    uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Ptr{Void}), read_end, 0, 1, readable_julia_only, C_NULL))
526
531
    uv_error("init_pipe(2)",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Ptr{Void}), write_end, 1, 0, writable_julia_only, C_NULL))
527
 
    uv_error("pipe_link",ccall(:uv_pipe_link, Int32, (Ptr{Void}, Ptr{Void}), read_end, write_end))
 
532
    _link_pipe(read_end,write_end)
528
533
end
529
534
 
530
 
function link_pipe(read_end2::Pipe,readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool)
531
 
    if read_end2.handle == C_NULL
532
 
        read_end2.handle = malloc_pipe()
 
535
function link_pipe(read_end::Pipe,readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool)
 
536
    if read_end.handle == C_NULL
 
537
        read_end.handle = malloc_pipe()
533
538
    end
534
 
    link_pipe(read_end2.handle,readable_julia_only,write_end,writable_julia_only,read_end2,read_end2)
535
 
    read_end2.status = StatusOpen
 
539
    init_pipe!(read_end; readable = true, writable = false, julia_only = readable_julia_only)
 
540
    uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), write_end, 1, 0, writable_julia_only, read_end))
 
541
    _link_pipe(read_end.handle,write_end)
 
542
    read_end.status = StatusOpen
536
543
end
537
544
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::Pipe,writable_julia_only::Bool)
538
545
    if write_end.handle == C_NULL
539
546
        write_end.handle = malloc_pipe()
540
547
    end
541
 
    link_pipe(read_end,readable_julia_only,write_end.handle,writable_julia_only,write_end,write_end)
 
548
    uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), read_end, 0, 1, readable_julia_only, write_end))
 
549
    init_pipe!(write_end; readable = false, writable = true, julia_only = writable_julia_only)
 
550
    _link_pipe(read_end,write_end.handle)
542
551
    write_end.status = StatusOpen
543
552
end
544
553
function link_pipe(read_end::Pipe,readable_julia_only::Bool,write_end::Pipe,writable_julia_only::Bool)
548
557
    if read_end.handle == C_NULL
549
558
        read_end.handle = malloc_pipe()
550
559
    end
551
 
    link_pipe(read_end.handle,readable_julia_only,write_end.handle,writable_julia_only,read_end,write_end)
 
560
    init_pipe!(read_end; readable = true, writable = false, julia_only = readable_julia_only)
 
561
    init_pipe!(write_end; readable = false, writable = true, julia_only = writable_julia_only)
 
562
    _link_pipe(read_end.handle,write_end.handle)
552
563
    write_end.status = StatusOpen
553
564
    read_end.status = StatusOpen
554
565
    nothing
569
580
## stream functions ##
570
581
function start_reading(stream::AsyncStream)
571
582
    if stream.status == StatusOpen
 
583
        if !isreadable(stream)
 
584
            error("Tried to read a stream that is not readable!")
 
585
        end
572
586
        ret = ccall(:uv_read_start,Cint,(Ptr{Void},Ptr{Void},Ptr{Void}),
573
587
            handle(stream),uv_jl_alloc_buf::Ptr{Void},uv_jl_readcb::Ptr{Void})
574
588
        stream.status = StatusActive