Skip to content

Commit a20cc6e

Browse files
committed
accept sockaddr_storage in bind() and connect()
1 parent 9c7be02 commit a20cc6e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

FlyingSocks/Sources/Socket.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ public struct Socket: Sendable, Hashable {
9999
return option.makeValue(from: valuePtr.pointee)
100100
}
101101

102-
public func bind<A: SocketAddress>(to address: A) throws {
102+
public func bind(to address: some SocketAddress) throws {
103103
var addr = address
104104
let result = withUnsafePointer(to: &addr) {
105105
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
106-
Socket.bind(file.rawValue, $0, socklen_t(MemoryLayout<A>.size))
106+
Socket.bind(file.rawValue, $0, address.size)
107107
}
108108
}
109109
guard result >= 0 else {
@@ -170,11 +170,11 @@ public struct Socket: Sendable, Hashable {
170170
return (newFile, addr)
171171
}
172172

173-
public func connect<A: SocketAddress>(to address: A) throws {
173+
public func connect(to address: some SocketAddress) throws {
174174
var addr = address
175175
let result = withUnsafePointer(to: &addr) {
176176
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
177-
Socket.connect(file.rawValue, $0, socklen_t(MemoryLayout<A>.size))
177+
Socket.connect(file.rawValue, $0, address.size)
178178
}
179179
}
180180
guard result >= 0 || errno == EISCONN else {

0 commit comments

Comments
 (0)