<commit_before>/**
 * Copyright IBM Corporation 2016
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import BlueSocket
import LoggerAPI

// MARK: HttpServerSpi

class HttpServerSpi {
    
    /// 
    /// Delegate for handling the HttpServer connection 
    ///
    weak var delegate: HttpServerSpiDelegate?
    
    ///
    /// Whether the Http service provider handler has stopped runnign
    ///
    var stopped = false

    ///
    /// Handles instructions for listening on a socket
    ///
    /// - Parameter socket: socket to use for connecting 
    /// - Parameter port: number to listen on
    ///
    func spiListen(socket: BlueSocket?, port: Int) {
        
        do {
            guard let socket = socket, let delegate = delegate else {
                return
            }

            try socket.listenOn(port)
            Log.info("Listening on port \(port)")

            // TODO: Change server exit to not rely on error being thrown
            repeat {
                let clientSocket = try socket.acceptConnectionAndKeepListening()
                Log.info("Accepted connection from: \(clientSocket.remoteHostName)" +
                    " on port \(clientSocket.remotePort)")

                delegate.handleClientRequest(clientSocket)
            } while true
            <commit_msg>IBM-Swift/Kitura-net#10 fixed log printing of accepted connection<commit_after>/**
 * Copyright IBM Corporation 2016
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import BlueSocket
import LoggerAPI

// MARK: HttpServerSpi

class HttpServerSpi {
    
    /// 
    /// Delegate for handling the HttpServer connection 
    ///
    weak var delegate: HttpServerSpiDelegate?
    
    ///
    /// Whether the Http service provider handler has stopped runnign
    ///
    var stopped = false

    ///
    /// Handles instructions for listening on a socket
    ///
    /// - Parameter socket: socket to use for connecting 
    /// - Parameter port: number to listen on
    ///
    func spiListen(socket: BlueSocket?, port: Int) {
        
        do {
            guard let socket = socket, let delegate = delegate else {
                return
            }

            try socket.listenOn(port)
            Log.info("Listening on port \(port)")

            // TODO: Change server exit to not rely on error being thrown
            repeat {
                let clientSocket = try socket.acceptConnectionAndKeepListening()
                Log.info("Accepted connection from: " +
                         "\(clientSocket.remoteHostName):\(clientSocket.remotePort)")
                delegate.handleClientRequest(clientSocket)
            } while true
            
{'fraction_non_alphanumeric': 0.08048780487804878, 'fraction_numerical': 0.004878048780487805, 'mean_word_length': 2.15200683176772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1065375', 'n_tokens_mistral': 914, 'n_tokens_neox': 872, 'n_words': 363}