I was trying to skip some initial server info header when using tcp client in Julia 0.6.0:
julia> s=connect("smtp.mail.ru",25)
TCPSocket(RawFD(18) open, 0 bytes waiting)
julia> nb_available(s)
0
julia> nb_available(s)
0
(after 5 seconds or so...)
julia> nb_available(s)
0
julia> t=read(s,10)
10-element Array{UInt8,1}:
0x32
0x32
0x30
0x20
0x73
0x6d
0x74
0x70
0x31
0x34
(HOW, WHY???? nb_available==0, but read returns me 10 bytes?!)
... (read was repeated many times...)
julia> t=read(s,10)
^CERROR: InterruptException:
Stacktrace:
[1] process_events at ./libuv.jl:82 [inlined]
[2] wait() at ./event.jl:216
[3] wait(::Condition) at ./event.jl:27
[4] wait_readnb(::TCPSocket, ::Int64) at ./stream.jl:296
[5] readbytes!(::TCPSocket, ::Array{UInt8,1}, ::Int64) at ./stream.jl:714
[6] read(::TCPSocket, ::Int64) at ./io.jl:529
So… nb_available shows something incorrect. Mail server sends me some initial header, but nb_available cant see it and tell me that 0 bytes awaiting in the read buffer. Why?
Is there any other posobilities to skip server “greatings” header without blocking?
All I/O in julia is non-blocking in the traditional sense of the word, because we don’t block threads on I/O activity. However, we do use tasks to simulate blocking I/O for ease of programming. The nb_available function isn’t super meaningful for sockets. It tells you how many bytes are available in the userspace buffer. It says nothing about now many bytes are available in the kernel, in various buffers along the network path or are in transit.