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

JuliaLang / julia / #37433

pending completion
#37433

push

local

web-flow
Merge pull request #48513 from JuliaLang/jn/extend-once

ensure extension triggers are only run by the package that satified them

60 of 60 new or added lines in 1 file covered. (100.0%)

72324 of 82360 relevant lines covered (87.81%)

31376331.4 hits per line

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

83.02
/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)
427✔
8
        p = new(handle,
427✔
9
                status,
10
                Base.ThreadSynchronizer())
11
        associate_julia_struct(p.handle, p)
427✔
12
        finalizer(uvfinalize, p)
427✔
13
        return p
427✔
14
    end
15
end
16

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

27
## server functions ##
28

29
accept(server::PipeServer) = accept(server, PipeEndpoint())
430✔
30

31
function accept_nonblock(server::PipeServer, client::PipeEndpoint)
856✔
32
    iolock_begin()
856✔
33
    if client.status != StatusInit
856✔
34
        error("client is already in use or has been closed")
×
35
    end
36
    err = ccall(:uv_accept, Int32, (Ptr{Cvoid}, Ptr{Cvoid}), server.handle, client.handle)
856✔
37
    if err == 0
856✔
38
        client.status = StatusOpen
429✔
39
    end
40
    iolock_end()
856✔
41
    return err
856✔
42
end
43

44
function accept_nonblock(server::PipeServer)
×
45
    client = PipeEndpoint()
×
46
    uv_error("accept", accept_nonblock(server, client) != 0)
×
47
    return client
×
48
end
49

50
function bind(server::PipeServer, name::AbstractString)
427✔
51
    iolock_begin()
427✔
52
    @assert server.status == StatusInit
427✔
53
    err = ccall(:uv_pipe_bind, Int32, (Ptr{Cvoid}, Cstring),
427✔
54
                server, name)
55
    if err != 0
427✔
56
        iolock_end()
×
57
        if err != UV_EADDRINUSE && err != UV_EACCES
×
58
            #TODO: this codepath is currently not tested
59
            throw(_UVError("bind", err))
×
60
        else
61
            return false
×
62
        end
63
    end
64
    server.status = StatusOpen
427✔
65
    iolock_end()
427✔
66
    return true
427✔
67
end
68

69
"""
70
    listen(path::AbstractString) -> PipeServer
71

72
Create and listen on a named pipe / UNIX domain socket.
73

74
!!! note
75
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
76
"""
77
function listen(path::AbstractString)
427✔
78
    sock = PipeServer()
427✔
79
    bind(sock, path) || throw(ArgumentError("could not listen on path $path"))
427✔
80
    return listen(sock)
427✔
81
end
82

83
function connect!(sock::PipeEndpoint, path::AbstractString)
430✔
84
    iolock_begin()
430✔
85
    @assert sock.status == StatusInit
430✔
86
    req = Libc.malloc(Base._sizeof_uv_connect)
430✔
87
    uv_req_set_data(req, C_NULL)
430✔
88
    ccall(:uv_pipe_connect, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), req, sock.handle, path,
430✔
89
          @cfunction(uv_connectcb, Cvoid, (Ptr{Cvoid}, Cint)))
90
    sock.status = StatusConnecting
430✔
91
    iolock_end()
430✔
92
    return sock
430✔
93
end
94

95
"""
96
    connect(path::AbstractString) -> PipeEndpoint
97

98
Connect to the named pipe / UNIX domain socket at `path`.
99

100
!!! note
101
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
102
"""
103
connect(path::AbstractString) = connect(PipeEndpoint(), path)
430✔
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

© 2025 Coveralls, Inc