cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
Term::Private::Sigwinch Class Reference

#include <cpp-terminal/private/sigwinch.hpp>

Static Public Member Functions

static void registerSigwinch ()
 
static void blockSigwinch ()
 
static void unblockSigwinch ()
 
static bool isSigwinch (const std::int32_t &file_descriptor=-1) noexcept
 
static std::int32_t get () noexcept
 

Static Private Attributes

static std::int32_t m_fd {-1}
 

Detailed Description

Definition at line 19 of file sigwinch.hpp.

Member Function Documentation

◆ blockSigwinch()

void Term::Private::Sigwinch::blockSigwinch ( )
static

Definition at line 65 of file sigwinch.cpp.

66{
67#if !defined(_WIN32)
68 ::sigset_t windows_event = {};
69 Term::Private::Errno().check_if(sigemptyset(&windows_event) != 0).throw_exception("sigemptyset(&windows_event)");
70 Term::Private::Errno().check_if(sigaddset(&windows_event, SIGWINCH) != 0).throw_exception("sigaddset(&windows_event, SIGWINCH)");
71 Term::Private::Errno().check_if(::pthread_sigmask(SIG_BLOCK, &windows_event, nullptr) != 0).throw_exception("::pthread_sigmask(SIG_BLOCK, &windows_event, nullptr)");
72#endif
73}
void throw_exception(const std::string &str={}) const
Errno & check_if(const bool &ret) noexcept

◆ get()

std::int32_t Term::Private::Sigwinch::get ( )
staticnoexcept

Definition at line 38 of file sigwinch.cpp.

39{
40#if defined(__APPLE__) || defined(__wasm__) || defined(__wasm) || defined(__EMSCRIPTEN__)
42#else
43 return m_fd;
44#endif
45}
static std::int32_t m_fd
Definition sigwinch.hpp:47
volatile std::sig_atomic_t m_signalStatus
Definition sigwinch.cpp:28

◆ isSigwinch()

bool Term::Private::Sigwinch::isSigwinch ( const std::int32_t & file_descriptor = -1)
staticnoexcept

Definition at line 85 of file sigwinch.cpp.

86{
87#if defined(__APPLE__) || defined(__wasm__) || defined(__wasm) || defined(__EMSCRIPTEN__)
89 {
90 static_cast<void>(file_descriptor); // suppress warning
92 return true;
93 }
94 return false;
95#elif defined(__linux__)
96 if(m_fd == file_descriptor)
97 {
98 // read it to clean
99 ::signalfd_siginfo fdsi = {};
100 ::read(m_fd, &fdsi, sizeof(fdsi));
101 return true;
102 }
103 return false;
104#else
105 static_cast<void>(file_descriptor); // suppress warning
106 return false;
107#endif
108}

◆ registerSigwinch()

void Term::Private::Sigwinch::registerSigwinch ( )
static

Definition at line 49 of file sigwinch.cpp.

50{
51#if defined(__APPLE__) || defined(__wasm__) || defined(__wasm) || defined(__EMSCRIPTEN__)
52 struct sigaction sa;
53 Term::Private::Errno().check_if(sigemptyset(&sa.sa_mask) != 0).throw_exception("sigemptyset(&sa.sa_mask)");
54 sa.sa_flags = {0};
55 sa.sa_handler = {Term::Private::sigwinchHandler};
56 Term::Private::Errno().check_if(sigaction(SIGWINCH, &sa, nullptr) != 0).throw_exception("sigaction(SIGWINCH, &sa, nullptr)");
57#elif defined(__linux__)
58 ::sigset_t windows_event = {};
59 Term::Private::Errno().check_if(sigemptyset(&windows_event) != 0).throw_exception("sigemptyset(&windows_event)");
60 Term::Private::Errno().check_if(sigaddset(&windows_event, SIGWINCH) != 0).throw_exception("sigaddset(&windows_event, SIGWINCH)");
61 Term::Private::Errno().check_if((m_fd = ::signalfd(-1, &windows_event, SFD_NONBLOCK | SFD_CLOEXEC)) == -1).throw_exception("m_fd = ::signalfd(-1, &windows_event, SFD_NONBLOCK | SFD_CLOEXEC)");
62#endif
63}

◆ unblockSigwinch()

void Term::Private::Sigwinch::unblockSigwinch ( )
static

Definition at line 75 of file sigwinch.cpp.

76{
77#if !defined(_WIN32)
78 ::sigset_t windows_event = {};
79 Term::Private::Errno().check_if(sigemptyset(&windows_event) != 0).throw_exception("sigemptyset(&windows_event)");
80 Term::Private::Errno().check_if(sigaddset(&windows_event, SIGWINCH) != 0).throw_exception("sigaddset(&windows_event, SIGWINCH)");
81 Term::Private::Errno().check_if(::pthread_sigmask(SIG_UNBLOCK, &windows_event, nullptr) != 0).throw_exception("::pthread_sigmask(SIG_UNBLOCK, &windows_event, nullptr)");
82#endif
83}

Member Data Documentation

◆ m_fd

std::int32_t Term::Private::Sigwinch::m_fd {-1}
staticprivate

Definition at line 47 of file sigwinch.hpp.


The documentation for this class was generated from the following files: