13
13
14
14
# # types ##
15
15
abstract type IOServer end
16
+ """
17
+ LibuvServer
18
+
19
+ An abstract type for IOServers handled by libuv.
20
+
21
+ If `server isa LibuvServer`, it must obey the following interface:
22
+
23
+ - `server.handle` must be a `Ptr{Cvoid}`
24
+ - `server.status` must be an `Int`
25
+ - `server.cond` must be a `GenericCondition`
26
+ """
16
27
abstract type LibuvServer <: IOServer end
28
+
29
+ function getproperty (server:: LibuvServer , name:: Symbol )
30
+ if name === :handle
31
+ return getfield (server, :handle ):: Ptr{Cvoid}
32
+ elseif name === :status
33
+ return getfield (server, :status ):: Int
34
+ elseif name === :cond
35
+ return getfield (server, :cond ):: GenericCondition
36
+ else
37
+ return getfield (server, name)
38
+ end
39
+ end
40
+
41
+ """
42
+ LibuvStream
43
+
44
+ An abstract type for IO streams handled by libuv.
45
+
46
+ If`stream isa LibuvStream`, it must obey the following interface:
47
+
48
+ - `stream.handle`, if present, must be a `Ptr{Cvoid}`
49
+ - `stream.status`, if present, must be an `Int`
50
+ - `stream.buffer`, if present, must be an `IOBuffer`
51
+ - `stream.sendbuf`, if present, must be a `Union{Nothing,IOBuffer}`
52
+ - `stream.cond`, if present, must be a `GenericCondition`
53
+ - `stream.lock`, if present, must be an `AbstractLock`
54
+ - `stream.throttle`, if present, must be an `Int`
55
+ """
17
56
abstract type LibuvStream <: IO end
18
57
58
+ function getproperty (stream:: LibuvStream , name:: Symbol )
59
+ if name === :handle
60
+ return getfield (stream, :handle ):: Ptr{Cvoid}
61
+ elseif name === :status
62
+ return getfield (stream, :status ):: Int
63
+ elseif name === :buffer
64
+ return getfield (stream, :buffer ):: IOBuffer
65
+ elseif name === :sendbuf
66
+ return getfield (stream, :sendbuf ):: Union{Nothing,IOBuffer}
67
+ elseif name === :cond
68
+ return getfield (stream, :cond ):: GenericCondition
69
+ elseif name === :lock
70
+ return getfield (stream, :lock ):: AbstractLock
71
+ elseif name === :throttle
72
+ return getfield (stream, :throttle ):: Int
73
+ else
74
+ return getfield (stream, name)
75
+ end
76
+ end
19
77
20
78
# IO
21
79
# +- GenericIOBuffer{T<:AbstractArray{UInt8,1}} (not exported)
@@ -320,7 +378,7 @@ function isopen(x::Union{LibuvStream, LibuvServer})
320
378
if x. status == StatusUninit || x. status == StatusInit
321
379
throw (ArgumentError (" $x is not initialized" ))
322
380
end
323
- return x. status:: Int != StatusClosed && x. status:: Int != StatusEOF
381
+ return x. status != StatusClosed && x. status != StatusEOF
324
382
end
325
383
326
384
function check_open (x:: Union{LibuvStream, LibuvServer} )
@@ -395,7 +453,7 @@ function close(stream::Union{LibuvStream, LibuvServer})
395
453
stream. status = StatusClosing
396
454
elseif isopen (stream) || stream. status == StatusEOF
397
455
should_wait = uv_handle_data (stream) != C_NULL
398
- if stream. status:: Int != StatusClosing
456
+ if stream. status != StatusClosing
399
457
ccall (:jl_close_uv , Cvoid, (Ptr{Cvoid},), stream. handle)
400
458
stream. status = StatusClosing
401
459
end
@@ -410,7 +468,7 @@ function uvfinalize(uv::Union{LibuvStream, LibuvServer})
410
468
iolock_begin ()
411
469
if uv. handle != C_NULL
412
470
disassociate_julia_struct (uv. handle) # not going to call the usual close hooks
413
- if uv. status:: Int != StatusUninit
471
+ if uv. status != StatusUninit
414
472
close (uv)
415
473
else
416
474
Libc. free (uv. handle)
@@ -524,7 +582,7 @@ function uv_alloc_buf(handle::Ptr{Cvoid}, size::Csize_t, buf::Ptr{Cvoid})
524
582
stream = unsafe_pointer_to_objref (hd):: LibuvStream
525
583
526
584
local data:: Ptr{Cvoid} , newsize:: Csize_t
527
- if stream. status:: Int != StatusActive
585
+ if stream. status != StatusActive
528
586
data = C_NULL
529
587
newsize = 0
530
588
else
@@ -557,7 +615,7 @@ function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid})
557
615
if isa (stream, TTY)
558
616
stream. status = StatusEOF # libuv called uv_stop_reading already
559
617
notify (stream. cond)
560
- elseif stream. status:: Int != StatusClosing
618
+ elseif stream. status != StatusClosing
561
619
# begin shutdown of the stream
562
620
ccall (:jl_close_uv , Cvoid, (Ptr{Cvoid},), stream. handle)
563
621
stream. status = StatusClosing
@@ -667,7 +725,7 @@ show(io::IO, stream::Pipe) = print(io,
667
725
668
726
function open_pipe! (p:: PipeEndpoint , handle:: OS_HANDLE )
669
727
iolock_begin ()
670
- if p. status:: Int != StatusInit
728
+ if p. status != StatusInit
671
729
error (" pipe is already in use or has been closed" )
672
730
end
673
731
err = ccall (:uv_pipe_open , Int32, (Ptr{Cvoid}, OS_HANDLE), p. handle, handle)
@@ -1061,7 +1119,7 @@ _fd(x::Union{OS_HANDLE, RawFD}) = x
1061
1119
1062
1120
function _fd (x:: Union{LibuvStream, LibuvServer} )
1063
1121
fd = Ref {OS_HANDLE} (INVALID_OS_HANDLE)
1064
- if x. status:: Int != StatusUninit && x. status:: Int != StatusClosed
1122
+ if x. status != StatusUninit && x. status != StatusClosed
1065
1123
err = ccall (:uv_fileno , Int32, (Ptr{Cvoid}, Ptr{OS_HANDLE}), x. handle, fd)
1066
1124
# handle errors by returning INVALID_OS_HANDLE
1067
1125
end
0 commit comments