Skip to content

Commit

Permalink
accept sockaddr_storage in bind() and connect()
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 12, 2024
1 parent 9c7be02 commit a20cc6e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions FlyingSocks/Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public struct Socket: Sendable, Hashable {
return option.makeValue(from: valuePtr.pointee)
}

public func bind<A: SocketAddress>(to address: A) throws {
public func bind(to address: some SocketAddress) throws {
var addr = address
let result = withUnsafePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
Socket.bind(file.rawValue, $0, socklen_t(MemoryLayout<A>.size))
Socket.bind(file.rawValue, $0, address.size)
}
}
guard result >= 0 else {
Expand Down Expand Up @@ -170,11 +170,11 @@ public struct Socket: Sendable, Hashable {
return (newFile, addr)
}

public func connect<A: SocketAddress>(to address: A) throws {
public func connect(to address: some SocketAddress) throws {
var addr = address
let result = withUnsafePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
Socket.connect(file.rawValue, $0, socklen_t(MemoryLayout<A>.size))
Socket.connect(file.rawValue, $0, address.size)
}
}
guard result >= 0 || errno == EISCONN else {
Expand Down

0 comments on commit a20cc6e

Please sign in to comment.