https://github.com/sequel-ace/unixsockets
A fork of macintosh-HD/fd, which is a fork of kylef-archive/fd
https://github.com/sequel-ace/unixsockets
hacktoberfest sockets
Last synced: 4 months ago
JSON representation
A fork of macintosh-HD/fd, which is a fork of kylef-archive/fd
- Host: GitHub
- URL: https://github.com/sequel-ace/unixsockets
- Owner: Sequel-Ace
- License: bsd-2-clause
- Created: 2020-10-31T23:02:25.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-01T02:56:25.000Z (almost 5 years ago)
- Last Synced: 2025-06-21T07:08:16.537Z (4 months ago)
- Topics: hacktoberfest, sockets
- Language: Swift
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# UnixSockets: A File Descriptor Library
Swift file descriptor library, with a primary focus on supporting file-based sockets. UnixSockets
evolved out of a general purpose socket library## Example
```swift
```
## Usage
### FileDescriptor
FileDescriptor is a protocol containing a single property (fileNumber).
```swift
protocol FileDescriptor {
var fileNumber: FileNumber { get }
}
```There are various protocol extensions to FileDescriptor to add functionality.
#### Close
You may close a file descriptor.
```swift
try descriptor.close()
```#### Select
You may use the select function to examine which file descriptors are ready for
reading, writing or have error conditions.```swift
let readable = try select(reads: [descriptor]).reads
```### ReadableFileDescriptor
You may read from a readable file descriptor.
```swift
let bytes = try descriptor.read(1024)
```### WritableFileDescriptor
You may write to a writable file descriptor.
```swift
try descriptor.write([1])
```### Pipe
You may use the pipe function to create a unidirectional data flow. The reader
allows you to read data which was previously written to the writer.```swift
let (reader, writer) = try pipe()
try writer.write([1])
let bytes = try reader.read(1)
```### Listener
A listener is a file descriptor which can accept connections.
```swift
let connection = try listener.accept()
```#### TCPListener
```swift
let listener = try TCPListener(address: "127.0.0.1", port: 8000)
```#### UNIXListener
UNIXListener is a Unix domain socket listener.
```swift
let listener = try UNIXListener(path: "/tmp/my-unix-listener")
```### Connection
A connection conforms to FileDescriptor so you can use the previously
documented `read` and `write` capabilities.