void LocalNode::_redispatchCommands() { bool changes = true; while( changes && !_pendingCommands.empty( )) { changes = false; for( CommandList::iterator i = _pendingCommands.begin(); i != _pendingCommands.end(); ++i ) { Command* command = *i; EQASSERT( command->isValid( )); if( dispatchCommand( *command )) { _pendingCommands.erase( i ); command->release(); changes = true; break; } } } #ifndef NDEBUG if( !_pendingCommands.empty( )) EQVERB << _pendingCommands.size() << " undispatched commands" << std::endl; EQASSERT( _pendingCommands.size() < 200 ); #endif }
bool FrameworkListener::onDataAvailable(SocketClient *c) { char buffer[CMD_BUF_SIZE]; int len; len = TEMP_FAILURE_RETRY(read(c->getSocket(), buffer, sizeof(buffer))); if (len < 0) { SLOGE("read() failed (%s)", strerror(errno)); return false; } else if (!len) return false; if(buffer[len-1] != '\0') SLOGW("String is not zero-terminated"); int offset = 0; int i; for (i = 0; i < len; i++) { if (buffer[i] == '\0') { /* IMPORTANT: dispatchCommand() expects a zero-terminated string */ dispatchCommand(c, buffer + offset); offset = i + 1; } } return true; }
/* * Dispatch command to gang. * * Throw out error to upper try-catch block if anything goes wrong. */ static void cdbdisp_dispatchToGang_async(struct CdbDispatcherState *ds, struct Gang *gp, int sliceIndex, CdbDispatchDirectDesc * dispDirect) { int i; CdbDispatchCmdAsync *pParms = (CdbDispatchCmdAsync*)ds->dispatchParams; /* * Start the dispatching */ for (i = 0; i < gp->size; i++) { CdbDispatchResult* qeResult; SegmentDatabaseDescriptor *segdbDesc = &gp->db_descriptors[i]; Assert(segdbDesc != NULL); if (dispDirect->directed_dispatch) { /* We can direct dispatch to one segment DB only */ Assert(dispDirect->count == 1); if (dispDirect->content[0] != segdbDesc->segindex) continue; } /* * Initialize the QE's CdbDispatchResult object. */ qeResult = cdbdisp_makeResult(ds->primaryResults, segdbDesc, sliceIndex); if (qeResult == NULL) { /* * writer_gang could be NULL if this is an extended query. */ if (ds->primaryResults->writer_gang) ds->primaryResults->writer_gang->dispatcherActive = true; elog(FATAL, "could not allocate resources for segworker communication"); } pParms->dispatchResultPtrArray[pParms->dispatchCount++] = qeResult; if (cdbconn_isBadConnection(segdbDesc)) { char *msg = PQerrorMessage(qeResult->segdbDesc->conn); qeResult->stillRunning = false; ereport(ERROR, (errcode(ERRCODE_GP_INTERCONNECTION_ERROR), errmsg("Connection lost before dispatch to %s: %s", segdbDesc->whoami, msg ? msg : "unknown error"))); } dispatchCommand(qeResult, pParms->query_text, pParms->query_text_len); } }
void INDI::BaseClientQt::listenINDI() { char buffer[MAXINDIBUF]; char errorMsg[MAXRBUF]; int err_code=0; XMLEle ** nodes; XMLEle * root; int inode=0; if (sConnected == false) return; while (client_socket.bytesAvailable() > 0) { qint64 readBytes = client_socket.read(buffer, MAXINDIBUF - 1); if ( readBytes > 0 ) buffer[ readBytes ] = '\0'; nodes=parseXMLChunk(lillp, buffer, readBytes, errorMsg); if (!nodes) { if (errorMsg[0]) { fprintf (stderr, "Bad XML from %s/%d: %s\n%s\n", cServer.c_str(), cPort, errorMsg, buffer); return; } return; } root=nodes[inode]; while (root) { if (verbose) prXMLEle(stderr, root, 0); if ( (err_code = dispatchCommand(root, errorMsg)) < 0) { // Silenty ignore property duplication errors if (err_code != INDI_PROPERTY_DUPLICATED) { IDLog("Dispatch command error(%d): %s\n", err_code, errorMsg); prXMLEle (stderr, root, 0); } } delXMLEle (root); // not yet, delete and continue inode++; root=nodes[inode]; } free(nodes); inode=0; } }
TSS_RESULT getTCSDPacket(struct tcsd_thread_data *data) { if (data->comm.hdr.packet_size != (UINT32)(data->comm.hdr.parm_offset + data->comm.hdr.parm_size)) { LogError("Invalid packet received by TCSD"); return TCSERR(TSS_E_INTERNAL_ERROR); } /* dispatch the command to the TCS */ return dispatchCommand(data); }
TSS_RESULT getTCSDPacket(struct tcsd_thread_data *data) { /* make sure the all the data is present */ if (data->comm.hdr.num_parms > 0 && data->comm.hdr.packet_size != (UINT32)(data->comm.hdr.parm_offset + data->comm.hdr.parm_size)) return TCSERR(TSS_E_INTERNAL_ERROR); /* dispatch the command to the TCS */ return dispatchCommand(data); }
void LocalNode::_dispatchCommand( Command& command ) { EQASSERT( command.isValid( )); const bool dispatched = dispatchCommand( command ); _redispatchCommands(); if( !dispatched ) { command.retain(); _pendingCommands.push_back( &command ); } }
void WebServer::processConnection(char *buff, int *bufflen) { m_client = m_server.available(); if (m_client) { m_readingContent = false; buff[0] = 0; ConnectionType requestType = INVALID; #if WEBDUINO_SERIAL_DEBUGGING > 1 Serial.println("*** checking request ***"); #endif getRequest(requestType, buff, bufflen); #if WEBDUINO_SERIAL_DEBUGGING > 1 Serial.print("*** requestType = "); Serial.print((int)requestType); Serial.println(", request = \""); Serial.print(buff); Serial.println("\" ***"); #endif processHeaders(); #if WEBDUINO_SERIAL_DEBUGGING > 1 Serial.println("*** headers complete ***"); #endif int urlPrefixLen = strlen(m_urlPrefix); if (strcmp(buff, "/robots.txt") == 0) { noRobots(requestType); } else if (requestType == INVALID || strncmp(buff, m_urlPrefix, urlPrefixLen) != 0 || !dispatchCommand(requestType, buff + urlPrefixLen, (*bufflen) >= 0)) { m_failureCmd(*this, requestType, buff, (*bufflen) >= 0); } #if WEBDUINO_SERIAL_DEBUGGING > 1 Serial.println("*** stopping connection ***"); #endif m_client.stop(); } }
bool FrameworkListener::onDataAvailable(SocketClient *c) { char buffer[255]; int len; if ((len = read(c->getSocket(), buffer, sizeof(buffer) -1)) < 0) { SLOGE("read() failed (%s)", strerror(errno)); return false; } else if (!len) return false; int offset = 0; int i; for (i = 0; i < len; i++) { if (buffer[i] == '\0') { dispatchCommand(c, buffer + offset); offset = i + 1; } } return true; }
/***************************************************** ** ** ChildWindow --- OnCommand ** ******************************************************/ void ChildWindow::OnCommand( wxCommandEvent &event ) { if ( ! isvalid ) return; // nothing to do for closing views BasicView *bview = 0; wxObject *oo = event.GetEventObject(); if ( oo ) { if ( oo->GetClassInfo()->IsKindOf( CLASSINFO( MyMenu ))) { MyMenu *menu = (MyMenu*)oo; bview = (BasicView*)menu->getView(); } } if ( event.GetId() >= CMD_CHILD_NEW_TEXT && event.GetId() <= CMD_CHILD_NEW_RASI+30 ) { event.Skip(); // Delegate to parent } else dispatchCommand( event.GetId(), bview ); }
bool FrameworkListener::onDataAvailable(SocketClient *c) { char buffer[CMD_BUF_SIZE]; int len; int last_offset = 0; do{ len = TEMP_FAILURE_RETRY(read(c->getSocket(), buffer+last_offset, sizeof(buffer)-last_offset)); if (len < 0) { SLOGE("read() failed (%s)", strerror(errno)); return false; } else if (!len) return false; /*update buffer len if there are old data*/ len += last_offset; if(buffer[len-1] != '\0') SLOGW("String is not zero-terminated"); int offset = 0; int i; SLOGI("onDataAvailable get %d bytes ", len); for (i = 0; i < len; i++) { if (buffer[i] == '\0') { /* IMPORTANT: dispatchCommand() expects a zero-terminated string */ dispatchCommand(c, buffer + offset); offset = i + 1; } } /*fix not zero-terminated cmd issue*/ if(offset < len){ last_offset = len-offset; if(offset != 0) strncpy(buffer, buffer + offset, last_offset); SLOGW("there is %d bytes left due to non-zero-terminated", last_offset); } }while (buffer[len-1] != '\0'); return true; }
void WebServer::processConnection(char *buff, int *bufflen) { int urlPrefixLen = strlen(m_urlPrefix); m_client = m_server.available(); if (m_client) { m_readingContent = false; buff[0] = 0; ConnectionType requestType = INVALID; getRequest(requestType, buff, bufflen); // don't even look further at invalid requests. // this is done to prevent Webduino from hanging // - when there are illegal requests, // - when someone contacts it through telnet rather than proper HTTP, // - etc. if (requestType != INVALID) { processHeaders(); if (strcmp(buff, "/robots.txt") == 0) { noRobots(requestType); } else if (strcmp(buff, "/favicon.ico") == 0) { favicon(requestType); } } if (requestType == INVALID || strncmp(buff, m_urlPrefix, urlPrefixLen) != 0 || !dispatchCommand(requestType, buff + urlPrefixLen, (*bufflen) >= 0)) { m_failureCmd(*this, requestType, buff, (*bufflen) >= 0); } reset(); if(this->finalCommand != NULL){ this->finalCommand(requestType, this->currentCollection, this->currentModel); this->finalCommand = NULL; } } }
/***************************************************** ** ** BasicView --- OnCommand ** ******************************************************/ void BasicView::OnCommand( wxCommandEvent &event ) { //printf( "BasicView::OnCommand\n" ); if ( dispatchCommand( event.GetId())) OnDataChanged(); else event.Skip(); }
static void thread_DispatchOut(DispatchCommandParms * pParms) { CdbDispatchResult *dispatchResult; int i, db_count = pParms->db_count; /* * The pParms contains an array of SegmentDatabaseDescriptors * to send commands through to. */ for (i = 0; i < db_count; i++) { dispatchResult = pParms->dispatchResultPtrArray[i]; /* * Don't use elog, it's not thread-safe */ if (DEBUG5 >= log_min_messages) { if (dispatchResult->segdbDesc->conn) { write_log ("thread_DispatchCommand working on %d of %d commands. asyncStatus %d", i + 1, db_count, dispatchResult->segdbDesc->conn->asyncStatus); } } dispatchResult->hasDispatched = false; dispatchResult->sentSignal = DISPATCH_WAIT_NONE; dispatchResult->wasCanceled = false; if (!shouldStillDispatchCommand(pParms, dispatchResult)) { /* * Don't dispatch if cancellation pending or no connection. */ dispatchResult->stillRunning = false; if (PQisBusy(dispatchResult->segdbDesc->conn)) write_log (" We thought we were done, because !shouldStillDispatchCommand(), but libpq says we are still busy"); if (PQstatus(dispatchResult->segdbDesc->conn) == CONNECTION_BAD) write_log (" We thought we were done, because !shouldStillDispatchCommand(), but libpq says the connection died?"); } else { /* * Kick off the command over the libpq connection. * * If unsuccessful, proceed anyway, and check for lost connection below. */ if (PQisBusy(dispatchResult->segdbDesc->conn)) { write_log ("Trying to send to busy connection %s %d %d asyncStatus %d", dispatchResult->segdbDesc->whoami, i, db_count, dispatchResult->segdbDesc->conn->asyncStatus); } if (PQstatus(dispatchResult->segdbDesc->conn) == CONNECTION_BAD) { char *msg; msg = PQerrorMessage(dispatchResult->segdbDesc->conn); write_log ("Dispatcher noticed a problem before query transmit: %s (%s)", msg ? msg : "unknown error", dispatchResult->segdbDesc->whoami); /* * Save error info for later. */ cdbdisp_appendMessage(dispatchResult, LOG, ERRCODE_GP_INTERCONNECTION_ERROR, "Error before transmit from %s: %s", dispatchResult->segdbDesc->whoami, msg ? msg : "unknown error"); PQfinish(dispatchResult->segdbDesc->conn); dispatchResult->segdbDesc->conn = NULL; dispatchResult->stillRunning = false; continue; } #ifdef USE_NONBLOCKING /* * In 2000, Tom Lane said: * "I believe that the nonblocking-mode code is pretty buggy, and don't * recommend using it unless you really need it and want to help debug * it.." * * Reading through the code, I'm not convinced the situation has * improved in 2007... I still see some very questionable things * about nonblocking mode, so for now, I'm disabling it. */ PQsetnonblocking(dispatchResult->segdbDesc->conn, TRUE); #endif dispatchCommand(dispatchResult, pParms->query_text, pParms->query_text_len); } } #ifdef USE_NONBLOCKING /* * Is everything sent? Well, if the network stack was too busy, and we are using * nonblocking mode, some of the sends * might not have completed. We can't use SELECT to wait unless they have * received their work, or we will wait forever. Make sure they do. */ { bool allsent = true; /* * debug loop to check to see if this really is needed */ for (i = 0; i < db_count; i++) { dispatchResult = pParms->dispatchResultPtrArray[i]; if (!dispatchResult->stillRunning || !dispatchResult->hasDispatched) continue; if (PQstatus(dispatchResult->segdbDesc->conn) == CONNECTION_BAD) continue; if (dispatchResult->segdbDesc->conn->outCount > 0) { write_log("Yes, extra flushing is necessary %d", i); break; } } /* * Check to see if any needed extra flushing. */ for (i = 0; i < db_count; i++) { int flushResult; dispatchResult = pParms->dispatchResultPtrArray[i]; if (!dispatchResult->stillRunning || !dispatchResult->hasDispatched) continue; if (PQstatus(dispatchResult->segdbDesc->conn) == CONNECTION_BAD) continue; /* * If data remains unsent, send it. Else we might be waiting for the * result of a command the backend hasn't even got yet. */ flushResult = PQflush(dispatchResult->segdbDesc->conn); /* * First time, go through the loop without waiting if we can't * flush, in case we are using multiple network adapters, and * other connections might be able to flush */ if (flushResult > 0) { allsent = false; write_log("flushing didn't finish the work %d", i); } } /* * our first attempt at doing more flushes didn't get everything out, * so we need to continue to try. */ for (i = 0; i < db_count; i++) { dispatchResult = pParms->dispatchResultPtrArray[i]; while (PQisnonblocking(dispatchResult->segdbDesc->conn)) { PQflush(dispatchResult->segdbDesc->conn); PQsetnonblocking(dispatchResult->segdbDesc->conn, FALSE); } } } #endif }
int main(int argc, char **argv) { int choice, scroll, curr, max, status; /* Catch fatal signals and complain about them if running as init */ if (getpid() == 1) { signal(SIGBUS, screech); signal(SIGSEGV, screech); } /* We don't work too well when running as non-root anymore */ if (geteuid() != 0) { fprintf(stderr, "Error: This utility should only be run as root.\n"); return 1; } if (argc > 1 && !strcmp(argv[1], "-fake")) { Fake = TRUE; } /* Set up whatever things need setting up */ systemInitialize(argc, argv); /* Set default flag and variable values */ installVarDefaults(NULL); /* only when multi-user is it reasonable to do this here */ if (!RunningAsInit) installEnvironment(); if (argc > 1 && !strcmp(argv[1], "-fake")) { variable_set2(VAR_DEBUG, "YES"); msgConfirm("I'll be just faking it from here on out, OK?"); } /* Try to preserve our scroll-back buffer */ if (OnVTY) { for (curr = 0; curr < 25; curr++) putchar('\n'); } /* Move stderr aside */ if (DebugFD) dup2(DebugFD, 2); #ifdef PCCARD /* Initialize PC-card */ pccardInitialize(); #endif /* Probe for all relevant devices on the system */ deviceGetAll(); /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */ if (!RunningAsInit) { int i, start_arg; if (!strstr(argv[0], "sysinstall")) start_arg = 0; else if (Fake) start_arg = 2; else start_arg = 1; for (i = start_arg; i < argc; i++) { if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) systemShutdown(1); } if (argc > start_arg) systemShutdown(0); } else dispatch_load_file_int(TRUE); status = setjmp(BailOut); if (status) { msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n" "If you can reproduce the problem, please turn Debug on in\n" "the Options menu for the extra information it provides in\n" "debugging problems like this.", status); systemShutdown(status); } /* Begin user dialog at outer menu */ dialog_clear(); while (1) { choice = scroll = curr = max = 0; dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); if (getpid() != 1 || !msgYesNo("Are you sure you wish to exit? The system will reboot\n" "(be sure to remove any floppies from the drives).")) break; } /* Say goodnight, Gracie */ systemShutdown(0); return 0; /* We should never get here */ }
// runloop. void loop() { if (readIncoming()) { dispatchCommand(); } }