From d7ae7ebe452a34f20faf7e82ea9fe53a0dab6822 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:01:42 +0100 Subject: [PATCH 01/17] Add spm support --- Package.swift | 28 +++ Sources/{ => SwiftSocket}/Result.swift | 0 Sources/{ => SwiftSocket}/Socket.swift | 0 .../Supporting Files}/Info-tvOS.plist | 0 .../Supporting Files}/Info.plist | 0 .../Supporting Files}/SwiftSocket.h | 0 .../TCPSocket}/TCPClient.swift | 0 .../{ => SwiftSocket/TCPSocket}/ytcpsocket.c | 0 .../UDPSocket}/UDPClient.swift | 0 .../{ => SwiftSocket/UDPSocket}/yudpsocket.c | 0 SwiftSocket.xcodeproj/project.pbxproj | 200 ++++++++---------- .../xcschemes/SwiftSocket iOS.xcscheme | 6 +- .../xcschemes/SwiftSocket macOS.xcscheme | 6 +- .../xcschemes/SwiftSocket tvOS.xcscheme | 6 +- Tests/LinuxMain.swift | 7 + Tests/SwiftSocketTests/SwiftSocketTests.swift | 15 ++ Tests/SwiftSocketTests/XCTestManifests.swift | 9 + 17 files changed, 155 insertions(+), 122 deletions(-) create mode 100644 Package.swift rename Sources/{ => SwiftSocket}/Result.swift (100%) rename Sources/{ => SwiftSocket}/Socket.swift (100%) rename Sources/{ => SwiftSocket/Supporting Files}/Info-tvOS.plist (100%) rename Sources/{ => SwiftSocket/Supporting Files}/Info.plist (100%) rename Sources/{ => SwiftSocket/Supporting Files}/SwiftSocket.h (100%) rename Sources/{ => SwiftSocket/TCPSocket}/TCPClient.swift (100%) rename Sources/{ => SwiftSocket/TCPSocket}/ytcpsocket.c (100%) rename Sources/{ => SwiftSocket/UDPSocket}/UDPClient.swift (100%) rename Sources/{ => SwiftSocket/UDPSocket}/yudpsocket.c (100%) create mode 100644 Tests/LinuxMain.swift create mode 100644 Tests/SwiftSocketTests/SwiftSocketTests.swift create mode 100644 Tests/SwiftSocketTests/XCTestManifests.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..4608b5b --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SwiftSocket", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "SwiftSocket", + targets: ["SwiftSocket"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "SwiftSocket", + dependencies: []), + .testTarget( + name: "SwiftSocketTests", + dependencies: ["SwiftSocket"]), + ] +) diff --git a/Sources/Result.swift b/Sources/SwiftSocket/Result.swift similarity index 100% rename from Sources/Result.swift rename to Sources/SwiftSocket/Result.swift diff --git a/Sources/Socket.swift b/Sources/SwiftSocket/Socket.swift similarity index 100% rename from Sources/Socket.swift rename to Sources/SwiftSocket/Socket.swift diff --git a/Sources/Info-tvOS.plist b/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist similarity index 100% rename from Sources/Info-tvOS.plist rename to Sources/SwiftSocket/Supporting Files/Info-tvOS.plist diff --git a/Sources/Info.plist b/Sources/SwiftSocket/Supporting Files/Info.plist similarity index 100% rename from Sources/Info.plist rename to Sources/SwiftSocket/Supporting Files/Info.plist diff --git a/Sources/SwiftSocket.h b/Sources/SwiftSocket/Supporting Files/SwiftSocket.h similarity index 100% rename from Sources/SwiftSocket.h rename to Sources/SwiftSocket/Supporting Files/SwiftSocket.h diff --git a/Sources/TCPClient.swift b/Sources/SwiftSocket/TCPSocket/TCPClient.swift similarity index 100% rename from Sources/TCPClient.swift rename to Sources/SwiftSocket/TCPSocket/TCPClient.swift diff --git a/Sources/ytcpsocket.c b/Sources/SwiftSocket/TCPSocket/ytcpsocket.c similarity index 100% rename from Sources/ytcpsocket.c rename to Sources/SwiftSocket/TCPSocket/ytcpsocket.c diff --git a/Sources/UDPClient.swift b/Sources/SwiftSocket/UDPSocket/UDPClient.swift similarity index 100% rename from Sources/UDPClient.swift rename to Sources/SwiftSocket/UDPSocket/UDPClient.swift diff --git a/Sources/yudpsocket.c b/Sources/SwiftSocket/UDPSocket/yudpsocket.c similarity index 100% rename from Sources/yudpsocket.c rename to Sources/SwiftSocket/UDPSocket/yudpsocket.c diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index 0e42045..ecf06c7 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -7,45 +7,25 @@ objects = { /* Begin PBXBuildFile section */ - 3723138F1DCF84CA0042DA87 /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 372313921DCF84D80042DA87 /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313901DCF84D80042DA87 /* UDPClient.swift */; }; - 372313931DCF84D80042DA87 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313911DCF84D80042DA87 /* yudpsocket.c */; }; - 372313961DCF84E30042DA87 /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313941DCF84E30042DA87 /* TCPClient.swift */; }; - 372313971DCF84E30042DA87 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313951DCF84E30042DA87 /* ytcpsocket.c */; }; - 3723139A1DCF84EC0042DA87 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313981DCF84EC0042DA87 /* Result.swift */; }; - 3723139B1DCF84EC0042DA87 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313991DCF84EC0042DA87 /* Socket.swift */; }; - 3723139C1DCF85270042DA87 /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 37454ED71E0615FE00800AE5 /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 37454ED81E06163C00800AE5 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313981DCF84EC0042DA87 /* Result.swift */; }; - 37454ED91E06163C00800AE5 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313991DCF84EC0042DA87 /* Socket.swift */; }; - 37454EDA1E06163C00800AE5 /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313941DCF84E30042DA87 /* TCPClient.swift */; }; - 37454EDB1E06163C00800AE5 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313951DCF84E30042DA87 /* ytcpsocket.c */; }; - 37454EDC1E06163C00800AE5 /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313901DCF84D80042DA87 /* UDPClient.swift */; }; - 37454EDD1E06163C00800AE5 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313911DCF84D80042DA87 /* yudpsocket.c */; }; - 37454EDF1E06163D00800AE5 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313981DCF84EC0042DA87 /* Result.swift */; }; - 37454EE01E06163D00800AE5 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313991DCF84EC0042DA87 /* Socket.swift */; }; - 37454EE11E06163D00800AE5 /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313941DCF84E30042DA87 /* TCPClient.swift */; }; - 37454EE21E06163D00800AE5 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313951DCF84E30042DA87 /* ytcpsocket.c */; }; - 37454EE31E06163D00800AE5 /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313901DCF84D80042DA87 /* UDPClient.swift */; }; - 37454EE41E06163D00800AE5 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313911DCF84D80042DA87 /* yudpsocket.c */; }; 375C48301DDC4C56008C701D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375C482F1DDC4C56008C701D /* AppDelegate.swift */; }; 375C48321DDC4C56008C701D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375C48311DDC4C56008C701D /* ViewController.swift */; }; 375C48351DDC4C56008C701D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48331DDC4C56008C701D /* Main.storyboard */; }; 375C48371DDC4C56008C701D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 375C48361DDC4C56008C701D /* Assets.xcassets */; }; 375C483A1DDC4C56008C701D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48381DDC4C56008C701D /* LaunchScreen.storyboard */; }; + 56AE7B4425CD3F940068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3B25CD3F940068681D /* yudpsocket.c */; }; + 56AE7B4525CD3F940068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3C25CD3F940068681D /* ytcpsocket.c */; }; + 56AE7B4625CD3F940068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; + 56AE7B4725CD3F940068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; + 56AE7B4825CD3F940068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 56AE7B4925CD3F940068681D /* Info-tvOS.plist in Resources */ = {isa = PBXBuildFile; fileRef = 56AE7B4025CD3F940068681D /* Info-tvOS.plist */; }; + 56AE7B4A25CD3F940068681D /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4125CD3F940068681D /* UDPClient.swift */; }; + 56AE7B4C25CD3F940068681D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4325CD3F940068681D /* Socket.swift */; }; + 56AE7B7025CD40690068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 56AE7B7525CD406E0068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 3723138C1DCF84CA0042DA87 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sources/Info.plist; sourceTree = SOURCE_ROOT; }; - 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SwiftSocket.h; path = Sources/SwiftSocket.h; sourceTree = SOURCE_ROOT; }; - 372313901DCF84D80042DA87 /* UDPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UDPClient.swift; path = Sources/UDPClient.swift; sourceTree = SOURCE_ROOT; }; - 372313911DCF84D80042DA87 /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = yudpsocket.c; path = Sources/yudpsocket.c; sourceTree = SOURCE_ROOT; }; - 372313941DCF84E30042DA87 /* TCPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TCPClient.swift; path = Sources/TCPClient.swift; sourceTree = SOURCE_ROOT; }; - 372313951DCF84E30042DA87 /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ytcpsocket.c; path = Sources/ytcpsocket.c; sourceTree = SOURCE_ROOT; }; - 372313981DCF84EC0042DA87 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Result.swift; path = Sources/Result.swift; sourceTree = SOURCE_ROOT; }; - 372313991DCF84EC0042DA87 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Socket.swift; path = Sources/Socket.swift; sourceTree = SOURCE_ROOT; }; 37454ECA1E06158200800AE5 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 37454EE81E0617F300800AE5 /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "Sources/Info-tvOS.plist"; sourceTree = SOURCE_ROOT; }; 375C482D1DDC4C56008C701D /* iOS Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 375C482F1DDC4C56008C701D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 375C48311DDC4C56008C701D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -55,6 +35,15 @@ 375C483B1DDC4C56008C701D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 377DAA691DCDE40200009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 377DAA761DCDE45D00009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 56AE7B3B25CD3F940068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; + 56AE7B3C25CD3F940068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; + 56AE7B3D25CD3F940068681D /* TCPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCPClient.swift; sourceTree = ""; }; + 56AE7B3E25CD3F940068681D /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; + 56AE7B3F25CD3F940068681D /* SwiftSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftSocket.h; sourceTree = ""; }; + 56AE7B4025CD3F940068681D /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; + 56AE7B4125CD3F940068681D /* UDPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UDPClient.swift; sourceTree = ""; }; + 56AE7B4225CD3F940068681D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 56AE7B4325CD3F940068681D /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -89,24 +78,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 375BC51D1DCDE86B006AD8F6 /* TCPSocket */ = { - isa = PBXGroup; - children = ( - 372313941DCF84E30042DA87 /* TCPClient.swift */, - 372313951DCF84E30042DA87 /* ytcpsocket.c */, - ); - name = TCPSocket; - sourceTree = ""; - }; - 375BC51E1DCDE878006AD8F6 /* UDPSocket */ = { - isa = PBXGroup; - children = ( - 372313901DCF84D80042DA87 /* UDPClient.swift */, - 372313911DCF84D80042DA87 /* yudpsocket.c */, - ); - name = UDPSocket; - sourceTree = ""; - }; 375C482E1DDC4C56008C701D /* iOS Example */ = { isa = PBXGroup; children = ( @@ -120,21 +91,10 @@ path = "iOS Example"; sourceTree = ""; }; - 377DAA6A1DCDE40200009697 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 3723138C1DCF84CA0042DA87 /* Info.plist */, - 37454EE81E0617F300800AE5 /* Info-tvOS.plist */, - 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */, - ); - name = "Supporting Files"; - path = "../SwiftSocket iOS"; - sourceTree = ""; - }; 5518C82619A3290F0049DC22 = { isa = PBXGroup; children = ( - 5518C83119A329100049DC22 /* Source */, + 56AE7B3925CD3F940068681D /* Sources */, 375C482E1DDC4C56008C701D /* iOS Example */, 5518C83019A329100049DC22 /* Products */, ); @@ -151,17 +111,52 @@ name = Products; sourceTree = ""; }; - 5518C83119A329100049DC22 /* Source */ = { + 56AE7B3925CD3F940068681D /* Sources */ = { + isa = PBXGroup; + children = ( + 56AE7B3A25CD3F940068681D /* SwiftSocket */, + ); + path = Sources; + sourceTree = ""; + }; + 56AE7B3A25CD3F940068681D /* SwiftSocket */ = { + isa = PBXGroup; + children = ( + 56AE7B5325CD3FDA0068681D /* Supporting Files */, + 56AE7B5225CD3FA10068681D /* UDPSocket */, + 56AE7B5125CD3F990068681D /* TCPSocket */, + 56AE7B3E25CD3F940068681D /* Result.swift */, + 56AE7B4325CD3F940068681D /* Socket.swift */, + ); + path = SwiftSocket; + sourceTree = ""; + }; + 56AE7B5125CD3F990068681D /* TCPSocket */ = { + isa = PBXGroup; + children = ( + 56AE7B3D25CD3F940068681D /* TCPClient.swift */, + 56AE7B3C25CD3F940068681D /* ytcpsocket.c */, + ); + path = TCPSocket; + sourceTree = ""; + }; + 56AE7B5225CD3FA10068681D /* UDPSocket */ = { isa = PBXGroup; children = ( - 372313981DCF84EC0042DA87 /* Result.swift */, - 372313991DCF84EC0042DA87 /* Socket.swift */, - 375BC51D1DCDE86B006AD8F6 /* TCPSocket */, - 375BC51E1DCDE878006AD8F6 /* UDPSocket */, - 377DAA6A1DCDE40200009697 /* Supporting Files */, - ); - name = Source; - path = SwiftC; + 56AE7B4125CD3F940068681D /* UDPClient.swift */, + 56AE7B3B25CD3F940068681D /* yudpsocket.c */, + ); + path = UDPSocket; + sourceTree = ""; + }; + 56AE7B5325CD3FDA0068681D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 56AE7B3F25CD3F940068681D /* SwiftSocket.h */, + 56AE7B4025CD3F940068681D /* Info-tvOS.plist */, + 56AE7B4225CD3F940068681D /* Info.plist */, + ); + path = "Supporting Files"; sourceTree = ""; }; /* End PBXGroup section */ @@ -171,7 +166,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 37454ED71E0615FE00800AE5 /* SwiftSocket.h in Headers */, + 56AE7B7525CD406E0068681D /* SwiftSocket.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -179,7 +174,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 3723138F1DCF84CA0042DA87 /* SwiftSocket.h in Headers */, + 56AE7B4825CD3F940068681D /* SwiftSocket.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -187,7 +182,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 3723139C1DCF85270042DA87 /* SwiftSocket.h in Headers */, + 56AE7B7025CD40690068681D /* SwiftSocket.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -273,7 +268,7 @@ attributes = { LastSwiftMigration = 0710; LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1240; ORGANIZATIONNAME = swift; TargetAttributes = { 37454EC91E06158200800AE5 = { @@ -340,6 +335,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 56AE7B4925CD3F940068681D /* Info-tvOS.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -357,12 +353,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 37454EE31E06163D00800AE5 /* UDPClient.swift in Sources */, - 37454EE01E06163D00800AE5 /* Socket.swift in Sources */, - 37454EE41E06163D00800AE5 /* yudpsocket.c in Sources */, - 37454EDF1E06163D00800AE5 /* Result.swift in Sources */, - 37454EE21E06163D00800AE5 /* ytcpsocket.c in Sources */, - 37454EE11E06163D00800AE5 /* TCPClient.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -379,12 +369,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 372313931DCF84D80042DA87 /* yudpsocket.c in Sources */, - 3723139A1DCF84EC0042DA87 /* Result.swift in Sources */, - 3723139B1DCF84EC0042DA87 /* Socket.swift in Sources */, - 372313921DCF84D80042DA87 /* UDPClient.swift in Sources */, - 372313971DCF84E30042DA87 /* ytcpsocket.c in Sources */, - 372313961DCF84E30042DA87 /* TCPClient.swift in Sources */, + 56AE7B4625CD3F940068681D /* TCPClient.swift in Sources */, + 56AE7B4A25CD3F940068681D /* UDPClient.swift in Sources */, + 56AE7B4725CD3F940068681D /* Result.swift in Sources */, + 56AE7B4C25CD3F940068681D /* Socket.swift in Sources */, + 56AE7B4525CD3F940068681D /* ytcpsocket.c in Sources */, + 56AE7B4425CD3F940068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -392,12 +382,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 37454EDC1E06163C00800AE5 /* UDPClient.swift in Sources */, - 37454ED91E06163C00800AE5 /* Socket.swift in Sources */, - 37454EDD1E06163C00800AE5 /* yudpsocket.c in Sources */, - 37454ED81E06163C00800AE5 /* Result.swift in Sources */, - 37454EDB1E06163C00800AE5 /* ytcpsocket.c in Sources */, - 37454EDA1E06163C00800AE5 /* TCPClient.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -438,9 +422,9 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "Sources/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; @@ -470,9 +454,9 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "Sources/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; @@ -498,7 +482,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "iOS Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 10.1; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -521,7 +505,7 @@ COPY_PHASE_STRIP = NO; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "iOS Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 10.1; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -551,9 +535,9 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Sources/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; @@ -586,9 +570,9 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = Sources/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; @@ -616,7 +600,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = Sources/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; @@ -625,7 +609,7 @@ SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; - TVOS_DEPLOYMENT_TARGET = 9.0; + TVOS_DEPLOYMENT_TARGET = 12.0; }; name = Debug; }; @@ -642,7 +626,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = Sources/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; @@ -651,7 +635,7 @@ SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; - TVOS_DEPLOYMENT_TARGET = 9.0; + TVOS_DEPLOYMENT_TARGET = 12.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -679,6 +663,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -702,7 +687,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -736,6 +721,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -752,7 +738,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = ""; diff --git a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket iOS.xcscheme b/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket iOS.xcscheme index f6d73a0..ebd1cca 100644 --- a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket iOS.xcscheme +++ b/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket iOS.xcscheme @@ -1,6 +1,6 @@ - - - - - - - - - - - - [XCTestCaseEntry] { + return [ + testCase(SwiftSocketTests.allTests), + ] +} +#endif From 5197f9ec9fe0d793c66d55ab3c94ec63db871f5a Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:09:08 +0100 Subject: [PATCH 02/17] bump version --- Sources/SwiftSocket/Supporting Files/Info-tvOS.plist | 2 +- Sources/SwiftSocket/Supporting Files/Info.plist | 2 +- SwiftSocket.podspec | 3 ++- SwiftSocket.xcodeproj/project.pbxproj | 8 ++++++++ iOS Example/Info.plist | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist b/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist index d25faeb..ffa070f 100755 --- a/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist +++ b/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.2.0 + $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion diff --git a/Sources/SwiftSocket/Supporting Files/Info.plist b/Sources/SwiftSocket/Supporting Files/Info.plist index 0e27f5f..ec0cc7b 100644 --- a/Sources/SwiftSocket/Supporting Files/Info.plist +++ b/Sources/SwiftSocket/Supporting Files/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.1 + $(MARKETING_VERSION) CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index be00bbb..c1e242a 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -1,7 +1,8 @@ +# coding: utf-8 Pod::Spec.new do |s| s.name = 'SwiftSocket' - s.version = '2.0.2' + s.version = '2.1.1' s.summary = 'A cool framework to work with TCP and UDP sockets' s.description = <<-DESC diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index ecf06c7..5d2327b 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -426,6 +426,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = appletvos; @@ -458,6 +459,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = appletvos; @@ -484,6 +486,7 @@ INFOPLIST_FILE = "iOS Example/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -507,6 +510,7 @@ INFOPLIST_FILE = "iOS Example/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -539,6 +543,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = iphoneos; @@ -574,6 +579,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = iphoneos; @@ -603,6 +609,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = macosx; @@ -629,6 +636,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 2.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.swiftsocket.SwiftSocket; PRODUCT_NAME = SwiftSocket; SDKROOT = macosx; diff --git a/iOS Example/Info.plist b/iOS Example/Info.plist index d052473..214653b 100644 --- a/iOS Example/Info.plist +++ b/iOS Example/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion 1 LSRequiresIPhoneOS From f3637c183803ac5797ab900231dbf5c569e6aae8 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:15:11 +0100 Subject: [PATCH 03/17] Update spm --- .../Info-tvOS.plist | 0 .../Info.plist | 0 .../SwiftSocket.h | 0 SwiftSocket.xcodeproj/project.pbxproj | 28 +++++++++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) rename {Sources/SwiftSocket/Supporting Files => Supporting Files}/Info-tvOS.plist (100%) rename {Sources/SwiftSocket/Supporting Files => Supporting Files}/Info.plist (100%) rename {Sources/SwiftSocket/Supporting Files => Supporting Files}/SwiftSocket.h (100%) diff --git a/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist b/Supporting Files/Info-tvOS.plist similarity index 100% rename from Sources/SwiftSocket/Supporting Files/Info-tvOS.plist rename to Supporting Files/Info-tvOS.plist diff --git a/Sources/SwiftSocket/Supporting Files/Info.plist b/Supporting Files/Info.plist similarity index 100% rename from Sources/SwiftSocket/Supporting Files/Info.plist rename to Supporting Files/Info.plist diff --git a/Sources/SwiftSocket/Supporting Files/SwiftSocket.h b/Supporting Files/SwiftSocket.h similarity index 100% rename from Sources/SwiftSocket/Supporting Files/SwiftSocket.h rename to Supporting Files/SwiftSocket.h diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index 5d2327b..c9dcf8b 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -17,11 +17,16 @@ 56AE7B4625CD3F940068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; 56AE7B4725CD3F940068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; 56AE7B4825CD3F940068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 56AE7B4925CD3F940068681D /* Info-tvOS.plist in Resources */ = {isa = PBXBuildFile; fileRef = 56AE7B4025CD3F940068681D /* Info-tvOS.plist */; }; 56AE7B4A25CD3F940068681D /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4125CD3F940068681D /* UDPClient.swift */; }; 56AE7B4C25CD3F940068681D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4325CD3F940068681D /* Socket.swift */; }; 56AE7B7025CD40690068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; 56AE7B7525CD406E0068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 56AE7BAA25CD440B0068681D /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4125CD3F940068681D /* UDPClient.swift */; }; + 56AE7BAB25CD440B0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3B25CD3F940068681D /* yudpsocket.c */; }; + 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; + 56AE7BAD25CD440B0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3C25CD3F940068681D /* ytcpsocket.c */; }; + 56AE7BAE25CD440B0068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; + 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4325CD3F940068681D /* Socket.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -94,6 +99,7 @@ 5518C82619A3290F0049DC22 = { isa = PBXGroup; children = ( + 56AE7B5325CD3FDA0068681D /* Supporting Files */, 56AE7B3925CD3F940068681D /* Sources */, 375C482E1DDC4C56008C701D /* iOS Example */, 5518C83019A329100049DC22 /* Products */, @@ -122,7 +128,6 @@ 56AE7B3A25CD3F940068681D /* SwiftSocket */ = { isa = PBXGroup; children = ( - 56AE7B5325CD3FDA0068681D /* Supporting Files */, 56AE7B5225CD3FA10068681D /* UDPSocket */, 56AE7B5125CD3F990068681D /* TCPSocket */, 56AE7B3E25CD3F940068681D /* Result.swift */, @@ -335,7 +340,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56AE7B4925CD3F940068681D /* Info-tvOS.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -382,6 +386,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 56AE7BAA25CD440B0068681D /* UDPClient.swift in Sources */, + 56AE7BAB25CD440B0068681D /* yudpsocket.c in Sources */, + 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */, + 56AE7BAD25CD440B0068681D /* ytcpsocket.c in Sources */, + 56AE7BAE25CD440B0068681D /* Result.swift in Sources */, + 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -422,7 +432,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -455,7 +465,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -539,7 +549,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -575,7 +585,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -606,7 +616,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 2.1.1; @@ -633,7 +643,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftSocket/Supporting Files/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 2.1.1; From 19dfba32eb29c6bced078379b992fac72ceac952 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:25:32 +0100 Subject: [PATCH 04/17] Update spm --- .../contents.xcworkspacedata | 7 ++++ Package.swift | 3 ++ .../{SwiftSocket/TCPSocket => C}/ytcpsocket.c | 0 .../{SwiftSocket/UDPSocket => C}/yudpsocket.c | 0 SwiftSocket.xcodeproj/project.pbxproj | 36 ++++++++++++------- 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata rename Sources/{SwiftSocket/TCPSocket => C}/ytcpsocket.c (100%) rename Sources/{SwiftSocket/UDPSocket => C}/yudpsocket.c (100%) diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.swift b/Package.swift index 4608b5b..8705f05 100644 --- a/Package.swift +++ b/Package.swift @@ -20,6 +20,9 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "SwiftSocket", + dependencies: ["SwiftSocket-c"]), + .target( + name: "SwiftSocket-c", dependencies: []), .testTarget( name: "SwiftSocketTests", diff --git a/Sources/SwiftSocket/TCPSocket/ytcpsocket.c b/Sources/C/ytcpsocket.c similarity index 100% rename from Sources/SwiftSocket/TCPSocket/ytcpsocket.c rename to Sources/C/ytcpsocket.c diff --git a/Sources/SwiftSocket/UDPSocket/yudpsocket.c b/Sources/C/yudpsocket.c similarity index 100% rename from Sources/SwiftSocket/UDPSocket/yudpsocket.c rename to Sources/C/yudpsocket.c diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index c9dcf8b..afdf782 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -12,8 +12,6 @@ 375C48351DDC4C56008C701D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48331DDC4C56008C701D /* Main.storyboard */; }; 375C48371DDC4C56008C701D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 375C48361DDC4C56008C701D /* Assets.xcassets */; }; 375C483A1DDC4C56008C701D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48381DDC4C56008C701D /* LaunchScreen.storyboard */; }; - 56AE7B4425CD3F940068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3B25CD3F940068681D /* yudpsocket.c */; }; - 56AE7B4525CD3F940068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3C25CD3F940068681D /* ytcpsocket.c */; }; 56AE7B4625CD3F940068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; 56AE7B4725CD3F940068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; 56AE7B4825CD3F940068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -22,11 +20,15 @@ 56AE7B7025CD40690068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; 56AE7B7525CD406E0068681D /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7B3F25CD3F940068681D /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; 56AE7BAA25CD440B0068681D /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4125CD3F940068681D /* UDPClient.swift */; }; - 56AE7BAB25CD440B0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3B25CD3F940068681D /* yudpsocket.c */; }; 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; - 56AE7BAD25CD440B0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3C25CD3F940068681D /* ytcpsocket.c */; }; 56AE7BAE25CD440B0068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4325CD3F940068681D /* Socket.swift */; }; + 56AE7BB725CD45C40068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; + 56AE7BB825CD45C40068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; + 56AE7BC125CD45DA0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; + 56AE7BC225CD45DA0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; + 56AE7BC725CD45DA0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; + 56AE7BC825CD45DA0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -40,8 +42,6 @@ 375C483B1DDC4C56008C701D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 377DAA691DCDE40200009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 377DAA761DCDE45D00009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 56AE7B3B25CD3F940068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; - 56AE7B3C25CD3F940068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; 56AE7B3D25CD3F940068681D /* TCPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCPClient.swift; sourceTree = ""; }; 56AE7B3E25CD3F940068681D /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 56AE7B3F25CD3F940068681D /* SwiftSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftSocket.h; sourceTree = ""; }; @@ -49,6 +49,8 @@ 56AE7B4125CD3F940068681D /* UDPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UDPClient.swift; sourceTree = ""; }; 56AE7B4225CD3F940068681D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56AE7B4325CD3F940068681D /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; + 56AE7BB525CD45C40068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; + 56AE7BB625CD45C40068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -120,6 +122,7 @@ 56AE7B3925CD3F940068681D /* Sources */ = { isa = PBXGroup; children = ( + 56AE7BB425CD45C40068681D /* C */, 56AE7B3A25CD3F940068681D /* SwiftSocket */, ); path = Sources; @@ -140,7 +143,6 @@ isa = PBXGroup; children = ( 56AE7B3D25CD3F940068681D /* TCPClient.swift */, - 56AE7B3C25CD3F940068681D /* ytcpsocket.c */, ); path = TCPSocket; sourceTree = ""; @@ -149,7 +151,6 @@ isa = PBXGroup; children = ( 56AE7B4125CD3F940068681D /* UDPClient.swift */, - 56AE7B3B25CD3F940068681D /* yudpsocket.c */, ); path = UDPSocket; sourceTree = ""; @@ -164,6 +165,15 @@ path = "Supporting Files"; sourceTree = ""; }; + 56AE7BB425CD45C40068681D /* C */ = { + isa = PBXGroup; + children = ( + 56AE7BB525CD45C40068681D /* yudpsocket.c */, + 56AE7BB625CD45C40068681D /* ytcpsocket.c */, + ); + path = C; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -357,6 +367,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 56AE7BC825CD45DA0068681D /* ytcpsocket.c in Sources */, + 56AE7BC725CD45DA0068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -377,8 +389,8 @@ 56AE7B4A25CD3F940068681D /* UDPClient.swift in Sources */, 56AE7B4725CD3F940068681D /* Result.swift in Sources */, 56AE7B4C25CD3F940068681D /* Socket.swift in Sources */, - 56AE7B4525CD3F940068681D /* ytcpsocket.c in Sources */, - 56AE7B4425CD3F940068681D /* yudpsocket.c in Sources */, + 56AE7BB825CD45C40068681D /* ytcpsocket.c in Sources */, + 56AE7BB725CD45C40068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -387,11 +399,11 @@ buildActionMask = 2147483647; files = ( 56AE7BAA25CD440B0068681D /* UDPClient.swift in Sources */, - 56AE7BAB25CD440B0068681D /* yudpsocket.c in Sources */, 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */, - 56AE7BAD25CD440B0068681D /* ytcpsocket.c in Sources */, 56AE7BAE25CD440B0068681D /* Result.swift in Sources */, 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */, + 56AE7BC225CD45DA0068681D /* ytcpsocket.c in Sources */, + 56AE7BC125CD45DA0068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 703f7d8d2a73bc56cb43263f6860e11127165168 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:27:55 +0100 Subject: [PATCH 05/17] Update spm --- Package.swift | 4 +- Sources/C/ytcpsocket.c | 223 -------------------------- Sources/C/yudpsocket.c | 139 ---------------- SwiftSocket.xcodeproj/project.pbxproj | 38 ++--- 4 files changed, 21 insertions(+), 383 deletions(-) delete mode 100644 Sources/C/ytcpsocket.c delete mode 100644 Sources/C/yudpsocket.c diff --git a/Package.swift b/Package.swift index 8705f05..5e00347 100644 --- a/Package.swift +++ b/Package.swift @@ -20,9 +20,9 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "SwiftSocket", - dependencies: ["SwiftSocket-c"]), + dependencies: ["SwiftSocketC"]), .target( - name: "SwiftSocket-c", + name: "SwiftSocketC", dependencies: []), .testTarget( name: "SwiftSocketTests", diff --git a/Sources/C/ytcpsocket.c b/Sources/C/ytcpsocket.c deleted file mode 100644 index 50ad313..0000000 --- a/Sources/C/ytcpsocket.c +++ /dev/null @@ -1,223 +0,0 @@ -// -// Copyright (c) <2014>, skysent -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// 3. All advertising materials mentioning features or use of this software -// must display the following acknowledgement: -// This product includes software developed by skysent. -// 4. Neither the name of the skysent nor the -// names of its contributors may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY -// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void ytcpsocket_set_block(int socket, int on) { - int flags; - flags = fcntl(socket, F_GETFL, 0); - if (on == 0) { - fcntl(socket, F_SETFL, flags | O_NONBLOCK); - } else { - flags &= ~ O_NONBLOCK; - fcntl(socket, F_SETFL, flags); - } -} - -int ytcpsocket_connect(const char *host, int port, int timeout) { - struct sockaddr_in sa; - struct hostent *hp; - int sockfd = -1; - hp = gethostbyname(host); - if (hp == NULL) { - return -1; - } - - bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); - sa.sin_family = hp->h_addrtype; - sa.sin_port = htons(port); - sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0); - ytcpsocket_set_block(sockfd,0); - connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)); - fd_set fdwrite; - struct timeval tvSelect; - FD_ZERO(&fdwrite); - FD_SET(sockfd, &fdwrite); - tvSelect.tv_sec = timeout; - tvSelect.tv_usec = 0; - - int retval = select(sockfd + 1, NULL, &fdwrite, NULL, &tvSelect); - if (retval < 0) { - close(sockfd); - return -2; - } else if(retval == 0) {//timeout - close(sockfd); - return -3; - } else { - int error = 0; - int errlen = sizeof(error); - getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&errlen); - if (error != 0) { - close(sockfd); - return -4;//connect fail - } - - int set = 1; - setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); - return sockfd; - } -} - -int ytcpsocket_close(int socketfd){ - return close(socketfd); -} - -int ytcpsocket_pull(int socketfd, char *data, int len, int timeout_sec) { - int readlen = 0; - int datalen = 0; - if (timeout_sec > 0) { - fd_set fdset; - struct timeval timeout; - timeout.tv_usec = 0; - timeout.tv_sec = timeout_sec; - FD_ZERO(&fdset); - FD_SET(socketfd, &fdset); - int ret = select(socketfd + 1, &fdset, NULL, NULL, &timeout); - if (ret <= 0) { - return ret; // select-call failed or timeout occurred (before anything was sent) - } - } - // use loop to make sure receive all data - do { - readlen = (int)read(socketfd, data + datalen, len - datalen); - if (readlen > 0) { - datalen += readlen; - } - } while (readlen > 0); - - return datalen; -} - -int ytcpsocket_bytes_available(int socketfd) { - int count; - int callResult = ioctl(socketfd, FIONREAD, &count); - - if (callResult < 0) { - return callResult; - } - - return count; -} - -int ytcpsocket_send(int socketfd, const char *data, int len){ - int byteswrite = 0; - while (len - byteswrite > 0) { - int writelen = (int)write(socketfd, data + byteswrite, len - byteswrite); - if (writelen < 0) { - return -1; - } - byteswrite += writelen; - } - return byteswrite; -} - -//return socket fd -int ytcpsocket_listen(const char *address, int port) { - //create socket - int socketfd = socket(AF_INET, SOCK_STREAM, 0); - int reuseon = 1; - setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); - - //bind - struct sockaddr_in serv_addr; - memset( &serv_addr, '\0', sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = inet_addr(address); - serv_addr.sin_port = htons(port); - int r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); - if (r == 0) { - if (listen(socketfd, 128) == 0) { - return socketfd; - } else { - return -2;//listen error - } - } else { - return -1;//bind error - } -} - -//return client socket fd -int ytcpsocket_accept(int onsocketfd, char *remoteip, int *remoteport, int timeouts) { - socklen_t clilen; - struct sockaddr_in cli_addr; - clilen = sizeof(cli_addr); - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(onsocketfd, &fdset); - struct timeval *timeptr = NULL; - struct timeval timeout; - if (timeouts > 0) { - timeout.tv_sec = timeouts; - timeout.tv_usec = 0; - timeptr = &timeout; - } - int status = select(FD_SETSIZE, &fdset, NULL, NULL, timeptr); - if (status != 1) { - return -1; - } - int newsockfd = accept(onsocketfd, (struct sockaddr *) &cli_addr, &clilen); - char *clientip=inet_ntoa(cli_addr.sin_addr); - memcpy(remoteip, clientip, strlen(clientip)); - *remoteport = cli_addr.sin_port; - if (newsockfd > 0) { - int set = 1; - setsockopt(newsockfd, SOL_SOCKET, SO_NOSIGPIPE, (void*) &set, sizeof(int)); - return newsockfd; - } else { - return -1; - } -} - -//return socket port -int ytcpsocket_port(int socketfd) { - struct sockaddr_in sin; - socklen_t len = sizeof(sin); - if (getsockname(socketfd, (struct sockaddr *)&sin, &len) == -1) { - return -1; - } else { - return ntohs(sin.sin_port); - } -} diff --git a/Sources/C/yudpsocket.c b/Sources/C/yudpsocket.c deleted file mode 100644 index e59a725..0000000 --- a/Sources/C/yudpsocket.c +++ /dev/null @@ -1,139 +0,0 @@ -// -// Copyright (c) <2014>, skysent -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// 3. All advertising materials mentioning features or use of this software -// must display the following acknowledgement: -// This product includes software developed by skysent. -// 4. Neither the name of the skysent nor the -// names of its contributors may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY -// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#define yudpsocket_buff_len 8192 - -//return socket fd -int yudpsocket_server(const char *address, int port) { - - //create socket - int socketfd=socket(AF_INET, SOCK_DGRAM, 0); - int reuseon = 1; - int r = -1; - - //bind - struct sockaddr_in serv_addr; - memset( &serv_addr, '\0', sizeof(serv_addr)); - serv_addr.sin_len = sizeof(struct sockaddr_in); - serv_addr.sin_family = AF_INET; - if (address == NULL || strlen(address) == 0 || strcmp(address, "255.255.255.255") == 0) { - r = setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon)); - serv_addr.sin_port = htons(port); - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - } else { - r = setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); - serv_addr.sin_addr.s_addr = inet_addr(address); - serv_addr.sin_port = htons(port); - } - - if (r == -1) { - return -1; - } - - r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); - if (r == 0) { - return socketfd; - } else { - return -1; - } -} - -int yudpsocket_recive(int socket_fd, char *outdata, int expted_len, char *remoteip, int *remoteport) { - struct sockaddr_in cli_addr; - socklen_t clilen = sizeof(cli_addr); - memset(&cli_addr, 0x0, sizeof(struct sockaddr_in)); - int len = (int)recvfrom(socket_fd, outdata, expted_len, 0, (struct sockaddr *)&cli_addr, &clilen); - char *clientip = inet_ntoa(cli_addr.sin_addr); - memcpy(remoteip, clientip, strlen(clientip)); - *remoteport = cli_addr.sin_port; - - return len; -} - -int yudpsocket_close(int socket_fd) { - return close(socket_fd); -} - -//return socket fd -int yudpsocket_client() { - //create socket - int socketfd = socket(AF_INET, SOCK_DGRAM, 0); - int reuseon = 1; - setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); - - //disable SIGPIPE as we'll handle send errors ourselves - int noSigPipe = 1; - setsockopt(socketfd, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); - - return socketfd; -} - -//enable broadcast -void enable_broadcast(int socket_fd) { - int reuseon = 1; - setsockopt(socket_fd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon)); -} - -int yudpsocket_get_server_ip(char *host, char *ip) { - struct hostent *hp; - struct sockaddr_in address; - - hp = gethostbyname(host); - if (hp == NULL) { - return -1; - } - - bcopy((char *)hp->h_addr, (char *)&address.sin_addr, hp->h_length); - char *clientip = inet_ntoa(address.sin_addr); - memcpy(ip, clientip, strlen(clientip)); - - return 0; -} - -//send message to address and port -int yudpsocket_sentto(int socket_fd, char *msg, int len, char *toaddr, int topotr) { - struct sockaddr_in address; - socklen_t addrlen = sizeof(address); - memset(&address, 0x0, sizeof(struct sockaddr_in)); - address.sin_family = AF_INET; - address.sin_port = htons(topotr); - address.sin_addr.s_addr = inet_addr(toaddr); - int sendlen = (int)sendto(socket_fd, msg, len, 0, (struct sockaddr *)&address, addrlen); - - return sendlen; -} diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index afdf782..51b2300 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -23,12 +23,12 @@ 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3D25CD3F940068681D /* TCPClient.swift */; }; 56AE7BAE25CD440B0068681D /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B3E25CD3F940068681D /* Result.swift */; }; 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7B4325CD3F940068681D /* Socket.swift */; }; - 56AE7BB725CD45C40068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; - 56AE7BB825CD45C40068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; - 56AE7BC125CD45DA0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; - 56AE7BC225CD45DA0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; - 56AE7BC725CD45DA0068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB525CD45C40068681D /* yudpsocket.c */; }; - 56AE7BC825CD45DA0068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BB625CD45C40068681D /* ytcpsocket.c */; }; + 56AE7BD825CD47080068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD625CD47080068681D /* yudpsocket.c */; }; + 56AE7BD925CD47080068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD725CD47080068681D /* ytcpsocket.c */; }; + 56AE7BDE25CD47100068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD625CD47080068681D /* yudpsocket.c */; }; + 56AE7BE325CD47100068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD625CD47080068681D /* yudpsocket.c */; }; + 56AE7BE825CD47130068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD725CD47080068681D /* ytcpsocket.c */; }; + 56AE7BED25CD47130068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD725CD47080068681D /* ytcpsocket.c */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -49,8 +49,8 @@ 56AE7B4125CD3F940068681D /* UDPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UDPClient.swift; sourceTree = ""; }; 56AE7B4225CD3F940068681D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56AE7B4325CD3F940068681D /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; - 56AE7BB525CD45C40068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; - 56AE7BB625CD45C40068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; + 56AE7BD625CD47080068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; + 56AE7BD725CD47080068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -122,7 +122,7 @@ 56AE7B3925CD3F940068681D /* Sources */ = { isa = PBXGroup; children = ( - 56AE7BB425CD45C40068681D /* C */, + 56AE7BD525CD47080068681D /* SwiftSocketC */, 56AE7B3A25CD3F940068681D /* SwiftSocket */, ); path = Sources; @@ -165,13 +165,13 @@ path = "Supporting Files"; sourceTree = ""; }; - 56AE7BB425CD45C40068681D /* C */ = { + 56AE7BD525CD47080068681D /* SwiftSocketC */ = { isa = PBXGroup; children = ( - 56AE7BB525CD45C40068681D /* yudpsocket.c */, - 56AE7BB625CD45C40068681D /* ytcpsocket.c */, + 56AE7BD625CD47080068681D /* yudpsocket.c */, + 56AE7BD725CD47080068681D /* ytcpsocket.c */, ); - path = C; + path = SwiftSocketC; sourceTree = ""; }; /* End PBXGroup section */ @@ -367,8 +367,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56AE7BC825CD45DA0068681D /* ytcpsocket.c in Sources */, - 56AE7BC725CD45DA0068681D /* yudpsocket.c in Sources */, + 56AE7BED25CD47130068681D /* ytcpsocket.c in Sources */, + 56AE7BE325CD47100068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -386,11 +386,11 @@ buildActionMask = 2147483647; files = ( 56AE7B4625CD3F940068681D /* TCPClient.swift in Sources */, + 56AE7BD825CD47080068681D /* yudpsocket.c in Sources */, 56AE7B4A25CD3F940068681D /* UDPClient.swift in Sources */, 56AE7B4725CD3F940068681D /* Result.swift in Sources */, + 56AE7BD925CD47080068681D /* ytcpsocket.c in Sources */, 56AE7B4C25CD3F940068681D /* Socket.swift in Sources */, - 56AE7BB825CD45C40068681D /* ytcpsocket.c in Sources */, - 56AE7BB725CD45C40068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -399,11 +399,11 @@ buildActionMask = 2147483647; files = ( 56AE7BAA25CD440B0068681D /* UDPClient.swift in Sources */, + 56AE7BDE25CD47100068681D /* yudpsocket.c in Sources */, 56AE7BAC25CD440B0068681D /* TCPClient.swift in Sources */, 56AE7BAE25CD440B0068681D /* Result.swift in Sources */, + 56AE7BE825CD47130068681D /* ytcpsocket.c in Sources */, 56AE7BAF25CD440B0068681D /* Socket.swift in Sources */, - 56AE7BC225CD45DA0068681D /* ytcpsocket.c in Sources */, - 56AE7BC125CD45DA0068681D /* yudpsocket.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From d9083ac51e991b2addfd0acb14d12fc890e227dd Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 10:30:49 +0100 Subject: [PATCH 06/17] Update C path --- Sources/SwiftSocketC/ytcpsocket.c | 223 ++++++++++++++++++++++++++++++ Sources/SwiftSocketC/yudpsocket.c | 139 +++++++++++++++++++ 2 files changed, 362 insertions(+) create mode 100644 Sources/SwiftSocketC/ytcpsocket.c create mode 100644 Sources/SwiftSocketC/yudpsocket.c diff --git a/Sources/SwiftSocketC/ytcpsocket.c b/Sources/SwiftSocketC/ytcpsocket.c new file mode 100644 index 0000000..50ad313 --- /dev/null +++ b/Sources/SwiftSocketC/ytcpsocket.c @@ -0,0 +1,223 @@ +// +// Copyright (c) <2014>, skysent +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. All advertising materials mentioning features or use of this software +// must display the following acknowledgement: +// This product includes software developed by skysent. +// 4. Neither the name of the skysent nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY +// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void ytcpsocket_set_block(int socket, int on) { + int flags; + flags = fcntl(socket, F_GETFL, 0); + if (on == 0) { + fcntl(socket, F_SETFL, flags | O_NONBLOCK); + } else { + flags &= ~ O_NONBLOCK; + fcntl(socket, F_SETFL, flags); + } +} + +int ytcpsocket_connect(const char *host, int port, int timeout) { + struct sockaddr_in sa; + struct hostent *hp; + int sockfd = -1; + hp = gethostbyname(host); + if (hp == NULL) { + return -1; + } + + bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); + sa.sin_family = hp->h_addrtype; + sa.sin_port = htons(port); + sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0); + ytcpsocket_set_block(sockfd,0); + connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)); + fd_set fdwrite; + struct timeval tvSelect; + FD_ZERO(&fdwrite); + FD_SET(sockfd, &fdwrite); + tvSelect.tv_sec = timeout; + tvSelect.tv_usec = 0; + + int retval = select(sockfd + 1, NULL, &fdwrite, NULL, &tvSelect); + if (retval < 0) { + close(sockfd); + return -2; + } else if(retval == 0) {//timeout + close(sockfd); + return -3; + } else { + int error = 0; + int errlen = sizeof(error); + getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&errlen); + if (error != 0) { + close(sockfd); + return -4;//connect fail + } + + int set = 1; + setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); + return sockfd; + } +} + +int ytcpsocket_close(int socketfd){ + return close(socketfd); +} + +int ytcpsocket_pull(int socketfd, char *data, int len, int timeout_sec) { + int readlen = 0; + int datalen = 0; + if (timeout_sec > 0) { + fd_set fdset; + struct timeval timeout; + timeout.tv_usec = 0; + timeout.tv_sec = timeout_sec; + FD_ZERO(&fdset); + FD_SET(socketfd, &fdset); + int ret = select(socketfd + 1, &fdset, NULL, NULL, &timeout); + if (ret <= 0) { + return ret; // select-call failed or timeout occurred (before anything was sent) + } + } + // use loop to make sure receive all data + do { + readlen = (int)read(socketfd, data + datalen, len - datalen); + if (readlen > 0) { + datalen += readlen; + } + } while (readlen > 0); + + return datalen; +} + +int ytcpsocket_bytes_available(int socketfd) { + int count; + int callResult = ioctl(socketfd, FIONREAD, &count); + + if (callResult < 0) { + return callResult; + } + + return count; +} + +int ytcpsocket_send(int socketfd, const char *data, int len){ + int byteswrite = 0; + while (len - byteswrite > 0) { + int writelen = (int)write(socketfd, data + byteswrite, len - byteswrite); + if (writelen < 0) { + return -1; + } + byteswrite += writelen; + } + return byteswrite; +} + +//return socket fd +int ytcpsocket_listen(const char *address, int port) { + //create socket + int socketfd = socket(AF_INET, SOCK_STREAM, 0); + int reuseon = 1; + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); + + //bind + struct sockaddr_in serv_addr; + memset( &serv_addr, '\0', sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = inet_addr(address); + serv_addr.sin_port = htons(port); + int r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); + if (r == 0) { + if (listen(socketfd, 128) == 0) { + return socketfd; + } else { + return -2;//listen error + } + } else { + return -1;//bind error + } +} + +//return client socket fd +int ytcpsocket_accept(int onsocketfd, char *remoteip, int *remoteport, int timeouts) { + socklen_t clilen; + struct sockaddr_in cli_addr; + clilen = sizeof(cli_addr); + fd_set fdset; + FD_ZERO(&fdset); + FD_SET(onsocketfd, &fdset); + struct timeval *timeptr = NULL; + struct timeval timeout; + if (timeouts > 0) { + timeout.tv_sec = timeouts; + timeout.tv_usec = 0; + timeptr = &timeout; + } + int status = select(FD_SETSIZE, &fdset, NULL, NULL, timeptr); + if (status != 1) { + return -1; + } + int newsockfd = accept(onsocketfd, (struct sockaddr *) &cli_addr, &clilen); + char *clientip=inet_ntoa(cli_addr.sin_addr); + memcpy(remoteip, clientip, strlen(clientip)); + *remoteport = cli_addr.sin_port; + if (newsockfd > 0) { + int set = 1; + setsockopt(newsockfd, SOL_SOCKET, SO_NOSIGPIPE, (void*) &set, sizeof(int)); + return newsockfd; + } else { + return -1; + } +} + +//return socket port +int ytcpsocket_port(int socketfd) { + struct sockaddr_in sin; + socklen_t len = sizeof(sin); + if (getsockname(socketfd, (struct sockaddr *)&sin, &len) == -1) { + return -1; + } else { + return ntohs(sin.sin_port); + } +} diff --git a/Sources/SwiftSocketC/yudpsocket.c b/Sources/SwiftSocketC/yudpsocket.c new file mode 100644 index 0000000..e59a725 --- /dev/null +++ b/Sources/SwiftSocketC/yudpsocket.c @@ -0,0 +1,139 @@ +// +// Copyright (c) <2014>, skysent +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. All advertising materials mentioning features or use of this software +// must display the following acknowledgement: +// This product includes software developed by skysent. +// 4. Neither the name of the skysent nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY +// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#define yudpsocket_buff_len 8192 + +//return socket fd +int yudpsocket_server(const char *address, int port) { + + //create socket + int socketfd=socket(AF_INET, SOCK_DGRAM, 0); + int reuseon = 1; + int r = -1; + + //bind + struct sockaddr_in serv_addr; + memset( &serv_addr, '\0', sizeof(serv_addr)); + serv_addr.sin_len = sizeof(struct sockaddr_in); + serv_addr.sin_family = AF_INET; + if (address == NULL || strlen(address) == 0 || strcmp(address, "255.255.255.255") == 0) { + r = setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon)); + serv_addr.sin_port = htons(port); + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + } else { + r = setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); + serv_addr.sin_addr.s_addr = inet_addr(address); + serv_addr.sin_port = htons(port); + } + + if (r == -1) { + return -1; + } + + r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); + if (r == 0) { + return socketfd; + } else { + return -1; + } +} + +int yudpsocket_recive(int socket_fd, char *outdata, int expted_len, char *remoteip, int *remoteport) { + struct sockaddr_in cli_addr; + socklen_t clilen = sizeof(cli_addr); + memset(&cli_addr, 0x0, sizeof(struct sockaddr_in)); + int len = (int)recvfrom(socket_fd, outdata, expted_len, 0, (struct sockaddr *)&cli_addr, &clilen); + char *clientip = inet_ntoa(cli_addr.sin_addr); + memcpy(remoteip, clientip, strlen(clientip)); + *remoteport = cli_addr.sin_port; + + return len; +} + +int yudpsocket_close(int socket_fd) { + return close(socket_fd); +} + +//return socket fd +int yudpsocket_client() { + //create socket + int socketfd = socket(AF_INET, SOCK_DGRAM, 0); + int reuseon = 1; + setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon)); + + //disable SIGPIPE as we'll handle send errors ourselves + int noSigPipe = 1; + setsockopt(socketfd, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); + + return socketfd; +} + +//enable broadcast +void enable_broadcast(int socket_fd) { + int reuseon = 1; + setsockopt(socket_fd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon)); +} + +int yudpsocket_get_server_ip(char *host, char *ip) { + struct hostent *hp; + struct sockaddr_in address; + + hp = gethostbyname(host); + if (hp == NULL) { + return -1; + } + + bcopy((char *)hp->h_addr, (char *)&address.sin_addr, hp->h_length); + char *clientip = inet_ntoa(address.sin_addr); + memcpy(ip, clientip, strlen(clientip)); + + return 0; +} + +//send message to address and port +int yudpsocket_sentto(int socket_fd, char *msg, int len, char *toaddr, int topotr) { + struct sockaddr_in address; + socklen_t addrlen = sizeof(address); + memset(&address, 0x0, sizeof(struct sockaddr_in)); + address.sin_family = AF_INET; + address.sin_port = htons(topotr); + address.sin_addr.s_addr = inet_addr(toaddr); + int sendlen = (int)sendto(socket_fd, msg, len, 0, (struct sockaddr *)&address, addrlen); + + return sendlen; +} From 2dfca91cfd2921f344412ddb79fd9ebb1eca3adf Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 11:23:09 +0100 Subject: [PATCH 07/17] Update include --- Sources/SwiftSocketC/include/readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Sources/SwiftSocketC/include/readme.md diff --git a/Sources/SwiftSocketC/include/readme.md b/Sources/SwiftSocketC/include/readme.md new file mode 100644 index 0000000..e69de29 From 286296e193eeda2e7c252fed9fcb9a65b0d7cc96 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 11:25:50 +0100 Subject: [PATCH 08/17] Remove readme --- Sources/SwiftSocketC/include/readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Sources/SwiftSocketC/include/readme.md diff --git a/Sources/SwiftSocketC/include/readme.md b/Sources/SwiftSocketC/include/readme.md deleted file mode 100644 index e69de29..0000000 From 14bf458d3eca9323a2c71836032170f0bf1a2b28 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 11:33:53 +0100 Subject: [PATCH 09/17] update header --- SwiftSocket.xcodeproj/project.pbxproj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj index 51b2300..9998c1c 100644 --- a/SwiftSocket.xcodeproj/project.pbxproj +++ b/SwiftSocket.xcodeproj/project.pbxproj @@ -29,6 +29,9 @@ 56AE7BE325CD47100068681D /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD625CD47080068681D /* yudpsocket.c */; }; 56AE7BE825CD47130068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD725CD47080068681D /* ytcpsocket.c */; }; 56AE7BED25CD47130068681D /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 56AE7BD725CD47080068681D /* ytcpsocket.c */; }; + 56AE7C0125CD56630068681D /* SwiftSocketC.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7C0025CD56630068681D /* SwiftSocketC.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 56AE7C0225CD56630068681D /* SwiftSocketC.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7C0025CD56630068681D /* SwiftSocketC.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 56AE7C0325CD56630068681D /* SwiftSocketC.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE7C0025CD56630068681D /* SwiftSocketC.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -51,6 +54,7 @@ 56AE7B4325CD3F940068681D /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; 56AE7BD625CD47080068681D /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; }; 56AE7BD725CD47080068681D /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; }; + 56AE7C0025CD56630068681D /* SwiftSocketC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftSocketC.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -168,12 +172,21 @@ 56AE7BD525CD47080068681D /* SwiftSocketC */ = { isa = PBXGroup; children = ( + 56AE7BFF25CD56630068681D /* include */, 56AE7BD625CD47080068681D /* yudpsocket.c */, 56AE7BD725CD47080068681D /* ytcpsocket.c */, ); path = SwiftSocketC; sourceTree = ""; }; + 56AE7BFF25CD56630068681D /* include */ = { + isa = PBXGroup; + children = ( + 56AE7C0025CD56630068681D /* SwiftSocketC.h */, + ); + path = include; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -182,6 +195,7 @@ buildActionMask = 2147483647; files = ( 56AE7B7525CD406E0068681D /* SwiftSocket.h in Headers */, + 56AE7C0325CD56630068681D /* SwiftSocketC.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -190,6 +204,7 @@ buildActionMask = 2147483647; files = ( 56AE7B4825CD3F940068681D /* SwiftSocket.h in Headers */, + 56AE7C0125CD56630068681D /* SwiftSocketC.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -198,6 +213,7 @@ buildActionMask = 2147483647; files = ( 56AE7B7025CD40690068681D /* SwiftSocket.h in Headers */, + 56AE7C0225CD56630068681D /* SwiftSocketC.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; From d5cfb4a089109f2889be6a249b9e76c2499762d6 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Fri, 5 Feb 2021 11:35:54 +0100 Subject: [PATCH 10/17] add header --- Sources/SwiftSocketC/include/SwiftSocketC.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 Sources/SwiftSocketC/include/SwiftSocketC.h diff --git a/Sources/SwiftSocketC/include/SwiftSocketC.h b/Sources/SwiftSocketC/include/SwiftSocketC.h new file mode 100644 index 0000000..41d098d --- /dev/null +++ b/Sources/SwiftSocketC/include/SwiftSocketC.h @@ -0,0 +1 @@ +@import Foundation; From 8cd26fa702c4298549f77cebb6ad11e34d5187e6 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 12:36:55 +0200 Subject: [PATCH 11/17] Update podspec --- SwiftSocket.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index c1e242a..ed3eefc 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'SwiftSocket' - s.version = '2.1.1' + s.version = '2.2' s.summary = 'A cool framework to work with TCP and UDP sockets' s.description = <<-DESC @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.author = { 'Dan Shevlyuk' => 'danshevlyuk@icloud.com' } s.social_media_url = 'http://twitter.com/danshevluk' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '13.0' s.osx.deployment_target = '10.10' s.tvos.deployment_target = '9.0' s.source = { @@ -25,5 +25,5 @@ Pod::Spec.new do |s| } s.source_files = 'Sources/**/*.{swift,c}' s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5' } - + s.swift_version = '5.4.2' end From e384d9d8862e3533c34f816675fb37df63e5651f Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 12:45:32 +0200 Subject: [PATCH 12/17] Update version --- .swift-version | 2 +- SwiftSocket.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.swift-version b/.swift-version index 9f55b2c..8ae03c1 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +5.4.2 diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index ed3eefc..1d4281c 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -20,7 +20,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.10' s.tvos.deployment_target = '9.0' s.source = { - :git => 'https://github.com/swiftsocket/SwiftSocket.git', + :git => 'git@github.com:charles-awayup/SwiftSocket.git', :tag => s.version } s.source_files = 'Sources/**/*.{swift,c}' From 23b8c1b758c0a0a2828759d347d1941b4c027708 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 12:45:48 +0200 Subject: [PATCH 13/17] bump version --- SwiftSocket.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index 1d4281c..ea9fdb2 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'SwiftSocket' - s.version = '2.2' + s.version = '2.2.1' s.summary = 'A cool framework to work with TCP and UDP sockets' s.description = <<-DESC From fcbe7f5113d2b2fa538c02bd6574038285104583 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 13:46:56 +0200 Subject: [PATCH 14/17] REmove swift version --- .swift-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .swift-version diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 8ae03c1..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -5.4.2 From 1a6f01c6920da16f5c82da5e5fe7bf527970e430 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 14:04:16 +0200 Subject: [PATCH 15/17] Update podspec --- SwiftSocket.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index ea9fdb2..99ba0f4 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'SwiftSocket' - s.version = '2.2.1' + s.version = '2.3' s.summary = 'A cool framework to work with TCP and UDP sockets' s.description = <<-DESC @@ -25,5 +25,5 @@ Pod::Spec.new do |s| } s.source_files = 'Sources/**/*.{swift,c}' s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5' } - s.swift_version = '5.4.2' + end From c010c06dbd6b974411a2abd9d8fcfdb1e9051a44 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 14:08:49 +0200 Subject: [PATCH 16/17] remove warning --- Sources/SwiftSocketC/yudpsocket.c | 2 +- Supporting Files/SwiftSocket.h | 1 + SwiftSocket.podspec | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftSocketC/yudpsocket.c b/Sources/SwiftSocketC/yudpsocket.c index e59a725..128d8de 100644 --- a/Sources/SwiftSocketC/yudpsocket.c +++ b/Sources/SwiftSocketC/yudpsocket.c @@ -90,7 +90,7 @@ int yudpsocket_close(int socket_fd) { } //return socket fd -int yudpsocket_client() { +int yudpsocket_client(void) { //create socket int socketfd = socket(AF_INET, SOCK_DGRAM, 0); int reuseon = 1; diff --git a/Supporting Files/SwiftSocket.h b/Supporting Files/SwiftSocket.h index dc196c5..61fc1d9 100644 --- a/Supporting Files/SwiftSocket.h +++ b/Supporting Files/SwiftSocket.h @@ -7,3 +7,4 @@ FOUNDATION_EXPORT double SwiftSocketVersionNumber; FOUNDATION_EXPORT const unsigned char SwiftSocketVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import +#import diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index 99ba0f4..16cf3d5 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -25,5 +25,5 @@ Pod::Spec.new do |s| } s.source_files = 'Sources/**/*.{swift,c}' s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5' } - + s.version = "4.3.2" end From 42bd572d943490d553f0797ce4e7975dd2ea6401 Mon Sep 17 00:00:00 2001 From: Charles HARROCH Date: Tue, 14 Sep 2021 14:09:50 +0200 Subject: [PATCH 17/17] Fix warning --- SwiftSocket.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec index 16cf3d5..8c72ac0 100644 --- a/SwiftSocket.podspec +++ b/SwiftSocket.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'SwiftSocket' - s.version = '2.3' + s.version = '2.3.1' s.summary = 'A cool framework to work with TCP and UDP sockets' s.description = <<-DESC @@ -25,5 +25,5 @@ Pod::Spec.new do |s| } s.source_files = 'Sources/**/*.{swift,c}' s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5' } - s.version = "4.3.2" + s.swift_versions = "4.3.2" end