On Tue, May 24, 2016 at 4:43 PM, Joshua Jones <
[email protected]> wrote:

> Hi,
>
> First post to the group, but I've been coding in Julia for about a year
> now.
>

Welcome!

*Questions*:
>
>    1. If I try to read from the TCP buffer, it blocks; CTRL-C seemingly
>    can't interrupt. Why?
>
> Appears to be fixed on master, I believe by 
> *https://github.com/JuliaLang/julia/issues/16174
<https://github.com/JuliaLang/julia/issues/16174>*

julia> s = connect(8880)
TCPSocket(open, 0 bytes waiting)

julia> t = try read(s) catch e println("error occurred"); throw(e) end
^Cerror occurred
ERROR: InterruptException:
 in eval(::Module, ::Any) at ./boot.jl:225
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

julia>



>
>    1. I've read (here and elsewhere) that Julia does an implicit block
>    while waiting for data. Is there a workaround?
>
> Do the blocking read asynchronously in a task. For network I/O (but not
file), `read` will only block at the task level. To end the read, `close`
the socket from another task.

>
>    1. If I *don't* try a read, the connection shows no data waiting. This
>    appears unique to Julia; I've tested simultaneous connections with
>    identical data requests using C and Python clients; those buffer data while
>    Julia shows 0 bytes waiting. Is something fundamentally different about how
>    Julia deals with (or shows) buffered data? If so, what?
>
> Are you using `nb_available`? Unfortunately, this is probably one of the
most confusing and poorly-documented functions we have.

https://github.com/JuliaLang/julia/issues/8762
https://github.com/JuliaLang/julia/issues/14624

The tl;dr is that it returns the number of bytes available
(already-buffered) to read *without* making a potentially-blocking call.
Hopefully you can (mostly) avoid needing to use it, by building around
tasks.

Reply via email to