Net++
A class-based C++ encapsulation over the POSIX Sockets API
Loading...
Searching...
No Matches
io_context.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <event2/event.h>
4#include <memory>
5
6namespace async {
12class IOContext : public std::enable_shared_from_this<IOContext>{
13 public:
14 using io_context_ptr = std::shared_ptr<async::IOContext>;
21
23 IOContext(const IOContext&) = delete;
24 const IOContext& operator=(const IOContext&) = delete;
26
35 IOContext(IOContext &&other) noexcept;
36
46 IOContext& operator=(IOContext &&other) noexcept;
47
54
60 event_base *c_base() const;
61
65 void run() const;
66
67 private:
68 std::unique_ptr<event_base, decltype(&event_base_free)> base_;
69};
70} // namespace event
Handles the event loop.
Definition io_context.hpp:12
io_context_ptr create()
Creates an instance of IOContext wrapped in shared_ptr.
std::shared_ptr< async::IOContext > io_context_ptr
Definition io_context.hpp:14
IOContext()
IOContext constructor.
event_base * c_base() const
Gives a pointer to the event base struct for libevent calls.
IOContext & operator=(IOContext &&other) noexcept
IOContext move assignment operator.
void run() const
Runs the event loop.
IOContext(IOContext &&other) noexcept
IOContext move constructor.
Definition io_context.hpp:6