• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #38202

25 Aug 2025 08:40PM UTC coverage: 78.315% (+0.4%) from 77.895%
#38202

push

local

web-flow
spawn: Allow libuv IOServers to be passed as extra FDs (#59373)

This allows libuv `IOServer`s (unix domain servers, tcp servers, etc)
to be passed as extra fd arguments to child processes that are
expecting them.

Extracted from #59271, but I now have an independent use case.

15 of 16 new or added lines in 3 files covered. (93.75%)

275 existing lines in 28 files now uncovered.

48726 of 62218 relevant lines covered (78.31%)

9701563.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/stdlib/Sockets/src/PipeServer.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
mutable struct PipeServer <: LibuvServer
4
    handle::Ptr{Cvoid}
5
    status::Int
6
    cond::Base.ThreadSynchronizer
7
    function PipeServer(handle::Ptr{Cvoid}, status)
8
        p = new(handle,
1✔
9
                status,
10
                Base.ThreadSynchronizer())
11
        associate_julia_struct(p.handle, p)
1✔
12
        finalizer(uvfinalize, p)
1✔
13
        return p
1✔
14
    end
15
end
16

17
function PipeServer()
1✔
18
    pipe = PipeServer(Libc.malloc(Base._sizeof_uv_named_pipe), StatusUninit)
1✔
19
    iolock_begin()
1✔
20
    err = ccall(:uv_pipe_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cint), eventloop(), pipe.handle, 0)
1✔
21
    uv_error("failed to create pipe server", err)
1✔
22
    pipe.status = StatusInit
1✔
23
    iolock_end()
1✔
24
    return pipe
1✔
25
end
26

27
function PipeServer(handle::OS_HANDLE)
1✔
28
    pipe = PipeServer()
1✔
29
    return Base.open_pipe!(pipe, handle)
1✔
30
end
31

32
function Base.open_pipe!(p::PipeServer, handle::OS_HANDLE)
33
    iolock_begin()
1✔
34
    if p.status != StatusInit
1✔
NEW
35
        error("pipe is already in use or has been closed")
×
36
    end
37
    err = ccall(:uv_pipe_open, Int32, (Ptr{Cvoid}, OS_HANDLE), p.handle, handle)
1✔
38
    uv_error("pipe_open", err)
1✔
39
    p.status = StatusOpen
1✔
40
    iolock_end()
1✔
41
    return p
1✔
42
end
43

44
## server functions ##
45

46
accept(server::PipeServer) = accept(server, PipeEndpoint())
631✔
47

48
function accept_nonblock(server::PipeServer, client::PipeEndpoint)
49
    iolock_begin()
2✔
50
    if client.status != StatusInit
2✔
UNCOV
51
        error("client is already in use or has been closed")
×
52
    end
53
    err = ccall(:uv_accept, Int32, (Ptr{Cvoid}, Ptr{Cvoid}), server.handle, client.handle)
2✔
54
    if err == 0
2✔
55
        client.status = StatusOpen
1✔
56
    end
57
    iolock_end()
2✔
58
    return err
2✔
59
end
60

UNCOV
61
function accept_nonblock(server::PipeServer)
×
UNCOV
62
    client = PipeEndpoint()
×
UNCOV
63
    uv_error("accept", accept_nonblock(server, client) != 0)
×
UNCOV
64
    return client
×
65
end
66

67
function bind(server::PipeServer, name::AbstractString)
628✔
68
    iolock_begin()
628✔
69
    @assert server.status == StatusInit
628✔
70
    err = ccall(:uv_pipe_bind, Int32, (Ptr{Cvoid}, Cstring),
628✔
71
                server, name)
72
    if err != 0
628✔
UNCOV
73
        iolock_end()
×
UNCOV
74
        if err != UV_EADDRINUSE && err != UV_EACCES
×
75
            #TODO: this codepath is currently not tested
UNCOV
76
            throw(_UVError("bind", err))
×
77
        else
78
            return false
×
79
        end
80
    end
81
    server.status = StatusOpen
628✔
82
    iolock_end()
628✔
83
    return true
628✔
84
end
85

86
"""
87
    listen(path::AbstractString) -> PipeServer
88

89
Create and listen on a named pipe / UNIX domain socket.
90

91
!!! note
92
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
93
"""
94
function listen(path::AbstractString)
627✔
95
    sock = PipeServer()
627✔
96
    bind(sock, path) || throw(ArgumentError("could not listen on path $path"))
627✔
97
    return listen(sock)
627✔
98
end
99

100
function connect!(sock::PipeEndpoint, path::AbstractString)
687✔
101
    iolock_begin()
687✔
102
    @assert sock.status == StatusInit
687✔
103
    req = Libc.malloc(Base._sizeof_uv_connect)
687✔
104
    uv_req_set_data(req, C_NULL)
687✔
105
    ccall(:uv_pipe_connect, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), req, sock.handle, path,
687✔
106
          @cfunction(uv_connectcb, Cvoid, (Ptr{Cvoid}, Cint)))
107
    sock.status = StatusConnecting
687✔
108
    iolock_end()
687✔
109
    return sock
687✔
110
end
111

112
"""
113
    connect(path::AbstractString) -> PipeEndpoint
114

115
Connect to the named pipe / UNIX domain socket at `path`.
116

117
!!! note
118
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
119
"""
120
connect(path::AbstractString) = connect(PipeEndpoint(), path)
687✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc