-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix preview * Format * Fix * Fix * Fix * Fix * Delete swiftlint.yaml
- Loading branch information
Showing
16 changed files
with
809 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/bin/bash | ||
dirs=( | ||
Packages | ||
FragmentedRecordWriter | ||
FragmentedRecordWriterTests | ||
Recoreon | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// swift-tools-version: 5.10 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "HLSServer", | ||
platforms: [.iOS(.v17)], | ||
products: [ | ||
.library( | ||
name: "HLSServer", | ||
targets: ["HLSServer"] | ||
) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-nio.git", exact: "2.68.0") | ||
], | ||
targets: [ | ||
.target( | ||
name: "HLSServer", | ||
dependencies: [ | ||
.product(name: "NIOCore", package: "swift-nio"), | ||
.product(name: "NIOHTTP1", package: "swift-nio"), | ||
.product(name: "NIOPosix", package: "swift-nio"), | ||
] | ||
), | ||
.testTarget( | ||
name: "HLSServerTests", | ||
dependencies: ["HLSServer"] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Derived from https://github.com/apple/swift-nio/blob/main/Sources/NIOHTTP1Server/main.swift | ||
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import NIOCore | ||
import NIOHTTP1 | ||
import NIOPosix | ||
|
||
enum HLSServerError: Error { | ||
case localAddressPortNotAvailable | ||
} | ||
|
||
public struct HLSServer { | ||
public let port: Int | ||
|
||
private let channel: Channel | ||
|
||
public init(htdocs: String, host: String, port: Int = 0) throws { | ||
let fileIO = NonBlockingFileIO(threadPool: .singleton) | ||
|
||
func childChannelInitializer(channel: Channel) -> EventLoopFuture<Void> { | ||
channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMap { | ||
channel.pipeline.addHandler(HTTPHandler(fileIO: fileIO, htdocsPath: htdocs)) | ||
} | ||
} | ||
|
||
let socketBootstrap = ServerBootstrap(group: MultiThreadedEventLoopGroup.singleton) | ||
// Specify backlog and enable SO_REUSEADDR for the server itself | ||
.serverChannelOption(ChannelOptions.backlog, value: 256) | ||
.serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) | ||
|
||
// Set the handlers that are applied to the accepted Channels | ||
.childChannelInitializer(childChannelInitializer(channel:)) | ||
|
||
// Enable SO_REUSEADDR for the accepted Channels | ||
.childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) | ||
.childChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) | ||
.childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true) | ||
|
||
channel = try socketBootstrap.bind(host: host, port: port).wait() | ||
|
||
guard let port = channel.localAddress?.port else { | ||
throw HLSServerError.localAddressPortNotAvailable | ||
} | ||
|
||
self.port = port | ||
} | ||
|
||
public func close() async throws { | ||
try await channel.eventLoop.shutdownGracefully() | ||
} | ||
|
||
} |
Oops, something went wrong.