Consumer::Consumer(MainObject *main, QObject *parent) : QObject(parent) { timer = new QTimer(this); m_main = main; connect(timer, SIGNAL(timeout()), this, SLOT(startConsuming())); timer->start(3000); }
void FileRegion::FileWriteRequest::start() { started_ = true; readBase_ = readPool.get()->getEventBase(); readBase_->runInEventBaseThread([this]{ auto flags = fcntl(readFd_, F_GETFL); if (flags == -1) { fail(__func__, AsyncSocketException( AsyncSocketException::INTERNAL_ERROR, "fcntl F_GETFL failed", errno)); return; } flags &= O_ACCMODE; if (flags == O_WRONLY) { fail(__func__, AsyncSocketException( AsyncSocketException::BAD_ARGS, "file not open for reading")); return; } #ifndef GLIBC_AT_LEAST_2_9 fail(__func__, AsyncSocketException( AsyncSocketException::NOT_SUPPORTED, "writeFile unsupported on glibc < 2.9")); return; #else int pipeFds[2]; if (::pipe2(pipeFds, O_NONBLOCK) == -1) { fail(__func__, AsyncSocketException( AsyncSocketException::INTERNAL_ERROR, "pipe2 failed", errno)); return; } #ifdef F_SETPIPE_SZ // Max size for unprevileged processes as set in /proc/sys/fs/pipe-max-size // Ignore failures and just roll with it // TODO maybe read max size from /proc? fcntl(pipeFds[0], F_SETPIPE_SZ, 1048576); fcntl(pipeFds[1], F_SETPIPE_SZ, 1048576); #endif pipe_out_ = pipeFds[0]; socket_->getEventBase()->runInEventBaseThreadAndWait([&]{ startConsuming(socket_->getEventBase(), &queue_); }); readHandler_ = folly::make_unique<FileReadHandler>( this, pipeFds[1], count_); #endif }); }
void start() { startProducing(); startConsuming(); }
void ProxygenServer::start() { m_httpServerSocket.reset(new AsyncServerSocket(m_worker.getEventBase())); bool needListen = true; auto failedToListen = [](const std::exception& ex, const folly::SocketAddress& addr) { Logger::Error("failed to listen: %s", ex.what()); throw FailedToListenException(addr.getAddressStr(), addr.getPort()); }; try { if (m_accept_sock >= 0) { Logger::Info("inheritfd: using inherited fd %d for server", m_accept_sock); m_httpServerSocket->useExistingSocket(m_accept_sock); } else { // make it possible to quickly reuse the port m_httpServerSocket->setReusePortEnabled(RuntimeOption::StopOldServer); m_httpServerSocket->bind(m_httpConfig.bindAddress); } } catch (const std::system_error& ex) { bool takoverSucceeded = false; if (ex.code().value() == EADDRINUSE && m_takeover_agent) { m_accept_sock = m_takeover_agent->takeover(); if (m_accept_sock >= 0) { Logger::Info("takeover: using takeover fd %d for server", m_accept_sock); m_httpServerSocket->useExistingSocket(m_accept_sock); needListen = false; m_takeover_agent->requestShutdown(); takoverSucceeded = true; } } if (!takoverSucceeded) { failedToListen(ex, m_httpConfig.bindAddress); } } if (m_takeover_agent) { m_takeover_agent->setupFdServer(m_worker.getEventBase()->getLibeventBase(), m_httpServerSocket->getSocket(), this); } m_httpAcceptor.reset(new HPHPSessionAcceptor(m_httpConfig, this)); m_httpAcceptor->init(m_httpServerSocket.get(), m_worker.getEventBase()); if (m_httpsConfig.isSSL()) { m_httpsServerSocket.reset(new AsyncServerSocket(m_worker.getEventBase())); try { if (m_accept_sock_ssl >= 0) { Logger::Info("inheritfd: using inherited fd %d for ssl", m_accept_sock_ssl); m_httpsServerSocket->useExistingSocket(m_accept_sock_ssl); } else { m_httpsServerSocket->setReusePortEnabled(RuntimeOption::StopOldServer); m_httpsServerSocket->bind(m_httpsConfig.bindAddress); } } catch (const TTransportException& ex) { failedToListen(ex, m_httpsConfig.bindAddress); } m_httpsAcceptor.reset(new HPHPSessionAcceptor(m_httpsConfig, this)); try { m_httpsAcceptor->init(m_httpsServerSocket.get(), m_worker.getEventBase()); } catch (const std::exception& ex) { // Could be some cert thing failedToListen(ex, m_httpsConfig.bindAddress); } } if (needListen) { try { m_httpServerSocket->listen(m_httpConfig.acceptBacklog); } catch (const std::system_error& ex) { failedToListen(ex, m_httpConfig.bindAddress); } } if (m_httpsServerSocket) { try { m_httpsServerSocket->listen(m_httpsConfig.acceptBacklog); } catch (const std::system_error& ex) { failedToListen(ex, m_httpsConfig.bindAddress); } } m_httpServerSocket->startAccepting(); if (m_httpsServerSocket) { m_httpsServerSocket->startAccepting(); } startConsuming(m_worker.getEventBase(), &m_responseQueue); setStatus(RunStatus::RUNNING); folly::AsyncTimeout::attachEventBase(m_worker.getEventBase()); m_worker.start(); m_dispatcher.start(); }