Skip to content

Commit

Permalink
Merge pull request #227 from JuliaInterop/docstrings
Browse files Browse the repository at this point in the history
Improve docstrings and remove implicit imports
  • Loading branch information
JamesWrigley authored May 18, 2024
2 parents 9ec590e + 20531b3 commit 03cf2c1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 81 deletions.
10 changes: 10 additions & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The ZMQ Socket type:

```@docs
Socket
Socket(::Context, ::Integer)
Socket(::Integer)
Socket(::Function)
isopen
close
```
Expand Down Expand Up @@ -42,6 +45,13 @@ DOWNSTREAM

```@docs
Message
Message()
Message(::Integer)
Message(::Any)
Message(::String)
Message(::SubString{String})
Message(::Array)
Message(::IOBuffer)
```

## Context
Expand Down
4 changes: 2 additions & 2 deletions src/ZMQ.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Support for ZeroMQ, a network and interprocess communication library

module ZMQ
using ZeroMQ_jll
import ZeroMQ_jll: libzmq

using Base.Libc: EAGAIN
using FileWatching: UV_READABLE, uv_pollcb, FDWatcher
Expand Down Expand Up @@ -43,7 +43,7 @@ function __init__()
end
end

using PrecompileTools
import PrecompileTools: @compile_workload
@compile_workload begin
__init__()
# The ZMQ scoping below isn't necessary, but it makes it easier to copy/paste
Expand Down
31 changes: 27 additions & 4 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,36 @@ const PUSH = 8
const XPUB = 9
"[XSUB](https://zeromq.org/socket-api/#xsub-socket) socket."
const XSUB = 10
"[XREQ](https://zeromq.org/socket-api/#dealer-socket) socket."
"""
[XREQ](https://zeromq.org/socket-api/#dealer-socket) socket.
!!! compat
This is a deprecated alias for [ZMQ.DEALER](@ref).
"""
const XREQ = DEALER
"[XREP](https://zeromq.org/socket-api/#router-socket) socket."

"""
[XREP](https://zeromq.org/socket-api/#router-socket) socket.
!!! compat
This is a deprecated alias for [ZMQ.ROUTER](@ref).
"""
const XREP = ROUTER
"[UPSTREAM](https://zeromq.org/socket-api/#pull-socket) socket."

"""
[UPSTREAM](https://zeromq.org/socket-api/#pull-socket) socket.
!!! compat
This is a deprecated alias for [ZMQ.PULL](@ref).
"""
const UPSTREAM = PULL
"[DOWNSTREAM](https://zeromq.org/socket-api/#push-socket) socket."

"""
[DOWNSTREAM](https://zeromq.org/socket-api/#push-socket) socket.
!!! compat
This is a deprecated alias for [ZMQ.PUSH](@ref).
"""
const DOWNSTREAM = PUSH

#Message options
Expand Down
64 changes: 7 additions & 57 deletions src/message.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,13 @@ end

"""
High-level Message object for sending/receiving ZMQ messages in shared buffers.
Message()
Create an empty message (for receive).
---
Message(len::Integer)
Create a message with a given buffer size (for send).
---
Message(origin::Any, m::Ptr{T}, len::Integer) where {T}
Low-level function to create a message (for send) with an existing
data buffer, without making a copy. The origin parameter should
be the Julia object that is the origin of the data, so that
we can hold a reference to it until ZMQ is done with the buffer.
---
Message(m::String)
Create a message with a string as a buffer (for send). Note: the Message now
"owns" the string, it must not be resized, or even written to after the message
is sent.
---
Message(p::SubString{String})
Create a message with a sub-string as a buffer (for send). Note: the same
ownership semantics as for [`Message(m::String)`](@ref) apply.
---
Message(a::Array)
Create a message with an array as a buffer (for send). Note: the same
ownership semantics as for [`Message(m::String)`](@ref) apply.
---
Message(io::IOBuffer)
Create a message with an
[`IOBuffer`](https://docs.julialang.org/en/v1/base/io-network/#Base.IOBuffer) as
a buffer (for send). Note: the same ownership semantics as for
[`Message(m::String)`](@ref) apply.
"""
mutable struct Message <: AbstractArray{UInt8,1}
# Matching the declaration in the header: char _[64];
w_padding::_Message
handle::Ptr{Cvoid} # index into gc_protect, if any

"""
@doc """
Message()
Create an empty message (for receive).
Expand All @@ -96,7 +46,7 @@ mutable struct Message <: AbstractArray{UInt8,1}
return zmsg
end

"""
@doc """
Message(len::Integer)
Create a message with a given buffer size (for send).
Expand All @@ -112,7 +62,7 @@ mutable struct Message <: AbstractArray{UInt8,1}
return zmsg
end

"""
@doc """
Message(origin::Any, m::Ptr{T}, len::Integer) where {T}
Low-level function to create a message (for send) with an existing
Expand All @@ -134,7 +84,7 @@ mutable struct Message <: AbstractArray{UInt8,1}
return zmsg
end

"""
@doc """
Message(m::String)
Create a message with a string as a buffer (for send). Note: the Message now
Expand All @@ -143,7 +93,7 @@ mutable struct Message <: AbstractArray{UInt8,1}
"""
Message(m::String) = Message(m, pointer(m), sizeof(m))

"""
@doc """
Message(p::SubString{String})
Create a message with a sub-string as a buffer (for send). Note: the same
Expand All @@ -152,15 +102,15 @@ mutable struct Message <: AbstractArray{UInt8,1}
Message(p::SubString{String}) =
Message(p, pointer(p.string)+p.offset, sizeof(p))

"""
@doc """
Message(a::Array)
Create a message with an array as a buffer (for send). Note: the same
ownership semantics as for [`Message(m::String)`](@ref) apply.
"""
Message(a::Array) = Message(a, pointer(a), sizeof(a))

"""
@doc """
Message(io::IOBuffer)
Create a message with an
Expand Down
20 changes: 2 additions & 18 deletions src/socket.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
"""
A ZMQ socket.
Socket(typ::Integer)
Create a socket of a certain type.
---
Socket(ctx::Context, typ::Integer)
Create a socket in a given context.
---
Socket(f::Function, args...)
Do-block constructor.
"""
mutable struct Socket
data::Ptr{Cvoid}
pollfd::FDWatcher

"""
@doc """
Socket(ctx::Context, typ::Integer)
Create a socket in a given context.
Expand All @@ -38,7 +22,7 @@ mutable struct Socket
return socket
end

"""
@doc """
Socket(typ::Integer)
Create a socket of a certain type.
Expand Down

0 comments on commit 03cf2c1

Please sign in to comment.