Skip to content

Commit 172219b

Browse files
committed
some SocketAddress
1 parent c77b908 commit 172219b

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

FlyingFox/Tests/HTTPServerTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ final class HTTPServerTests: XCTestCase {
439439

440440
extension HTTPServer {
441441

442-
static func make<A: SocketAddress>(address: A,
443-
timeout: TimeInterval = 15,
444-
logger: any Logging = defaultLogger(),
445-
handler: (any HTTPHandler)? = nil) -> HTTPServer {
442+
static func make(address: some SocketAddress,
443+
timeout: TimeInterval = 15,
444+
logger: any Logging = defaultLogger(),
445+
handler: (any HTTPHandler)? = nil) -> HTTPServer {
446446
HTTPServer(address: address,
447447
timeout: timeout,
448448
logger: logger,

FlyingSocks/Sources/AsyncSocket.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,23 @@ public struct AsyncSocket: Sendable {
7171
try socket.setFlags(.nonBlocking)
7272
}
7373

74-
public static func connected<A: SocketAddress>(to address: A) async throws -> Self {
75-
try await connected(to: address, pool: ClientPoolLoader.shared.getPool())
76-
}
77-
78-
public static func connected<A: SocketAddress>(to address: A, pool: some AsyncSocketPool) async throws -> Self {
79-
let socket = try Socket(domain: Int32(address.makeStorage().ss_family), type: Socket.stream)
80-
let asyncSocket = try AsyncSocket(socket: socket, pool: pool)
81-
try await asyncSocket.connect(to: address)
82-
return asyncSocket
74+
public static func connected(to address: some SocketAddress, timeout: TimeInterval = 5) async throws -> Self {
75+
try await connected(
76+
to: address,
77+
pool: ClientPoolLoader.shared.getPool(),
78+
timeout: timeout
79+
)
80+
}
81+
82+
public static func connected(to address: some SocketAddress,
83+
pool: some AsyncSocketPool,
84+
timeout: TimeInterval = 5) async throws -> Self {
85+
try await withThrowingTimeout(seconds: timeout) {
86+
let socket = try Socket(domain: Int32(address.makeStorage().ss_family), type: Socket.stream)
87+
let asyncSocket = try AsyncSocket(socket: socket, pool: pool)
88+
try await asyncSocket.connect(to: address)
89+
return asyncSocket
90+
}
8391
}
8492

8593
@Sendable
@@ -91,7 +99,7 @@ public struct AsyncSocket: Sendable {
9199
}
92100
}
93101

94-
public func connect<A: SocketAddress>(to address: A) async throws {
102+
public func connect(to address: some SocketAddress) async throws {
95103
return try await pool.loopUntilReady(for: [.write], on: socket) {
96104
try socket.connect(to: address)
97105
}

0 commit comments

Comments
 (0)