Repository: oatpp/oatpp
File: src/oatpp/web/server/HttpConnectionHandler.hpp (C++)

Code before:
 *     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.
 *
 ***************************************************************************/

#ifndef oatpp_web_server_HttpConnectionHandler_hpp
#define oatpp_web_server_HttpConnectionHandler_hpp

#include "oatpp/web/server/HttpProcessor.hpp"
#include "oatpp/network/ConnectionHandler.hpp"

namespace oatpp { namespace web { namespace server {

/**
 * Simple ConnectionHandler (&id:oatpp::network::ConnectionHandler;) for handling HTTP communication. <br>
 * Will create one thread per each connection to handle communication.
 */
class HttpConnectionHandler : public base::Countable, public network::ConnectionHandler {
private:
  std::shared_ptr<HttpProcessor::Components> m_components;
  std::shared_ptr<std::atomic_ulong> m_spawns;
public:

  /**
   * Constructor.
   * @param components - &id:oatpp::web::server::HttpProcessor::Components;.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpProcessor::Components>& components);

  /**
   * Constructor.
   * @param router - &id:oatpp::web::server::HttpRouter; to route incoming requests.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpRouter>& router)
    : HttpConnectionHandler(std::make_shared<HttpProcessor::Components>(router))
  {}

  /**
   * Constructor.
   * @param router - &id:oatpp::web::server::HttpRouter; to route incoming requests.
   * @param config - &id:oatpp::web::server::HttpProcessor::Config;.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpRouter>& router,
                        const std::shared_ptr<HttpProcessor::Config>& config)
    : HttpConnectionHandler(std::make_shared<HttpProcessor::Components>(router, config))
  {}

Review comment (suggestion):
Let's have it `signed` to avoid rounding in case of an error.
It also makes sense to add a redundant check after decrementing this value that it didn't go less than 0.

Code after:
 *     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.
 *
 ***************************************************************************/

#ifndef oatpp_web_server_HttpConnectionHandler_hpp
#define oatpp_web_server_HttpConnectionHandler_hpp

#include "oatpp/web/server/HttpProcessor.hpp"
#include "oatpp/network/ConnectionHandler.hpp"

namespace oatpp { namespace web { namespace server {

/**
 * Simple ConnectionHandler (&id:oatpp::network::ConnectionHandler;) for handling HTTP communication. <br>
 * Will create one thread per each connection to handle communication.
 */
class HttpConnectionHandler : public base::Countable, public network::ConnectionHandler {
private:
  std::shared_ptr<HttpProcessor::Components> m_components;
  std::atomic_long m_spawns;
  std::atomic_bool m_continue;
public:

  /**
   * Constructor.
   * @param components - &id:oatpp::web::server::HttpProcessor::Components;.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpProcessor::Components>& components);

  /**
   * Constructor.
   * @param router - &id:oatpp::web::server::HttpRouter; to route incoming requests.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpRouter>& router)
    : HttpConnectionHandler(std::make_shared<HttpProcessor::Components>(router))
  {}

  /**
   * Constructor.
   * @param router - &id:oatpp::web::server::HttpRouter; to route incoming requests.
   * @param config - &id:oatpp::web::server::HttpProcessor::Config;.
   */
  HttpConnectionHandler(const std::shared_ptr<HttpRouter>& router,
                        const std::shared_ptr<HttpProcessor::Config>& config)
    : HttpConnectionHandler(std::make_shared<HttpProcessor::Components>(router, config))