Skip to content

Commit

Permalink
Update from Hummingbird Project Template (#7)
Browse files Browse the repository at this point in the history
* Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef

* run swift-format

* Remove .swiftformat

---------

Co-authored-by: adam-fowler <[email protected]>
Co-authored-by: Adam Fowler <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2024
1 parent 76e02f8 commit 1d60de6
Show file tree
Hide file tree
Showing 20 changed files with 384 additions and 209 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ concurrency:

jobs:
validate:
runs-on: macOS-latest
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
brew install mint
mint install NickLockwood/[email protected] --no-link
- name: run script
run: ./scripts/validate.sh
63 changes: 63 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 150,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"multiElementCollectionTrailingCommas" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
26 changes: 0 additions & 26 deletions .swiftformat

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The main development branch of the repository is `main`.

### Formatting

We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.53.10.
We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted.
65 changes: 40 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,47 @@ let package = Package(
.package(url: "https://github.com/swift-server/swift-service-lifecycle", from: "2.0.0"),
],
targets: [
.target(name: "WSClient", dependencies: [
.byName(name: "WSCore"),
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOHTTPTypesHTTP1", package: "swift-nio-extras"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "NIOWebSocket", package: "swift-nio"),
], swiftSettings: swiftSettings),
.target(name: "WSCore", dependencies: [
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOWebSocket", package: "swift-nio"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
], swiftSettings: swiftSettings),
.target(name: "WSCompression", dependencies: [
.byName(name: "WSCore"),
.product(name: "CompressNIO", package: "compress-nio"),
], swiftSettings: swiftSettings),
.target(
name: "WSClient",
dependencies: [
.byName(name: "WSCore"),
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOHTTPTypesHTTP1", package: "swift-nio-extras"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "NIOWebSocket", package: "swift-nio"),
],
swiftSettings: swiftSettings
),
.target(
name: "WSCore",
dependencies: [
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOWebSocket", package: "swift-nio"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
],
swiftSettings: swiftSettings
),
.target(
name: "WSCompression",
dependencies: [
.byName(name: "WSCore"),
.product(name: "CompressNIO", package: "compress-nio"),
],
swiftSettings: swiftSettings
),

.testTarget(name: "WebSocketTests", dependencies: [
.byName(name: "WSClient"),
.byName(name: "WSCompression"),
]),
.testTarget(
name: "WebSocketTests",
dependencies: [
.byName(name: "WSClient"),
.byName(name: "WSCompression"),
]
),
],
swiftLanguageVersions: [.v5, .version("6")]
)
20 changes: 13 additions & 7 deletions Sources/WSClient/Client/ClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import Logging
import NIOCore
import NIOPosix
import NIOWebSocket

#if canImport(Network)
import Network
import NIOTransportServices
#endif
import NIOWebSocket

/// A generic client connection to a server.
///
Expand Down Expand Up @@ -104,7 +105,9 @@ public struct ClientConnection<ClientChannel: ClientConnectionChannel>: Sendable
bootstrap = tsBootstrap
} else {
#if os(iOS) || os(tvOS)
self.logger.warning("Running BSD sockets on iOS or tvOS is not recommended. Please use NIOTSEventLoopGroup, to run with the Network framework")
self.logger.warning(
"Running BSD sockets on iOS or tvOS is not recommended. Please use NIOTSEventLoopGroup, to run with the Network framework"
)
#endif
bootstrap = self.createSocketsBootstrap()
}
Expand All @@ -117,13 +120,15 @@ public struct ClientConnection<ClientChannel: ClientConnectionChannel>: Sendable
do {
switch address.value {
case .hostname(let host, let port):
result = try await bootstrap
result =
try await bootstrap
.connect(host: host, port: port) { channel in
clientChannel.setup(channel: channel, logger: self.logger)
}
self.logger.debug("Client connnected to \(host):\(port)")
case .unixDomainSocket(let path):
result = try await bootstrap
result =
try await bootstrap
.connect(unixDomainSocketPath: path) { channel in
clientChannel.setup(channel: channel, logger: self.logger)
}
Expand All @@ -137,15 +142,16 @@ public struct ClientConnection<ClientChannel: ClientConnectionChannel>: Sendable

/// create a BSD sockets based bootstrap
private func createSocketsBootstrap() -> ClientBootstrap {
return ClientBootstrap(group: self.eventLoopGroup)
ClientBootstrap(group: self.eventLoopGroup)
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
}

#if canImport(Network)
/// create a NIOTransportServices bootstrap using Network.framework
private func createTSBootstrap() -> NIOTSConnectionBootstrap? {
guard let bootstrap = NIOTSConnectionBootstrap(validatingGroup: self.eventLoopGroup)?
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
guard
let bootstrap = NIOTSConnectionBootstrap(validatingGroup: self.eventLoopGroup)?
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
else {
return nil
}
Expand Down
Loading

0 comments on commit 1d60de6

Please sign in to comment.