release: 0.3.0
Swift file descriptor library. fd is a minimal layer on-top of the underlying system file descriptor and socket APIs.
FileDescriptor is a protocol containing a single property (fileNumber).
protocol FileDescriptor { var fileNumber: FileNumber { get } }
There are various protocol extensions to FileDescriptor to add functionality.
You may close a file descriptor.
try descriptor.close()
You may use the select function to examine which file descriptors are ready for reading, writing or have error conditions.
let readable = try select(reads: [descriptor]).reads
You may read from a readable file descriptor.
let bytes = try descriptor.read(1024)
You may write to a writable file descriptor.
try descriptor.write([1])
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.
let (reader, writer) = try pipe() try writer.write([1]) let bytes = try reader.read(1)
A listener is a file descriptor which can accept connections.
let connection = try listener.accept()
let listener = try TCPListener(address: "127.0.0.1", port: 8000)
UNIXListener is a Unix domain socket listener.
let listener = try UNIXListener(path: "/tmp/my-unix-listener")
A connection conforms to FileDescriptor so you can use the previously documented read and write capabilities.
read
write
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
fd: File Descriptor
Swift file descriptor library. fd is a minimal layer on-top of the underlying system file descriptor and socket APIs.
Usage
FileDescriptor
FileDescriptor is a protocol containing a single property (fileNumber).
There are various protocol extensions to FileDescriptor to add functionality.
Close
You may close a file descriptor.
Select
You may use the select function to examine which file descriptors are ready for reading, writing or have error conditions.
ReadableFileDescriptor
You may read from a readable file descriptor.
WritableFileDescriptor
You may write to a writable file descriptor.
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.
Listener
A listener is a file descriptor which can accept connections.
TCPListener
UNIXListener
UNIXListener is a Unix domain socket listener.
Connection
A connection conforms to FileDescriptor so you can use the previously documented
read
andwrite
capabilities.