Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Mar 9, 2024
1 parent eea6e00 commit 5c5739d
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 100 deletions.
6 changes: 3 additions & 3 deletions FlyingFox/Sources/HTTPLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public extension Logging where Self == PrintLogger {
}
}

extension HTTPServer {
public extension HTTPServer {

public static func defaultLogger(category: String = "FlyingFox") -> some Logging {
static func defaultLogger(category: String = "FlyingFox") -> any Logging {
guard #available(macOS 11.0, iOS 14.0, tvOS 14.0, *) else {
return .print(category: category)
}
#if canImport(OSLog)
return .print(category: category)
return .oslog(category: category)
#else
return .print(category: category)
#endif
Expand Down
8 changes: 4 additions & 4 deletions FlyingFox/Sources/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final actor HTTPServer {
public init<A: SocketAddress>(address: A,
timeout: TimeInterval = 15,
pool: some AsyncSocketPool = defaultPool(),
logger: some Logging = defaultLogger(),
logger: any Logging = defaultLogger(),
handler: (any HTTPHandler)? = nil) {
self.address = address.makeStorage()
self.timeout = timeout
Expand Down Expand Up @@ -130,7 +130,7 @@ public final actor HTTPServer {
func start(on socket: Socket, pool: some AsyncSocketPool) async throws {
let asyncSocket = try AsyncSocket(socket: socket, pool: pool)

return try await withThrowingTaskGroup(of: Void.self) { group in
try await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
try await pool.run()
}
Expand Down Expand Up @@ -248,7 +248,7 @@ public extension HTTPServer {
init(port: UInt16,
timeout: TimeInterval = 15,
pool: some AsyncSocketPool = defaultPool(),
logger: some Logging = defaultLogger(),
logger: any Logging = defaultLogger(),
handler: (any HTTPHandler)? = nil) {
#if canImport(WinSDK)
let address = sockaddr_in.inet(port: port)
Expand All @@ -265,7 +265,7 @@ public extension HTTPServer {
init(port: UInt16,
timeout: TimeInterval = 15,
pool: some AsyncSocketPool = defaultPool(),
logger: some Logging = defaultLogger(),
logger: any Logging = defaultLogger(),
handler: @Sendable @escaping (HTTPRequest) async throws -> HTTPResponse) {
self.init(port: port,
timeout: timeout,
Expand Down
10 changes: 6 additions & 4 deletions FlyingFox/Sources/WebSocket/WSHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ public struct MessageFrameWSHandler: WSHandler {
return AsyncStream.protocolFrames(from: serverFrames)
}

func start<S: AsyncSequence>(framesIn: S,
framesOut: AsyncThrowingStream<WSFrame, any Error>.Continuation,
messagesIn: AsyncStream<WSMessage>.Continuation,
messagesOut: AsyncStream<WSMessage>) async where S.Element == WSFrame {
func start<S: AsyncSequence & Sendable>(
framesIn: S,
framesOut: AsyncThrowingStream<WSFrame, any Error>.Continuation,
messagesIn: AsyncStream<WSMessage>.Continuation,
messagesOut: AsyncStream<WSMessage>
) async where S.Element == WSFrame {
await withTaskGroup(of: Void.self) { group in
group.addTask {
do {
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/AsyncSocketTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension AsyncSocket {
try await make(pool: .client)
}

static func make(pool: AsyncSocketPool) throws -> AsyncSocket {
static func make(pool: some AsyncSocketPool) throws -> AsyncSocket {
let socket = try Socket(domain: AF_UNIX, type: Socket.stream)
return try AsyncSocket(socket: socket, pool: pool)
}
Expand All @@ -48,7 +48,7 @@ extension AsyncSocket {
try await makePair(pool: .client)
}

static func makePair(pool: AsyncSocketPool) throws -> (AsyncSocket, AsyncSocket) {
static func makePair(pool: some AsyncSocketPool) throws -> (AsyncSocket, AsyncSocket) {
let (file1, file2) = Socket.socketpair(AF_UNIX, Socket.stream, 0)
guard file1.rawValue > -1, file2.rawValue > -1 else {
throw SocketError.makeFailed("SocketPair")
Expand Down
2 changes: 1 addition & 1 deletion FlyingFox/Tests/HTTPConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ final class HTTPConnectionTests: XCTestCase {

private extension HTTPConnection {
init(socket: AsyncSocket) {
self.init(socket: socket, logger: nil)
self.init(socket: socket, logger: .disabled)
}
}

Expand Down
2 changes: 1 addition & 1 deletion FlyingFox/Tests/HTTPResponse+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension HTTPResponse {
}

static func make(headers: [HTTPHeader: String] = [:],
webSocket handler: WSHandler) -> Self {
webSocket handler: some WSHandler) -> Self {
HTTPResponse(headers: headers,
webSocket: handler)
}
Expand Down
26 changes: 13 additions & 13 deletions FlyingFox/Tests/HTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class HTTPServerTests: XCTestCase {
}

@discardableResult
func startServer(_ server: HTTPServer) async throws -> Task<Void, Error> {
func startServer(_ server: HTTPServer) async throws -> Task<Void, any Error> {
self.stopServer = server
let task = Task { try await server.start() }
try await server.waitUntilListening()
Expand Down Expand Up @@ -351,14 +351,14 @@ final class HTTPServerTests: XCTestCase {
}
#endif

func testDefaultLoggerFallback_IsPrintLogger() async throws {
XCTAssertTrue(HTTPServer.defaultLogger(forceFallback: true) is PrintLogger)
}
// func testDefaultLoggerFallback_IsPrintLogger() async throws {
// XCTAssertTrue(HTTPServer.defaultLogger(forceFallback: true) is PrintLogger)
// }

func testWaitUntilListing_WaitsUntil_SocketIsListening() async {
let server = HTTPServer.make()

let waiting = Task<Bool, Error> {
let waiting = Task<Bool, any Error> {
try await server.waitUntilListening()
return true
}
Expand All @@ -372,7 +372,7 @@ final class HTTPServerTests: XCTestCase {
func testWaitUntilListing_ThrowsWhen_TaskIsCancelled() async {
let server = HTTPServer.make()

let waiting = Task<Bool, Error> {
let waiting = Task<Bool, any Error> {
try await server.waitUntilListening()
return true
}
Expand All @@ -384,21 +384,21 @@ final class HTTPServerTests: XCTestCase {
func testWaitUntilListing_ThrowsWhen_TimeoutExpires() async throws {
let server = HTTPServer.make()

let waiting = Task<Bool, Error> {
let waiting = Task<Bool, any Error> {
try await server.waitUntilListening(timeout: 1)
return true
}

await AsyncAssertThrowsError(try await waiting.value, of: Error.self)
await AsyncAssertThrowsError(try await waiting.value, of: (any Error).self)
}
}

extension HTTPServer {

static func make<A: SocketAddress>(address: A,
timeout: TimeInterval = 15,
logger: Logging? = defaultLogger(),
handler: HTTPHandler? = nil) -> HTTPServer {
logger: any Logging = defaultLogger(),
handler: (any HTTPHandler)? = nil) -> HTTPServer {
HTTPServer(address: address,
timeout: timeout,
logger: logger,
Expand All @@ -407,8 +407,8 @@ extension HTTPServer {

static func make(port: UInt16 = 0,
timeout: TimeInterval = 15,
logger: Logging? = nil,
handler: HTTPHandler? = nil) -> HTTPServer {
logger: some Logging = .disabled,
handler: (any HTTPHandler)? = nil) -> HTTPServer {
HTTPServer(port: port,
timeout: timeout,
logger: logger,
Expand All @@ -417,7 +417,7 @@ extension HTTPServer {

static func make(port: UInt16 = 0,
timeout: TimeInterval = 15,
logger: Logging? = nil,
logger: some Logging = .disabled,
handler: @Sendable @escaping (HTTPRequest) async throws -> HTTPResponse) -> HTTPServer {
HTTPServer(port: port,
timeout: timeout,
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/Handlers/DirectoryHTTPHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class DirectoryHTTPHandlerTests: XCTestCase {
}

func testDirectoryHandler_ReturnsSubDirectoryFile() async throws {
let handler: HTTPHandler = .directory(for: .module, subPath: "Stubs", serverPath: "server/path")
let handler: some HTTPHandler = .directory(for: .module, subPath: "Stubs", serverPath: "server/path")

let response = try await handler.handleRequest(.make(path: "server/path/subdir/vinegar.json"))
XCTAssertEqual(response.statusCode, .ok)
Expand All @@ -72,7 +72,7 @@ final class DirectoryHTTPHandlerTests: XCTestCase {
}

func testDirectoryHandler_Returns404WhenFileDoesNotExist() async throws {
let handler: HTTPHandler = .directory(for: .module, subPath: "Stubs", serverPath: "server/path")
let handler: some HTTPHandler = .directory(for: .module, subPath: "Stubs", serverPath: "server/path")

let response = try await handler.handleRequest(.make())
XCTAssertEqual(response.statusCode, .notFound)
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/Handlers/HTTPHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class HTTPHandlerTests: XCTestCase {
//MARK: - HTTPHandler

func testUnhandledHandler_ThrowsError() async {
let handler: HTTPHandler = .unhandled()
let handler: some HTTPHandler = .unhandled()

await AsyncAssertThrowsError(try await handler.handleRequest(.make()), of: HTTPUnhandledError.self)
}
Expand Down Expand Up @@ -75,7 +75,7 @@ final class HTTPHandlerTests: XCTestCase {
}

func testFileHandler_Returns200WithData() async throws {
let handler: HTTPHandler = .file(named: "Stubs/fish.json", in: .module)
let handler: some HTTPHandler = .file(named: "Stubs/fish.json", in: .module)

let response = try await handler.handleRequest(.make())
XCTAssertEqual(response.statusCode, .ok)
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/Handlers/WebSocketHTTPHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ private extension Dictionary where Key == HTTPHeader, Value == String {
}

private extension WebSocketHTTPHandler {
static func make(handler: WSHandler = MockHandler(), accepts methods: Set<HTTPMethod> = [.GET]) -> WebSocketHTTPHandler {
static func make(handler: some WSHandler = MockHandler(), accepts methods: Set<HTTPMethod> = [.GET]) -> WebSocketHTTPHandler {
WebSocketHTTPHandler(handler: MockHandler(), accepts: methods)
}
}

private struct MockHandler: WSHandler {
func makeFrames(for client: AsyncThrowingStream<WSFrame, Error>) async throws -> AsyncStream<WSFrame> {
func makeFrames(for client: AsyncThrowingStream<WSFrame, any Error>) async throws -> AsyncStream<WSFrame> {
var iterator = client.makeAsyncIterator()
return AsyncStream<WSFrame> {
try? await iterator.next()
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/WebSocket/AsyncStream+WSFrameTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class WSFrameSequenceTests: XCTestCase {

func testProtocolFrames_CatchErrors_AndCloseStream() async throws {
var continuation: AsyncThrowingStream<WSFrame, Error>.Continuation!
let stream = AsyncThrowingStream<WSFrame, Error> {
let stream = AsyncThrowingStream<WSFrame, any Error> {
continuation = $0
}

Expand All @@ -76,7 +76,7 @@ extension WSFrame {
static let pong = WSFrame.make(opcode: .pong)
}

extension AsyncThrowingStream where Element == WSFrame, Failure == Error {
extension AsyncThrowingStream where Element == WSFrame, Failure == any Error {
static func make(_ frames: [WSFrame]) -> Self {
let bytes = ConsumingAsyncSequence(frames.flatMap(WSFrameEncoder.encodeFrame))
return AsyncThrowingStream.decodingFrames(from: bytes)
Expand Down
2 changes: 1 addition & 1 deletion FlyingFox/Tests/WebSocket/WSFrameValidatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class WSFrameValidatorTests: XCTestCase {

private extension WSFrameValidator {

static func validate(_ frames: [WSFrame]) async throws -> AsyncThrowingStream<WSFrame, Swift.Error> {
static func validate(_ frames: [WSFrame]) async throws -> AsyncThrowingStream<WSFrame, any Swift.Error> {
var iterator = validateFrames(from: AsyncThrowingStream.make(frames)).makeAsyncIterator()
return AsyncThrowingStream { try await iterator.next() }
}
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/WebSocket/WSHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final class WSHandlerTests: XCTestCase {

extension MessageFrameWSHandler {

static func make(handler: WSMessageHandler = Messages(),
static func make(handler: some WSMessageHandler = Messages(),
frameSize: Int = 1024) -> Self {
MessageFrameWSHandler(handler: handler,
frameSize: frameSize)
Expand All @@ -140,7 +140,7 @@ extension MessageFrameWSHandler {
}
}

private final class Messages: WSMessageHandler, @unchecked Sendable {
final class Messages: WSMessageHandler, @unchecked Sendable {

var input: AsyncStream<WSMessage>!
var output: AsyncStream<WSMessage>.Continuation!
Expand Down
31 changes: 20 additions & 11 deletions FlyingSocks/Sources/Logging+OSLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,35 @@ public struct OSLogLogger: Logging, @unchecked Sendable {
self.logger = logger
}

public func logDebug(_ debug: String) {
logger.debug("\(debug, privacy: .public)")
public func logDebug(_ debug: @autoclosure () -> String) {
withoutActuallyEscaping(debug) { debug in
logger.debug("\(debug(), privacy: .public)")
}
}

public func logInfo(_ info: String) {
logger.info("\(info, privacy: .public)")
public func logInfo(_ info: @autoclosure () -> String) {
withoutActuallyEscaping(info) { info in
logger.info("\(info(), privacy: .public)")
}
}

public func logWarning(_ warning: String) {
logger.warning("\(warning, privacy: .public)")
public func logWarning(_ warning: @autoclosure () -> String) {
withoutActuallyEscaping(warning) { warning in
logger.warning("\(warning(), privacy: .public)")
}
}

public func logError(_ error: String) {
logger.error("\(error, privacy: .public)")
public func logError(_ error: @autoclosure () -> String) {
withoutActuallyEscaping(error) { error in
logger.error("\(error(), privacy: .public)")
}
}

public func logCritical(_ critical: String) {
logger.critical("\(critical, privacy: .public)")
public func logCritical(_ critical: @autoclosure () -> String) {
withoutActuallyEscaping(critical) { critical in
logger.error("\(critical(), privacy: .public)")
}
}

}

@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)
Expand Down
Loading

0 comments on commit 5c5739d

Please sign in to comment.