Swiftpack.co - PureSwift/Socket as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by PureSwift.
PureSwift/Socket 0.2.2
Swift async/await based socket
⭐️ 42
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/PureSwift/Socket.git", from: "0.2.2")

Socket

Swift async/await based socket library

Introduction

This library exposes an idiomatic Swift API for interacting with POSIX sockets via an async/await interface. What makes this library unique (even to the point that Swift NIO is still using a custom socket / thread pool) is that it was built exclusively using Swift Concurrency and doesn't use old blocking C APIs, CFSocket, DispatchIO, CFRunloop, GCD, or explicitly create a single thread outside of the Swift's global cooperative thread pool to manage the sockets and polling.

The result is a Socket API that is optimized for async/await and built from the group up. Additionally, like the System, and Concurrency APIs, the Socket is represented as a struct instead of a class, greatly reducing ARC overhead. The internal state for the socket is managed by a singleton that stores both its state, and keeps an array of managed file descriptors so polling is global.

Goals

  • Minimal overhead for Swift Async/Await
  • Minimal ARC overhead, keep state outside of Socket
  • Avoid thread explosion and overcomitting the system
  • Use actors to prevent blocking threads
  • Optimize polling and C / System API usage
  • Low energy usage and memory overhead

GitHub

link
Stars: 42
Last commit: 5 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.2.2
1 week ago
  • 70b33784992f37c0d1b0fe56df8f24d662b862cd Added CSocket module

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics