void update() { if(!playing) return; if(GCODES.isFull()) { return; } if(!readHasNext()) { finishRead(); return; } char buf[MAX_GCODE_FRAG_SIZE] = {0}; int x=0; for(;x < MAX_GCODE_FRAG_SIZE && readHasNext(); x++) { buf[x] = readNext(); if(buf[x] <= 32) break; } if(buf[x] > 32) { HOST.write("SRO\n"); // TODO: Buffer overrun... error out return; } GCODES.parsebytes(buf, x, SD_SOURCE); }
void reset() { if (playing) finishRead(); if (dd != 0) { fat_close_dir(dd); dd = 0; } if (fs != 0) { fat_close(fs); fs = 0; } if (partition != 0) { partition_close(partition); partition = 0; } }
Trace * OTFConverter::importOTF2(QString filename, OTFImportOptions *_options) { // Keep track of options options = _options; // Start with the rawtrace similar to what we got from PARAVER OTF2Importer * importer = new OTF2Importer(); rawtrace = importer->importOTF2(filename.toStdString().c_str(), options->enforceMessageSizes); emit(finishRead()); convert(); delete importer; trace->fullpath = filename; return trace; }
bool PipeBase::performRead(PipeData* data, IPCManager* mng) { if (!data || !mng) return true; DWORD read; BOOL fSuccess = ReadFile(data->hPipe, data->buffer, BUFSIZE, &read, &data->oOverlap); if (fSuccess) { data->size = read; finishRead(data, mng); } else if (!fSuccess && (GetLastError() == ERROR_IO_PENDING)) { data->fPendingIO = TRUE; } else { gcAssert(false); } return false; }
void PipeBase::processEvents() { DWORD dwWait = WaitForMultipleObjects(getNumEvents(), m_hEventsArr, FALSE, 500); if (isStopped()) return; if (dwWait == WAIT_TIMEOUT) return; if (dwWait == WAIT_FAILED) { DWORD lErr = GetLastError(); return; } // dwWait shows which pipe completed the operation. size_t i = dwWait - WAIT_OBJECT_0; // determines which pipe if (i < 0 || i > (getNumEvents() - 1)) { printf("Index out of range.\n"); return; } PipeData* data = getData(i); DWORD cbRet = 0; #ifdef IPC_DEBUG if (fh) { fprintf(fh, "Triggered event %d\n", i); fflush(fh); } #endif //printf("Event %d, P: %d\n", i, data->fPendingIO); // Get the result if the operation was pending. if (data->fPendingIO) { BOOL fSuccess = GetOverlappedResult(data->hPipe, &data->oOverlap, &cbRet, FALSE); //printf("Pending S: %d A: %d P: %d\n", fSuccess, cbRet, data->pendingConnection); if (data->pendingConnection) { if (!fSuccess) throw gcException(ERR_PIPE, GetLastError(), gcString("Error {0}.\n", GetLastError())); data->pendingConnection = false; data->fPendingIO = FALSE; } else { DWORD err = GetLastError(); //Buffer is full. Wait for space if (err == ERROR_IO_INCOMPLETE) fSuccess = GetOverlappedResult(data->hPipe, &data->oOverlap, &cbRet, TRUE); if (!fSuccess || (cbRet == 0 && data->sender == false)) // || (cbRet != data->size && data->sender == true) { disconnectAndReconnect(i); ResetEvent(m_hEventsArr[i]); printf("Disconnect pending!\n"); return; } if (!data->sender) { data->size = cbRet; finishRead(data, getManager(i)); } } } bool res = false; // The pipe state determines which operation to do next. if (data->sender) res = performWrite(data, getManager(i)); else res = performRead(data, getManager(i)); if (res) ResetEvent(m_hEventsArr[i]); }