cppnet
C++ network utilities for asynchronous servers.
Loading...
Searching...
No Matches
context_thread.hpp
Go to the documentation of this file.
1// Copyright 2025 Kevin Exton
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
18#pragma once
19#ifndef CPPNET_CONTEXT_THREAD_HPP
20#define CPPNET_CONTEXT_THREAD_HPP
21#include "async_context.hpp"
22
23#include <mutex>
24#include <thread>
26namespace net::service {
28namespace detail {
35 static auto signal_handler(int signum) noexcept -> void {};
41 static auto start(async_context &ctx) noexcept -> std::error_code
42 {
43 return {};
44 };
45};
46} // namespace detail
47
56template <ServiceLike Service>
58public:
66 auto
70
78 template <typename... Args> auto start(Args &&...args) -> void;
79
82
83private:
85 std::thread server_;
87 std::mutex mtx_;
88
90 auto stop() noexcept -> void;
91};
92
101using context_thread = basic_context_thread<detail::null_service>;
102
103} // namespace net::service
104
105#include "impl/context_thread_impl.hpp" // IWYU pragma: export
106
107#endif // CPPNET_CONTEXT_THREAD_HPP
This file declares an asynchronous execution context.
A threaded asynchronous service.
Definition context_thread.hpp:57
auto start(Args &&...args) -> void
Start the asynchronous service.
basic_context_thread(const basic_context_thread &)=delete
Deleted copy constructor.
auto operator=(const basic_context_thread &) -> basic_context_thread &=delete
Deleted copy assignment.
auto operator=(basic_context_thread &&) -> basic_context_thread &=delete
Deleted move assignment.
~basic_context_thread()
The destructor signals the thread before joining it.
basic_context_thread(basic_context_thread &&)=delete
Deleted move constructor.
basic_context_thread()=default
Default constructor.
This namespace is for network services.
Definition async_context.hpp:31
An asynchronous execution context.
Definition async_context.hpp:34
Null service that services as a ServiceLike placeholder.
Definition context_thread.hpp:30
static auto signal_handler(int signum) noexcept -> void
signal handling placeholder.
Definition context_thread.hpp:35
static auto start(async_context &ctx) noexcept -> std::error_code
start placeholder.
Definition context_thread.hpp:41