         )
     }
     
-    private func setNonblocking() throws {
-        
-        var flags = try fileDescriptor.getStatus()
-        flags.insert(.nonBlocking)
-        try fileDescriptor.setStatus(flags)
-    }
-    
     /// Write to the socket.
     public func send(_ data: Data) throws {
         

import SystemPackage

/// L2CAP Bluetooth socket
public final class L2CAPSocket {
    
    // MARK: - Properties
    
    /// Internal socket file descriptor
    internal let fileDescriptor: FileDescriptor
    
    /// L2CAP Socket address

    /// Attempt to accept an incomping connection.
    public func accept() throws -> L2CAPSocket {
        let (clientFileDescriptor, clientAddress) = try fileDescriptor.accept(L2CAPSocketAddress.self)
        try clientFileDescriptor.closeIfThrows {
            try clientFileDescriptor.setNonblocking()
        }
        return L2CAPSocket(
            fileDescriptor: clientFileDescriptor,
            address: clientAddress
        )
    }
    
    /// Reads from the socket.
    public func recieve(_ bufferSize: Int = 1024) throws -> Data? {
        
        let events = try fileDescriptor.poll(
            for: [.read],
            timeout: 0
        )
        
        guard events.contains(.read) else {
            return nil
        }
        
        var buffer = Data(repeating: 0, count: bufferSize)
        let recievedByteCount = try buffer.withUnsafeMutableBytes {
