int SelectPolicy::waitForEvent(int timeout) { struct timeval time; int ret; fd_set *set[3]; Clock clock; while (_wait) { int t = this->handleTimers(timeout); if (t >= 0) { time.tv_sec = t / 1000; time.tv_usec = (t % 1000) * 1000; } fd_set rs = _read_set, ws = _write_set, es = _except_set; set[0] = (_rsize == 0) ? nullptr : &rs; set[1] = (_wsize == 0) ? nullptr : &ws; set[2] = (_esize == 0) ? nullptr : &es; #if defined (_WIN32) if (!set[0] && !set[1] && !set[2]) { Net::Clock::sleep(t); continue ; } else #endif ret = ::select(_maxfd + 1, set[0], set[1], set[2], (t < 0) ? nullptr : &time); if ((ret == -1 && errno == EINTR) || (ret == 0 && timeout != 0)) continue ; if (ret == -1) std::cerr << Net::getLastError() << std::endl; if (ret == -1 || (ret == 0 && timeout == 0)) return ret; if (timeout > 0) { timeout -= clock.getElapsedTime(); clock.update(); if (timeout < 0) timeout = 0; } for (auto it = _sockets.begin(); it != _sockets.end();) { auto socket = it->first; auto handler = socket->getEventHandler(); auto handle = socket->getHandle(); ++it; if (FD_ISSET(handle, &es)) handler->handleClose(*socket); else { if (FD_ISSET(handle, &rs) && handler->handleInput(*socket) <= 0) handler->handleClose(*socket); else if (FD_ISSET(handle, &ws) && handler->handleOutput(*socket) <= 0) handler->handleClose(*socket); } } } return 0; }
int main(int argc, char **argv) { ServerDomain = nextArg(); ServerPort = toValue(nextArg()); MutexName = nextArg(); StartEventName = nextArg(); AnswerEventName = nextArg(); ParamsFile = nextArg(); AnswerFile = nextArg(); errorCase(isEmptyJTkn(ServerDomain)); errorCase(ServerPort < 1 || 0xffff < ServerPort); errorCase(isEmptyJTkn(MutexName)); errorCase(isEmptyJTkn(StartEventName)); errorCase(isEmptyJTkn(AnswerEventName)); errorCase(isEmptyJTkn(ParamsFile)); errorCase(isEmptyJTkn(AnswerFile)); MutexHandle = mutexOpen(MutexName); StartEventHandle = eventOpen(StartEventName); AnswerEventHandle = eventOpen(AnswerEventName); StopAppEventHandle = eventOpen_x(xcout("cerulean.charlotte Factory Requester stop app event object %s %u", c_md5_makeHexHashLine(ServerDomain), ServerPort)); if(argIs("/T")) { Serializer = TextFltr; Deserializer = TextFltr; } if(argIs("/TS") || argIs("/TP")) { Serializer = TextFltr; } if(argIs("/TD") || argIs("/TA")) { Deserializer = TextFltr; } if(argIs("/S")) { eventSet(StopAppEventHandle); } else if(argIs("/1")) { error(); // todo: request at once } else { MainLoop(); } handleClose(MutexHandle); handleClose(StartEventHandle); handleClose(AnswerEventHandle); handleClose(StopAppEventHandle); }
bool TCPServer::handleIO( PSocketContext pSocketContext, PIOContext pIOContext, BOOL status) { if(!status) { if(!handleError(pSocketContext)) { return false; } return true; } if( (0 == pIOContext->overlapped.InternalHigh) && (pIOContext->opType & (OPT_READ + OPT_WRITE))) { handleClose(pSocketContext); return true; } switch(pIOContext->opType) { case OPT_ACCEPT: handleAccept(pSocketContext, pIOContext); break; case OPT_READ: handleRead(pSocketContext, pIOContext); break; case OPT_WRITE: handleWrite(pSocketContext, pIOContext); break; default: LOG("操作类型参数异常"); break; } return true; }
void OscController::handleOpen() { handleClose(false); if (!_params.enabled.get()) { return; } if (_params.inputEnabled.get()) { _receiver = std::make_shared<ofxOscReceiver>(); _receiver->setup(_params.inputPort.get()); } if (_params.outputEnabled.get()) { std::string host = _params.outputHost.get(); if (host.empty()) { host = _params.outputHost.getDefaultValue(); } _sender = std::make_shared<ofxOscSender>(); _sender->setup(host, _params.outputPort.get()); ofxOscMessage hello; hello.setAddress("/hi"); hello.addBoolArg(true); hello.addFloatArg(ofGetElapsedTimef()); _sender->sendMessage(hello, false); } loadBindings(_appParams, _params.paramPrefix.get()); sendParameterConfigs(); sendAllParameters(); }
static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socket) { if (cnx->coClosing && (socket->sentPos == other_socket->recvPos)) { PERROR("rinetd: local closed and no more output"); logEvent(cnx, cnx->server, cnx->coLog); closesocket(socket->fd); socket->fd = INVALID_SOCKET; return; } int got = send(socket->fd, other_socket->buffer + socket->sentPos, other_socket->recvPos - socket->sentPos, 0); if (got < 0) { if (GetLastError() == WSAEWOULDBLOCK) { return; } if (GetLastError() == WSAEINPROGRESS) { return; } handleClose(cnx, socket, other_socket); return; } socket->sentPos += got; socket->sentBytes += got; if (socket->sentPos == other_socket->recvPos) { socket->sentPos = other_socket->recvPos = 0; } }
void Connection::shutDown(int after) { if(m_status == Disconnecting || m_status == Disconnected) { return; } m_status = Disconnecting; if(after == 0) { handleClose(); } else { ConnectionPtr_t conn = shared_from_this(); m_loop->runInWheel(after, std::bind(&Connection::handleClose, conn)); } }
void TcpConnection::handleRead(Timestamp receiveTime) { LOG_DEBUG("TcpConnection::handleRead fd = %d, state = %s", socket_->fd(), getState(state_)); loop_->assertInLoopThread(); std::string data; size_t n = socket_->recv(data); inputBuffer_.write(data); if (n > 0) { messageCallback_(shared_from_this(), &inputBuffer_, receiveTime); } else if (n == 0) { handleClose(); } else { handleError(); } }
/* Backend is not calling FE_PaneChanged on Ldap Directory change right now, therefore, this method is not in use. However, the backend should really call FE_PaneChanged when directory order is changed in the prefs. That notification is hooked up for address book not for ldap search. Has filed a bug to phil */ void XFE_LdapSearchView::paneChanged(XP_Bool /*asynchronous*/, MSG_PANE_CHANGED_NOTIFY_CODE /* notify_code */, int32 /*value*/) { /* Shall we free existing list ? */ m_directories = FE_GetDirServers(); int nDirs = XP_ListCount(m_directories); XP_Bool found = False; for (int i=0; i < nDirs; i++) { DIR_Server *dir = (DIR_Server *) XP_ListGetObjectNum(m_directories,i+1); if (dir == m_dir || (dir && m_dir && (dir->dirType == m_dir->dirType))) { if ((dir->serverName==NULL && m_dir->serverName==NULL) || (dir->serverName && m_dir->serverName && !XP_STRCMP(dir->serverName, m_dir->serverName))) { found = True; break; }/* if */ }/* if */ }/* for i*/ if (!found) { /* m_dir got deleted */ m_dir = NULL; if ( !m_dir && nDirs ) { /* there are still some directories installed, pick the first one for best guess */ m_dir = (DIR_Server *) XP_ListGetObjectNum(m_directories, 1 ); } } if (!m_dir) /* non-directory left.... close search dialog*/ handleClose(); }
void Connection::handleRead() { if(m_status != Connected) { return; } char buf[MaxReadBuffer]; int n = read(m_fd, buf, sizeof(buf)); if(n > 0) { StackBuffer b(buf, n); updateActiveTime(); m_callback(shared_from_this(), Conn_ReadEvent, &b); return; } else if(n == 0) { handleClose(); return; } else { int err = errno; if(err == EAGAIN || err == EWOULDBLOCK) { //try write later, can enter here? LOG_INFO("read %s", errorMsg(err)); return; } handleError(); return; } }
static void handleRead(ConnectionInfo *cnx, Socket *socket, Socket *other_socket) { if (RINETD_BUFFER_SIZE == socket->recvPos) { return; } int got = recv(socket->fd, socket->buffer + socket->recvPos, RINETD_BUFFER_SIZE - socket->recvPos, 0); if (got < 0) { if (GetLastError() == WSAEWOULDBLOCK) { return; } if (GetLastError() == WSAEINPROGRESS) { return; } } if (got <= 0) { /* Prepare for closing */ handleClose(cnx, socket, other_socket); return; } socket->recvBytes += got; socket->recvPos += got; }
SearchWidget::SearchWidget(SearchOptions options, SearchMode mode, SearchButtons buttons, QWidget *parent) : QWidget(parent), ui(new Ui::SearchWidget) { ui->setupUi(this); setWindowTitle(tr("Search Widget")); int labelWidth = fontMetrics().width(ui->labelReplace->text()); ui->labelFind->setMinimumWidth(labelWidth); ui->labelReplace->setMinimumWidth(labelWidth); connect(ui->findPrevious, SIGNAL(clicked()), SLOT(handleFindPrevious())); connect(ui->findNext, SIGNAL(clicked()), SLOT(handleFindNext())); connect(ui->replacePrevious, SIGNAL(clicked()), SLOT(handleReplacePrevious())); connect(ui->replaceNext, SIGNAL(clicked()), SLOT(handleReplaceNext())); connect(ui->replaceAll, SIGNAL(clicked()), SLOT(handleReplaceAll())); connect(ui->close, SIGNAL(clicked()), SLOT(handleClose())); connect(ui->searchString, SIGNAL(textChanged(QString)), SLOT(handleSearchStringChanged(QString))); connect(ui->replaceString, SIGNAL(textChanged(QString)), SLOT(handleReplaceStringChanged(QString))); m_searchOptionsMenu = new QMenu(tr("Search Options"), this); m_searchOptionsMenu->setObjectName(objectName()); m_searchCaseSensitive = new QAction(tr("Case Sensitive"), this); m_searchCaseSensitive->setCheckable(true); m_searchCaseSensitive->setObjectName(objectName()); m_searchOptionsMenu->addAction(m_searchCaseSensitive); connect(m_searchCaseSensitive, SIGNAL(triggered()), SLOT(handleOptionsChanged())); m_searchWholeWordsOnly = new QAction(tr("Whole Words Only"), this); m_searchWholeWordsOnly->setCheckable(true); m_searchWholeWordsOnly->setObjectName(objectName()); m_searchOptionsMenu->addAction(m_searchWholeWordsOnly); connect(m_searchWholeWordsOnly, SIGNAL(triggered()), SLOT(handleOptionsChanged())); m_searchOptionsMenu->addSeparator(); m_searchRegEx = new QAction(tr("Regular Expression"), this); m_searchRegEx->setObjectName(objectName()); m_searchRegEx->setCheckable(true); m_searchOptionsMenu->addAction(m_searchRegEx); m_searchWildcard = new QAction(tr("Wildcard Expression"), this); m_searchWildcard->setCheckable(true); m_searchWildcard->setObjectName(objectName()); m_searchOptionsMenu->addAction(m_searchWildcard); m_searchFixedString = new QAction(tr("Fixed String"), this); m_searchFixedString->setCheckable(true); m_searchFixedString->setObjectName(objectName()); m_searchOptionsMenu->addAction(m_searchFixedString); m_searchPatternGroup = new QActionGroup(this); m_searchPatternGroup->addAction(m_searchRegEx); m_searchPatternGroup->addAction(m_searchWildcard); m_searchPatternGroup->addAction(m_searchFixedString); m_searchWildcard->setChecked(true); connect(m_searchPatternGroup, SIGNAL(triggered(QAction*)), SLOT(handleOptionsChanged())); ui->searchOptions->setPopupMode(QToolButton::InstantPopup); ui->searchOptions->setMenu(m_searchOptionsMenu); setSearchButtons(buttons); setSearchOptions(options); setSearchMode(mode); }
OscController::~OscController() { handleClose(false); _params.enabled.changed.removeListeners(this); _params.inputEnabled.changed.removeListeners(this); _params.outputEnabled.changed.removeListeners(this); }
mainlayout->setContentsMargins(5, 5, 5, 5); setLayout(mainlayout); m_cloesButton = new DImageButton(":/images/dark/images/dock_preview_close_normal.png", ":/images/dark/images/dock_preview_close_hover.png", ":/images/dark/images/dock_preview_close_press.png", ":/images/dark/images/dock_preview_close_press.png", this); m_cloesButton->setFixedSize(20, 20); m_cloesButton->setCheckable(false); m_cloesButton->hide(); } void ImageButton::initConnect(){ connect(this, SIGNAL(toggled(bool)), this, SLOT(handleChecked(bool))); connect(m_cloesButton, SIGNAL(clicked()), this, SLOT(handleClose())); } QString ImageButton::getId(){ return m_id; } void ImageButton::setId(QString id){ m_id = id; } bool ImageButton::isDeletable(){ return m_isDeletable; } void ImageButton::setDeletable(bool flag){
OisInputListener::~OisInputListener() { handleClose(); }
Value Interpreter::exec(const InstructionList &instructions, Bindings &bindings) { Stack stack; ClosureValues closureValues; for(InstructionList::const_iterator it = instructions.begin() ; it != instructions.end() ; ++it) { Instruction::Type type = it->type(); const Value &value = it->value(); switch(type) { case Instruction::PUSH: if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " push " << value << '\n'; } stack.push_back(value); break; case Instruction::CALL: { if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " call " << value << '\n'; } Value result = handleFunction(it->sourceLocation(), value, stack, bindings); stack.push_back(result); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " return value " << result << '\n'; } } break; case Instruction::JUMP: { int instructionsToSkip = getInstructionsToSkip(type, value); int remaining = instructions.end() - it; if(remaining < instructionsToSkip) { throw CompilerBug("insufficient instructions available to skip! (remaining: " + str(remaining) + " < instructionsToSkip: " + str(instructionsToSkip) + ")"); } if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " jumping back " << instructionsToSkip << '\n'; } it += instructionsToSkip; } break; case Instruction::LOOP: { int instructionsToSkip = getInstructionsToSkip(type, value); int instructionsAvailable = instructions.size(); // Note: signed type is important! if(instructionsAvailable < instructionsToSkip) { throw CompilerBug("insufficient instructions available to loop! (instructionsToSkip: " + str(instructionsToSkip) + " > instructions.size(): " + str(instructions.size()) + ")"); } if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " looping back " << instructionsToSkip << " instructions\n"; } it -= instructionsToSkip; } break; case Instruction::CLOSE: { if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " close " << value << '\n'; } Value result = handleClose(value, stack, closureValues, bindings); stack.push_back(result); } break; case Instruction::COND_JUMP: { if(stack.empty()) { throw CompilerBug("empty stack when testing conditional jump"); } int instructionsToSkip = getInstructionsToSkip(type, value); int remaining = instructions.end() - it; if(remaining < instructionsToSkip) { throw CompilerBug("insufficient instructions available to skip! (remaining: " + str(remaining) + " < instructionsToSkip: " + str(instructionsToSkip) + ")"); } Value top = pop(stack); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " jumping back " << instructionsToSkip << " if " << top << '\n'; } if(top.isFalsey()) { it += instructionsToSkip; } } break; case Instruction::REF_LOCAL: handleRef(Bindings::Local, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " local ref '" << value.string() << "' is " << stack.back() << '\n'; } break; case Instruction::INIT_LOCAL: { const Value &intialisedValue = handleInit(Bindings::Local, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " local init '" << value.string() << "' to " << intialisedValue << '\n'; } } break; case Instruction::ASSIGN_LOCAL: { const Value &assignedValue = handleAssign(Bindings::Local, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " local assign '" << value.string() << "' to " << assignedValue << '\n'; } } break; case Instruction::REF_GLOBAL: handleRef(Bindings::Global, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " global ref '" << value.string() << "' is " << stack.back() << '\n'; } break; case Instruction::INIT_GLOBAL: { const Value &intialisedValue = handleInit(Bindings::Global, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " global init '" << value.string() << "' to " << intialisedValue << '\n'; } } break; case Instruction::ASSIGN_GLOBAL: { const Value &assignedValue = handleAssign(Bindings::Global, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " global assign '" << value.string() << "' to " << assignedValue << '\n'; } } break; case Instruction::REF_CLOSURE: handleRef(Bindings::Closure, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " closure ref '" << value.string() << "' is " << stack.back() << '\n'; } break; case Instruction::INIT_CLOSURE: { Identifier identifier = Identifier(value.string()); Bindings::ValuePtr &binding = bindings.getPointer(identifier); closureValues.push_back(ClosedNameAndValue(identifier, binding)); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " closure init '" << value.string() << "' is " << *binding << '\n'; } } break; case Instruction::ASSIGN_CLOSURE: { const Value &assignedValue = handleAssign(Bindings::Closure, value, stack, bindings); if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " closure assign '" << value.string() << "' to " << assignedValue << '\n'; } } break; case Instruction::MEMBER_ACCESS: { if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " member access " << value << '\n'; } assert(value.isString()); const std::string &memberName = value.string(); Value top = pop(stack); if(!top.isObject()) { throw ExecutionError(it->sourceLocation(), "Member access instruction requires an object but got " + str(top)); } const Value::Object &object = top.object(); Value::Object::const_iterator memberIterator = object.find(memberName); if (memberIterator == object.end()) { throw ExecutionError(it->sourceLocation(), "Unknown member name " + memberName + " for " + str(top)); } if(settings_.trace) { std::cout << "DEBUG: " << it->sourceLocation() << " member access " << value.string() << "." << memberName << " was " << memberIterator->second << '\n'; } stack.push_back(memberIterator->second); } break; default: throw CompilerBug("unhandled instruction type: " + str(type)); } if (settings_.trace) { if (stack.empty()) { std::cout << "Stack is empty\n"; } else { std::cout << "Stack contains " << stack.size() << " entries:\n"; int index = 0; for(Stack::const_iterator it = stack.begin() ; it != stack.end() ; ++it) { ++index; std::cout << index << ": " << *it << '\n'; } } if (closureValues.empty()) { std::cout << "closureValues is empty\n"; } else { std::cout << "closureValues contains " << closureValues.size() << " entries:\n"; int index = 0; for(const ClosedNameAndValue &closedValue: closureValues) { ++index; std::cout << index << ": " << closedValue.first << " -> " << *closedValue.second << " @ " << closedValue.second << '\n'; } } } } return stack.empty() ? Value::nil() : pop(stack); }