@@ -48,12 +48,6 @@ extension SocketDescriptor {
4848 } . map ( SocketDescriptor . init ( rawValue: ) )
4949 }
5050
51- /// Deletes a socket's file descriptor.
52- ///
53- /// This is equivalent to `socket.fileDescriptor.close()`
54- @_alwaysEmitIntoClient
55- public func close( ) throws { try fileDescriptor. close ( ) }
56-
5751 /// Shutdown part of a full-duplex connection
5852 ///
5953 /// The corresponding C function is `shutdown`
@@ -87,3 +81,57 @@ extension SocketDescriptor {
8781
8882
8983}
84+
85+ // MARK: - Forward FileDescriptor methods
86+ extension SocketDescriptor {
87+ /// Deletes a socket's file descriptor.
88+ ///
89+ /// This is equivalent to calling `fileDescriptor.close()`
90+ @_alwaysEmitIntoClient
91+ public func close( ) throws { try fileDescriptor. close ( ) }
92+
93+ /// Reads bytes from a socket.
94+ ///
95+ /// This is equivalent to calling `fileDescriptor.read(into:retryOnInterrupt:)`
96+ ///
97+ /// - Parameters:
98+ /// - buffer: The region of memory to read into.
99+ /// - retryOnInterrupt: Whether to retry the read operation
100+ /// if it throws ``Errno/interrupted``.
101+ /// The default is `true`.
102+ /// Pass `false` to try only once and throw an error upon interruption.
103+ /// - Returns: The number of bytes that were read.
104+ ///
105+ /// The corresponding C function is `read`.
106+ @_alwaysEmitIntoClient
107+ public func read(
108+ into buffer: UnsafeMutableRawBufferPointer , retryOnInterrupt: Bool = true
109+ ) throws -> Int {
110+ try fileDescriptor. read ( into: buffer, retryOnInterrupt: retryOnInterrupt)
111+ }
112+
113+ /// Writes the contents of a buffer to the socket.
114+ ///
115+ /// This is equivalent to `fileDescriptor.write(_:retryOnInterrupt:)`
116+ ///
117+ /// - Parameters:
118+ /// - buffer: The region of memory that contains the data being written.
119+ /// - retryOnInterrupt: Whether to retry the write operation
120+ /// if it throws ``Errno/interrupted``.
121+ /// The default is `true`.
122+ /// Pass `false` to try only once and throw an error upon interruption.
123+ /// - Returns: The number of bytes that were written.
124+ ///
125+ /// After writing,
126+ /// this method increments the file's offset by the number of bytes written.
127+ /// To change the file's offset,
128+ /// call the ``seek(offset:from:)`` method.
129+ ///
130+ /// The corresponding C function is `write`.
131+ @_alwaysEmitIntoClient
132+ public func write(
133+ _ buffer: UnsafeRawBufferPointer , retryOnInterrupt: Bool = true
134+ ) throws -> Int {
135+ try fileDescriptor. write ( buffer, retryOnInterrupt: retryOnInterrupt)
136+ }
137+ }
0 commit comments