diff --git a/stdlib/Sockets/docs/src/index.md b/stdlib/Sockets/docs/src/index.md index 710a95f350a4f..f993e83480eaa 100644 --- a/stdlib/Sockets/docs/src/index.md +++ b/stdlib/Sockets/docs/src/index.md @@ -5,6 +5,7 @@ DocTestSetup = :(using Sockets) ``` ```@docs +Sockets.Sockets Sockets.connect(::TCPSocket, ::Integer) Sockets.connect(::AbstractString) Sockets.listen(::Any) @@ -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 diff --git a/stdlib/Sockets/src/IPAddr.jl b/stdlib/Sockets/src/IPAddr.jl index 79f9df4f5bbc6..c77e1f9887064 100644 --- a/stdlib/Sockets/src/IPAddr.jl +++ b/stdlib/Sockets/src/IPAddr.jl @@ -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) @@ -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" @@ -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" @@ -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 diff --git a/stdlib/Sockets/src/Sockets.jl b/stdlib/Sockets/src/Sockets.jl index 5cf1d79e98aee..8f0a36bcf04d6 100644 --- a/stdlib/Sockets/src/Sockets.jl +++ b/stdlib/Sockets/src/Sockets.jl @@ -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