GIp::operator QString() const { quint32 ip = htonl(ip_); char s[INET_ADDRSTRLEN]; const char* res = inet_ntop(AF_INET, &ip, s, INET_ADDRSTRLEN); if (res == nullptr) { qWarning() << "inet_ntop return null " << GLastErr(); return QString(); } return QString{s}; }
bool GSignal::setup(int signo) { Handler* handler = new Handler; handler->myAction_.sa_handler = _sigFunc; int res = sigaction(signo, &handler->myAction_, &handler->oldAction_); if (res != 0) { qCritical() << QString("sigaction(%1) return %2").arg(signo).arg(res) << GLastErr(); delete handler; return false; } handlers_[signo] = handler; return true; }
// ---------------------------------------------------------------------------- // GIp // ---------------------------------------------------------------------------- GIp& GIp::operator =(const char* rhs) { int res = inet_pton(AF_INET, rhs, &ip_); switch (res) { case 0: qWarning() << "inet_pton return zero ip=" << rhs; break; case 1: // succeed ip_ = ntohl(ip_); break; default: qWarning() << "inet_pton return " << res << " " << GLastErr(); } return *this; }
void GSignal::_sigFunc(int signo) { GSignal* signal = instance(); emit signal->signaled(signo); Handlers::iterator it = signal->handlers_.find(signo); if (it == signal->handlers_.end()) { qCritical() << "can not find signal" << signo; return; } Handler* handler = it.value(); int res = sigaction(signo, &handler->oldAction_, nullptr); if (res != 0) { qCritical() << QString("sigaction(%1) return %2").arg(signo).arg(res) << GLastErr(); } }