diff --git a/Package.resolved b/Package.resolved index 5513488..33a113e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,15 +1,6 @@ { "object": { "pins": [ - { - "package": "Socket", - "repositoryURL": "https://github.com/OperatorFoundation/BlueSocket", - "state": { - "branch": null, - "revision": "90212ea8b66787c2d51d03527a04748ba6ee7679", - "version": "1.1.0" - } - }, { "package": "Chord", "repositoryURL": "https://github.com/OperatorFoundation/Chord", diff --git a/Package.swift b/Package.swift index 0fef594..b028149 100644 --- a/Package.swift +++ b/Package.swift @@ -11,16 +11,12 @@ let package = Package( .library( name: "Transmission", targets: ["Transmission"]), - .library( - name: "TransmissionLinux", - targets: ["TransmissionLinux"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), .package(url: "https://github.com/OperatorFoundation/Chord", from: "0.0.5"), .package(url: "https://github.com/OperatorFoundation/Datable", from: "3.0.3"), - .package(name: "Socket", url: "https://github.com/OperatorFoundation/BlueSocket", from: "1.1.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -28,15 +24,9 @@ let package = Package( .target( name: "Transmission", dependencies: ["Chord", "Datable"]), - .target( - name: "TransmissionLinux", - dependencies: ["Chord", "Socket"]), .testTarget( name: "TransmissionTests", dependencies: ["Transmission", "Datable"]), - .testTarget( - name: "TransmissionLinuxTests", - dependencies: ["TransmissionLinux", "Datable"]), ], swiftLanguageVersions: [.v5] ) diff --git a/Sources/TransmissionLinux/Connection.swift b/Sources/TransmissionLinux/Connection.swift deleted file mode 100644 index a31260b..0000000 --- a/Sources/TransmissionLinux/Connection.swift +++ /dev/null @@ -1,95 +0,0 @@ -import Foundation -import Socket -import Datable -import Chord - -public class Connection -{ - var connectLock = DispatchGroup() - var readLock = DispatchGroup() - var writeLock = DispatchGroup() - - let socket: Socket - var buffer: Data = Data() - - public init?(host: String, port: Int) - { - guard let socket = try? Socket.create() else {return nil} - self.socket = socket - - do - { - try self.socket.connect(to: host, port: Int32(port)) - } - catch - { - return nil - } - } - - public init(socket: Socket) - { - self.socket = socket - } - - public func read(size: Int) -> Data? - { - if size == 0 - { - return nil - } - - if size <= buffer.count - { - let result = Data(buffer[0.. Bool - { - let data = string.data - return write(data: data) - } - - public func write(data: Data) -> Bool - { - do - { - try self.socket.write(from: data) - } - catch - { - return false - } - - return true - } -} - -public enum ConnectionType -{ - case udp - case tcp -} diff --git a/Sources/TransmissionLinux/Listener.swift b/Sources/TransmissionLinux/Listener.swift deleted file mode 100644 index d8fbeff..0000000 --- a/Sources/TransmissionLinux/Listener.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Listener.swift -// -// -// Created by Dr. Brandon Wiley on 8/31/20. -// - -import Foundation -import Socket -import Chord - -public class Listener -{ - var socket: Socket - - public init?(port: Int) - { - guard let socket = try? Socket.create() else {return nil} - self.socket = socket - - do - { - try socket.listen(on: port) - } - catch - { - return nil - } - } - - public func accept() -> Connection? - { - guard let newConnection = try? self.socket.acceptClientConnection(invokeDelegate: false) else {return nil} - return Connection(socket: newConnection) - } -} diff --git a/Tests/TransmissionLinuxTests/TransmissionLinuxTests.swift b/Tests/TransmissionLinuxTests/TransmissionLinuxTests.swift deleted file mode 100644 index dd6ec78..0000000 --- a/Tests/TransmissionLinuxTests/TransmissionLinuxTests.swift +++ /dev/null @@ -1,47 +0,0 @@ -import XCTest -import Foundation -@testable import TransmissionLinux - -final class TransmissionTests: XCTestCase -{ - public func testConnection() - { - let lock = DispatchGroup() - let queue = DispatchQueue(label: "testing") - - lock.enter() - - queue.async - { - self.runServer(lock) - } - - lock.wait() - - runClient() - } - - func runServer(_ lock: DispatchGroup) - { - guard let listener = Listener(port: 1234) else {return} - lock.leave() - - guard let connection = listener.accept() else {return} - let _ = connection.read(size: 4) - let _ = connection.write(string: "back") - } - - func runClient() - { - let connection = Connection(host: "127.0.0.1", port: 1234) - XCTAssertNotNil(connection) - - let writeResult = connection!.write(string: "test") - XCTAssertTrue(writeResult) - - let result = connection!.read(size: 4) - XCTAssertNotNil(result) - - XCTAssertEqual(result!, "back") - } -}