int ExtConn::connectEx(Multiplexer *pMplx) { int fd; int ret; ret = CoreSocket::connect(m_pWorker->getServerAddr(), pMplx->getFLTag(), &fd, 1); m_iReqProcessed = 0; m_iCPState = 0; m_iToStop = 0; if ((fd == -1) && (errno == ECONNREFUSED)) ret = CoreSocket::connect(m_pWorker->getServerAddr(), pMplx->getFLTag(), &fd, 1); if (fd != -1) { LS_DBG_L(this, "[ExtConn] connecting to [%s]...", m_pWorker->getURL()); m_tmLastAccess = DateTime::s_curTime; ::fcntl(fd, F_SETFD, FD_CLOEXEC); init(fd, pMplx); if (ret == 0) { m_iState = PROCESSING; onWrite(); } else m_iState = CONNECTING; return 0; } return LS_FAIL; }
void FileWriteBytestream::write(const std::vector<unsigned char>& data) { if (data.empty()) { return; } if (!stream) { stream = new boost::filesystem::ofstream(file, std::ios_base::out|std::ios_base::binary); } assert(stream->good()); stream->write(reinterpret_cast<const char*>(&data[0]), boost::numeric_cast<std::streamsize>(data.size())); onWrite(data); }
void PropertyStream::Source::write (PropertyStream& stream) { Map map (m_name, stream); onWrite (map); SharedState::Access state (m_state); for (List <Item>::iterator iter (state->children.begin()); iter != state->children.end(); ++iter) { Source& source (iter->source()); source.write (stream); } }
void http_session::do_write(std::string &&respons) { std::weak_ptr<http_session> wp(shared_Derived_from_this<http_session>()); boost::asio::async_write(*socket_, boost::asio::buffer(respons.c_str(), respons.length()), [wp](const boost::system::error_code &ec, std::size_t length){ auto sp(wp.lock()); if (sp) { //业务处理完成,取消定时器 boost::system::error_code error; sp->timer_.cancel(error); sp->onWrite(ec, length); } }); }
// BLEイベントを受け取ります。 void senstickMetaDataService_handleBLEEvent(ble_evt_t * p_ble_evt) { switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: context.connection_handle = p_ble_evt->evt.gap_evt.conn_handle; break; case BLE_GAP_EVT_DISCONNECTED: context.connection_handle = BLE_CONN_HANDLE_INVALID; break; case BLE_GATTS_EVT_WRITE: onWrite(p_ble_evt); break; case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: onRWAuthReq(p_ble_evt); default: break; } }
int LsapiConn::connect( Multiplexer * pMplx ) { LsapiWorker * pWorker = (LsapiWorker *)getWorker(); if ( pWorker->selfManaged() ) return ExtConn::connect( pMplx ); int fds[2]; errno = ECONNRESET; if ( socketpair( AF_UNIX, SOCK_STREAM, 0, fds ) == -1 ) { LOG_ERR(( "[LsapiConn::connect()] socketpair() failed!" )); return -1; } fcntl( fds[0], F_SETFD, FD_CLOEXEC ); setReqProcessed( 0 ); setToStop( 0 ); //if ( pApp->getCurInstances() >= pApp->getConfig().getInstances() ) // return -1; m_pid = LocalWorker::workerExec( pWorker->getConfig(), fds[1] ); ::close( fds[1] ); if ( m_pid == -1 ) { ::close( fds[0] ); return -1; } else { if ( D_ENABLED( DL_LESS ) ) LOG_D(( "[%s] add child process pid: %d", pWorker->getName(), m_pid )); PidRegistry::add( m_pid, pWorker, 0 ); } ::fcntl( fds[0], F_SETFL, HttpGlobals::getMultiplexer()->getFLTag() ); init( fds[0], pMplx ); //Increase the number of successful request to avoid max connections reduction. incReqProcessed(); setState( PROCESSING ); onWrite(); return 1; }
int EdStream::handleEvents(short event) { int ret = 0; LS_DBG_L("EdStream::handleEvent(), fd: %d, event: %hd", getfd(), event); if (event & POLLIN) { ret = onRead(); if (!getAssignedRevent()) goto EVENT_DONE; } if (event & POLLHUP) { if ((ret != -1) || (getHupCounter() > 50)) ret = onHangup(); else if (getHupCounter() > 100) abort(); if (!getAssignedRevent()) goto EVENT_DONE; } if ((ret != -1) && (event & POLLHUP)) { ret = onHangup(); if (!getAssignedRevent()) return 0; } if ((ret != -1) && (event & POLLOUT)) { ret = onWrite(); if (!getAssignedRevent()) goto EVENT_DONE; } if ((ret != -1) && (event & POLLERR)) { ret = onError(); if (!getAssignedRevent()) return 0; } EVENT_DONE: if (ret != -1) onEventDone(event); return 0; }
int FileAction::onClose(ServerContext& ctxt, FileServer& server, handle_t *handle) { int status = 0; #if 0 if (handle->h_special_write) { status = onWrite(ctxt, server, handle->h_path.c_str(), handle->h_contents); if (status >= 0) { status = 0; } } #endif //ctxt.getSession().disposeHandle(handle); handle->h_open = false; handle->h_handle = NULL; return status; }
void StemmedFileProcessingDialog::processFiles(const QString &inFile, const QString &outFile) { ui->cbxReading->setText(ui->cbxReading->text() + " " + inFile); ui->cbxWriting->setText(ui->cbxWriting->text() + " " + outFile); this->in = inFile; this->out = outFile; QThread* t = new QThread(this); StemmedFileParserController* controller = new StemmedFileParserController(this); controller->moveToThread(t); t->start(); QObject::connect(this, SIGNAL(read(QString)), controller, SLOT(onRead(QString)), Qt::QueuedConnection); QObject::connect(this, SIGNAL(process()), controller, SLOT(onProcess()), Qt::QueuedConnection); QObject::connect(this, SIGNAL(write(QString)), controller, SLOT(onWrite(QString)), Qt::QueuedConnection); QObject::connect(this, SIGNAL(generateHistograms(QString)), controller, SLOT(onGenerateHistograms(QString)), Qt::QueuedConnection); QObject::connect(controller, SIGNAL(readDone(bool)), this, SLOT(onReadDone(bool)), Qt::QueuedConnection); QObject::connect(controller, SIGNAL(processDone()), this, SLOT(onProcessDone()), Qt::QueuedConnection); QObject::connect(controller, SIGNAL(writeDone(bool)), this, SLOT(onWriteDone(bool)), Qt::QueuedConnection); QObject::connect(controller, SIGNAL(generateHistogramsDone(bool, QString)), this, SLOT(onGenerateHistogramsDone(bool, QString)), Qt::QueuedConnection); emit read(this->in); this->show(); }
void PropertyStream::Source::write_one (PropertyStream& stream) { Map map (m_name, stream); onWrite (map); }