<commit_before>import Foundation
import CocoaAsyncSocket

extension MConnectingSocket
{
    private static let kUdpQueueLabel:String = "velvetRoom.connecting.udp"
    private static let kTcpQueueLabel:String = "velvetRoom.connecting.tcp"
    
    //MARK: private
    
    private class func factoryUdpQueue() -> DispatchQueue
    {
        let queue = DispatchQueue(
            label:kUdpQueueLabel,
            qos:DispatchQoS.background,
            attributes:DispatchQueue.Attributes(),
            autoreleaseFrequency:DispatchQueue.AutoreleaseFrequency.inherit,
            target:DispatchQueue.global(qos:DispatchQoS.QoSClass.background))
        
        return queue
    }
    
    private class func factoryTcpQueue() -> DispatchQueue
    {
        let queue = DispatchQueue(
            label:kTcpQueueLabel,
            qos:DispatchQoS.background,
            attributes:DispatchQueue.Attributes(),
            autoreleaseFrequency:DispatchQueue.AutoreleaseFrequency.inherit,
            target:DispatchQueue.global(qos:DispatchQoS.QoSClass.background))
        
        return queue
    }
    
    private class func factoryUdpSocket(
        delegate:MConnectingSocketUdpDelegate,
        queue:DispatchQueue,
        configuration:MVitaConfiguration) -> GCDAsyncUdpSocket?
    {
        let socket:GCDAsyncUdpSocket = GCDAsyncUdpSocket(
            delegate:delegate,
            delegateQueue:queue,
            socketQueue:queue)
        
        socket.setPreferIPv4()
        socket.setIPv6Enabled(false)
        
        do
        {
            try socket.bind(
                toPort:configuration.port)
        }
        catch
        {
            return nil
        }
        
        do
        {
            try socket.enableReusePort(true)
        }
        catch
        {
            return nil
        }
        
        do
        {
            try socket.beginReceiving()
        }
        catch
        {
            return nil
        }
        
        return socket
    }
    
    private class func factoryTcpSocket(
        delegate:MConnectingSocketTcpDelegate,
        queue:DispatchQueue,
        configuration:MVitaConfiguration) -> GCDAsyncSocket?
    {
        let socket:GCDAsyncSocket = GCDAsyncSocket(
            delegate:delegate,
            delegateQueue:queue,
            socketQueue:queue)
        
        do
        {
            try socket.accept(
                onPort:configuration.port)
        }
        catch
        {
            return nil
        }
        
        return socket
    }
    
    //MARK: internal
    
    class func factoryUdp(
        configuration:MVitaConfiguration) -> MConnectingSocketUdp?
    {
        let delegate:MConnectingSocketUdpDelegate = MConnectingSocketUdpDelegate()
        let queue:DispatchQueue = factoryUdpQueue()
        
        guard
        
            let socket:GCDAsyncUdpSocket = factoryUdpSocket(
                delegate:delegate,
                queue:queue,
                configuration:configuration)
        
        else
        {
            return nil
        }
        
        let modelUdp:MConnectingSocketUdp = MConnectingSocketUdp(
            socket:socket,
            delegate:delegate,
            queue:queue,
            configuration:configuration)
        delegate.model = modelUdp
        
        return modelUdp
    }
}<commit_msg>Factory model tcp<commit_after>import Foundation
import CocoaAsyncSocket

extension MConnectingSocket
{
    private static let kUdpQueueLabel:String = "velvetRoom.connecting.udp"
    private static let kTcpQueueLabel:String = "velvetRoom.connecting.tcp"
    
    //MARK: private
    
    private class func factoryUdpQueue() -> DispatchQueue
    {
        let queue = DispatchQueue(
            label:kUdpQueueLabel,
            qos:DispatchQoS.background,
            attributes:DispatchQueue.Attributes(),
            autoreleaseFrequency:DispatchQueue.AutoreleaseFrequency.inherit,
            target:DispatchQueue.global(qos:DispatchQoS.QoSClass.background))
        
        return queue
    }
    
    private class func factoryTcpQueue() -> DispatchQueue
    {
        let queue = DispatchQueue(
            label:kTcpQueueLabel,
            qos:DispatchQoS.background,
            attributes:DispatchQueue.Attributes(),
            autoreleaseFrequency:DispatchQueue.AutoreleaseFrequency.inherit,
            target:DispatchQueue.global(qos:DispatchQoS.QoSClass.background))
        
        return queue
    }
    
    private class func factoryUdpSocket(
        delegate:MConnectingSocketUdpDelegate,
        queue:DispatchQueue,
        configuration:MVitaConfiguration) -> GCDAsyncUdpSocket?
    {
        let socket:GCDAsyncUdpSocket = GCDAsyncUdpSocket(
            delegate:delegate,
            delegateQueue:queue,
            socketQueue:queue)
        
        socket.setPreferIPv4()
        socket.setIPv6Enabled(false)
        
        do
        {
            try socket.bind(
                toPort:configuration.port)
        }
        catch
        {
            return nil
        }
        
        do
        {
            try socket.enableReusePort(true)
        }
        catch
        {
            return nil
        }
        
        do
        {
            try socket.beginReceiving()
        }
        catch
        {
            return nil
        }
        
        return socket
    }
    
    private class func factoryTcpSocket(
        delegate:MConnectingSocketTcpDelegate,
        queue:DispatchQueue,
        configuration:MVitaConfiguration) -> GCDAsyncSocket?
    {
        let socket:GCDAsyncSocket = GCDAsyncSocket(
            delegate:delegate,
            delegateQueue:queue,
            socketQueue:queue)
        
        do
        {
            try socket.accept(
                onPort:configuration.port)
        }
        catch
        {
            return nil
        }
        
        return socket
    }
    
    //MARK: internal
    
    class func factoryUdp(
        configuration:MVitaConfiguration) -> MConnectingSocketUdp?
    {
        let delegate:MConnectingSocketUdpDelegate = MConnectingSocketUdpDelegate()
        let queue:DispatchQueue = factoryUdpQueue()
        
        guard
        
            let socket:GCDAsyncUdpSocket = factoryUdpSocket(
                delegate:delegate,
                queue:queue,
                configuration:configuration)
        
        else
        {
            return nil
        }
        
        let modelUdp:MConnectingSocketUdp = MConnectingSocketUdp(
            socket:socket,
            delegate:delegate,
            queue:queue,
            configuration:configuration)
        delegate.model = modelUdp
        
        return modelUdp
    }
    
    class func factoryTcp(
        configuration:MVitaConfiguration) -> MConnectingSocketTcp?
    {
        let delegate:MConnectingSocketTcpDelegate = MConnectingSocketTcpDelegate()
        let queue:DispatchQueue = factoryTcpQueue()
        
        guard
        
            let socket:GCDAsyncSocket = factoryTcpSocket(
                delegate:delegate,
                queue:queue,
                configuration:configuration)
        
        else
        {
            return nil
        }
        
        let modelTcp:MConnectingSocketTcp = MConnectingSocketTcp(
            socket:socket,
            delegate:delegate,
            queue:queue,
            configuration:configuration)
        delegate.model = modelTcp
        
        return modelTcp
    }
}
{'fraction_non_alphanumeric': 0.05927698032961191, 'fraction_numerical': 0.000531632110579479, 'mean_word_length': 1.5850223290965304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7149045', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1892, 'n_words': 318}