Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document undocumented exports and add Examples #31225

Merged
merged 2 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stdlib/Sockets/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DocTestSetup = :(using Sockets)
```

```@docs
Sockets.Sockets
Sockets.connect(::TCPSocket, ::Integer)
Sockets.connect(::AbstractString)
Sockets.listen(::Any)
Expand All @@ -16,8 +17,10 @@ Sockets.getalladdrinfo
Sockets.getnameinfo
Sockets.getsockname
Sockets.getpeername
Sockets.IPAddr
Sockets.IPv4
Sockets.IPv6
Sockets.@ip_str
Sockets.TCPSocket
Sockets.UDPSocket
Sockets.accept
Expand Down
21 changes: 21 additions & 0 deletions stdlib/Sockets/src/IPAddr.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

"""
IPAddr

Abstract supertype for IP addresses. [`IPv4`](@ref) and [`IPv6`](@ref) are subtypes of this.
"""
abstract type IPAddr end

Base.isless(a::T, b::T) where {T<:IPAddr} = isless(a.host, b.host)
Expand All @@ -25,6 +30,7 @@ end

Returns an IPv4 object from ip address `host` formatted as an [`Integer`](@ref).

# Examples
```jldoctest
julia> IPv4(3223256218)
ip"192.30.252.154"
Expand Down Expand Up @@ -77,6 +83,7 @@ end

Returns an IPv6 object from ip address `host` formatted as an [`Integer`](@ref).

# Examples
```jldoctest
julia> IPv6(3223256218)
ip"::c01e:fc9a"
Expand Down Expand Up @@ -241,6 +248,20 @@ function parse(::Type{IPAddr}, str::AbstractString)
end
end

"""
@ip_str str -> IPAddr

Parse `str` as an IP address.

# Examples
```jldoctest
julia> ip"127.0.0.1"
ip"127.0.0.1"

julia> @ip_str "2001:db8:0:0:0:0:2:1"
ip"2001:db8::2:1"
```
"""
macro ip_str(str)
return parse(IPAddr, str)
end
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

"""
Support for sockets. Provides [`IPAddr`](@ref) and subtypes, [`TCPSocket`](@ref), and [`UDPSocket`](@ref).
"""
module Sockets

export
Expand Down