 
 /// Server class
 open class Server: Router {
+
     private let port: UInt16
-//    let bufferSize = 20
-    var listenSocket: Socket? = nil
-    var connected = [Int32: Socket]()
-    var acceptNewConnection = true
+    private var listenSocket: Socket? = nil
+    public private(set) var runStatus: RunStatus = .stopped
+    private var connected = [Int32: Socket]()
+    private let semaphore = DispatchSemaphore(value: 1)
+    private let dispatchGroup = DispatchGroup()
+
     let serverRoot: Path
     /// url
     public let url: String

        listenSocket?.close()
    }

    /// Run server and start to listen on given `port` from `init(port:root:)`
    ///
    /// - Throws: Socket errors
    public func run() throws {
        let socket = try Socket.create()

        listenSocket = socket
//        socket
        try socket.listen(on: Int(port), maxBacklogSize: squirrelConfig.maximumPendingConnections, allowPortReuse: false)
        log.info("Server is running on port \(socket.listeningPort)")
        let queue = DispatchQueue(label: "clientQueue", attributes: .concurrent)
        repeat {
            let connectedSocket = try socket.acceptClientConnection()
//            try connectedSocket.setBlocking(mode: false)
            log.verbose("Connection from: \(connectedSocket.remoteHostname)")
            queue.async {self.newConnection(socket: connectedSocket)}
        } while acceptNewConnection
    }

    func newConnection(socket: Socket) {
        connected[socket.socketfd] = socket
        do {
            do {
                let request = try Request(socket: socket)

            return try Response(pathToFile: path)
        })
    }
}

// MARK: - RunStatus
public extension Server {
    public enum RunStatus {
        case willRun
        case running
        case paused
        case pausing(now: Bool, closure: ()->())
        case stopped
        case stopping(now: Bool)
    }

    var isPaused: Bool {
        guard case .stopped = runStatus else {
            return false
        }
        return true
    }

    var willRun: Bool {
        guard case .willRun = runStatus else {
            return false
        }
        return true
    }

    var isStopped: Bool {
        guard case .stopped = runStatus else {
            return false
        }
        return true
    }

    var isRunning: Bool {
        guard case .running = runStatus else {
            return false
        }
        return true
    }
}

// MARK: - Sending
private extension Server {


    private func sendPartial(socket: Socket, range: (bottom: UInt, top: UInt), response: Response) {
        let bodyBytes = response.rawBody
