void AsyncSerial::readEnd(const boost::system::error_code& error, size_t bytes_transferred) { if(error) { //error can be true even because the serial port was closed. //In this case it is not a real error, so ignore if(isOpen()) { _log.Log(LOG_ERROR,"Serial Port closed!... Error: %s", error.message().c_str()); clearReadCallback(); close(); doClose(); setErrorStatus(true); } } else { if(pimpl->callback) pimpl->callback(pimpl->readBuffer, bytes_transferred); doRead(); } }
/*! Read the file \a fileName from the existing DAE database \a dae. The given \a fileName must already be loaded into the DAE. Useful if multiple documents are stored in one DAE database or if an application needs to access the DAE itself to extract data that is not processed by the loader. */ NodeTransitPtr ColladaGlobal::read(DAE *dae, const std::string &fileName) { NodeTransitPtr rootN(NULL); _pathHandler.clearPathList(); _pathHandler.clearBaseFile(); _pathHandler.push_frontCurrentDir( ); _pathHandler.setBaseFile (fileName.c_str()); _docPath = fileName; _dae = dae; rootN = doRead(); _docPath.clear(); _dae = NULL; return rootN; }
gep::DirectoryWatcher::DirectoryWatcher(const char* path, WatchSubdirs::Enum watchSubdirs, uint32 watch) { m_watchSubdirs = watchSubdirs; m_filter = 0; if(watch & Watch::reads) m_filter |= FILE_NOTIFY_CHANGE_LAST_ACCESS; if(watch & Watch::writes) m_filter |= FILE_NOTIFY_CHANGE_LAST_WRITE; if(watch & Watch::creates) m_filter |= FILE_NOTIFY_CHANGE_CREATION; if(watch & Watch::renames) m_filter |= FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME; m_directoryHandle = CreateFileA( path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, nullptr); if(m_directoryHandle == INVALID_HANDLE_VALUE) { std::ostringstream msg; msg << "Couldn't open directory '" << path << "'. Maybe it does not exist?"; throw Exception(msg.str()); } m_completionPort = CreateIoCompletionPort(m_directoryHandle, nullptr, 0, 1); if(m_completionPort == INVALID_HANDLE_VALUE) { std::ostringstream msg; msg << "Couldn't create io completion port for directory '" << path << "'"; throw Exception(msg.str()); } doRead(); }
int_type underflow() { // if there is still data, then return it if ( gptr() < egptr() ) return static_cast<int_type>(*uptr()); assert ( gptr() == egptr() ); // load data size_t const g = doRead(buffer.begin(),buffersize); // set buffer pointers setg(buffer.begin(),buffer.begin(),buffer.begin()+g); // update start of buffer position readpos += g; if ( g ) return static_cast<int_type>(*uptr()); else return traits_type::eof(); }
void TimedTextPlayer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatPause: { mSendSubtitleGeneration++; break; } case kWhatRetryRead: { int64_t seekTimeUs; int seekMode; if (msg->findInt64("seekTimeUs", &seekTimeUs) && msg->findInt32("seekMode", &seekMode)) { MediaSource::ReadOptions options; options.setSeekTo( seekTimeUs, static_cast<MediaSource::ReadOptions::SeekMode>(seekMode)); doRead(&options); } else { doRead(); } break; } case kWhatSeek: { int64_t seekTimeUs = 0; msg->findInt64("seekTimeUs", &seekTimeUs); if (seekTimeUs < 0) { sp<MediaPlayerBase> listener = mListener.promote(); if (listener != NULL) { int32_t positionMs = 0; listener->getCurrentPosition(&positionMs); seekTimeUs = positionMs * 1000ll; } } doSeekAndRead(seekTimeUs); break; } case kWhatSendSubtitle: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mSendSubtitleGeneration) { // Drop obsolete msg. break; } sp<RefBase> obj; if (msg->findObject("subtitle", &obj)) { sp<ParcelEvent> parcelEvent; parcelEvent = static_cast<ParcelEvent*>(obj.get()); notifyListener(&(parcelEvent->parcel)); doRead(); } else { notifyListener(); } break; } case kWhatSetSource: { sp<RefBase> obj; msg->findObject("source", &obj); if (obj == NULL) break; if (mSource != NULL) { mSource->stop(); } mSource = static_cast<TimedTextSource*>(obj.get()); status_t err = mSource->start(); if (err != OK) { notifyError(err); break; } Parcel parcel; err = mSource->extractGlobalDescriptions(&parcel); if (err != OK) { notifyError(err); break; } notifyListener(&parcel); break; } } }
int main() { int i; char* argv[8]; int argc; printf_register(serial_putchar); printf("waiting..."); // Wait a short while for(i = 0; i < 10000; ++i) asm volatile ("nop"); printf("configuring..."); i2c_init(); argv[0] = "1"; argc = 1; doConfig(argv, argc); printf("done.\n"); while (1) { printf("\n> "); argc = readcmd(argv, 8); printf("\r\n> "); if(argc > 0) { switch(argv[0][0]) { case 'S': doSet(argv, argc); break; case 'G': doGet(argv, argc); break; case 'R': doResult(argv, argc); break; case 'W': doWrite(argv, argc); break; case 'X': doRead(argv, argc); break; case 'Z': doStatus(argv, argc); break; case 'I': switch(argv[0][1]) { case 'I': i2c_init(); break; case 'W': doI2CWrite(argv, argc); break; case 'R': doI2CRead(argv, argc); break; case 'C': doConfig(argv, argc); break; } break; } } } }
//! Read binary data from I/O handle. //! @param[in] data data buffer. //! @param[in] length number of bytes to read. //! @return number of bytes read. size_t read(uint8_t* data, size_t length) { return doRead(data, length); }
int main (int argc, char *argv []) { int i ; int model, rev, mem, maker, overVolted ; if (getenv ("WIRINGPI_DEBUG") != NULL) { printf ("gpio: wiringPi debug mode enabled\n") ; wiringPiDebug = TRUE ; } if (argc == 1) { fprintf (stderr, "%s\n", usage) ; return 1 ; } // Help if (strcasecmp (argv [1], "-h") == 0) { printf ("%s: %s\n", argv [0], usage) ; return 0 ; } // Sort of a special: if (strcmp (argv [1], "-R") == 0) { printf ("%d\n", piBoardRev ()) ; return 0 ; } // Version & Warranty if (strcmp (argv [1], "-V") == 0) { printf ("%d\n", piBoardRev ()) ; return 0 ; } if (strcmp (argv [1], "-v") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ; printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ; printf ("For details type: %s -warranty\n", argv [0]) ; printf ("\n") ; piBoardId (&model, &rev, &mem, &maker, &overVolted) ; if (model == PI_MODEL_UNKNOWN) { printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ; printf (" [email protected]\n") ; printf ("with a copy of your /proc/cpuinfo if possible\n") ; } else { printf ("Banana Pro Details:\n") ; printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; } return 0 ; } if (strcasecmp (argv [1], "-warranty") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012-2014 Gordon Henderson\n") ; printf ("\n") ; printf (" This program is free software; you can redistribute it and/or modify\n") ; printf (" it under the terms of the GNU Leser General Public License as published\n") ; printf (" by the Free Software Foundation, either version 3 of the License, or\n") ; printf (" (at your option) any later version.\n") ; printf ("\n") ; printf (" This program is distributed in the hope that it will be useful,\n") ; printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ; printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ; printf (" GNU Lesser General Public License for more details.\n") ; printf ("\n") ; printf (" You should have received a copy of the GNU Lesser General Public License\n") ; printf (" along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ; printf ("\n") ; return 0 ; } if (geteuid () != 0) { fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ; return 1 ; } // Initial test for /sys/class/gpio operations: /**/ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; } // Check for load command: if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; } // Check for -g argument if (strcasecmp (argv [1], "-g") == 0) { wiringPiSetupGpio () ; for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_GPIO ; } // Check for -1 argument else if (strcasecmp (argv [1], "-1") == 0) { wiringPiSetupPhys () ; for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_PHYS ; } // Default to wiringPi mode else { wiringPiSetup () ; wpMode = WPI_MODE_PINS ; } // Check for -x argument to load in a new extension if (strcasecmp (argv [1], "-x") == 0) { if (argc < 3) { fprintf (stderr, "%s: -x missing extension specification.\n", argv [0]) ; exit (EXIT_FAILURE) ; } if (!doExtension (argv [0], argv [2])) // Prints its own error messages exit (EXIT_FAILURE) ; for (i = 3 ; i < argc ; ++i) argv [i - 2] = argv [i] ; argc -= 2 ; } if (argc <= 1) { fprintf (stderr, "%s: no command given\n", argv [0]) ; exit (EXIT_FAILURE) ; } // Core wiringPi functions /**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ; else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ; else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ; else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ; else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite (argc, argv) ; else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ; // GPIO Nicies else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ; // Pi Specifics else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ; else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ; else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ; else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ; else if (strcasecmp (argv [1], "pwmTone" ) == 0) doPwmTone (argc, argv) ; else if (strcasecmp (argv [1], "usbp" ) == 0) doUsbP (argc, argv) ; else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ; else if (strcasecmp (argv [1], "nreadall" ) == 0) doReadall () ; else if (strcasecmp (argv [1], "pins" ) == 0) doPins () ; else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ; else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ; else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ; else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ; else { fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ; exit (EXIT_FAILURE) ; } return 0 ; }
//////////////////////////////////////////////////////////////////////// // Main entry point // // int __cdecl main(int argc, char *argv[]) { int nArgIndex; // Walk through command line arguments int nArgIncrement = 0; int val; //=== Parameterized IOCTL Example === // int nVal; // ULONG dwVal; DWORD Error; printf("Test application Test_ds7 starting...\n"); hDevice = OpenByInterface( &ClassGuid, 0, &Error); if (hDevice == INVALID_HANDLE_VALUE) { printf("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError()); Exit(1); } else { printf("Device found, handle open.\n"); } // Parse the command line if (argc < 2) Usage(); nArgIndex = 1; while (nArgIndex < argc) { // Parse ahead to determine numeric value of argument if (nArgIndex+1 >= argc) Usage(); if (!isdigit(argv[nArgIndex+1][0])) Usage(); val = atoi(argv[nArgIndex+1]); switch (argv[nArgIndex][0]) { case 'r': case 'R': doRead(val); nArgIncrement = 2; break; case 'w': case 'W': doWrite(val); nArgIncrement = 2; break; case 'i': case 'I': if (val >= N_IOCODES) { printf("IO control code index must be less than %d\n", N_IOCODES); ShowIoctlValues(); Exit(1); } switch (IOcodes[val]) { //=== Parameterized IOCTL Example === // case IOCTL_PARAMETERIZED: // if (nArgIndex+3 >= argc) Usage(); // nVal = atoi(argv[nArgIndex+2]); // dwVal = strtoul(argv[nArgIndex+3], NULL, 0); // Test_IOCTL_PARAMETERIZED(nVal, dwVal); // nArgIncrement = 4; // break; case DS7_IOCTL_800: Test_DS7_IOCTL_800(); nArgIncrement = 2; break; default: printf("IO control code not valid\n"); Exit(1); } break; case '?': case 'h': default: Usage(); } nArgIndex += nArgIncrement; } return 0; }
/*! @detail * Read/write as many size unless timeout happens * @param buf/size - buffer and size to read/write * @return the byte read or write, <0 means error occured */ int Read(char *buf, int size) { return doRead(buf, size); }
size32_t CThorContiguousRowBuffer::readPackedInt(void * ptr) { size32_t size = sizePackedInt(); doRead(size, ptr); return size; }
size32_t CThorContiguousRowBuffer::read(size32_t len, void * ptr) { doRead(len, ptr); return len; }
int main (int argc, char *argv []) { int i ; if (argc == 1) { fprintf (stderr, "%s\n", usage) ; return 1 ; } if (strcasecmp (argv [1], "-h") == 0) { printf ("%s: %s\n", argv [0], usage) ; return 0 ; } if (strcasecmp (argv [1], "-v") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012 Gordon Henderson\n") ; printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ; printf ("For details type: %s -warranty\n", argv [0]) ; printf ("\n") ; printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ; return 0 ; } if (strcasecmp (argv [1], "-warranty") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012 Gordon Henderson\n") ; printf ("\n") ; printf (" This program is free software; you can redistribute it and/or modify\n") ; printf (" it under the terms of the GNU Leser General Public License as published\n") ; printf (" by the Free Software Foundation, either version 3 of the License, or\n") ; printf (" (at your option) any later version.\n") ; printf ("\n") ; printf (" This program is distributed in the hope that it will be useful,\n") ; printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ; printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ; printf (" GNU Lesser General Public License for more details.\n") ; printf ("\n") ; printf (" You should have received a copy of the GNU Lesser General Public License\n") ; printf (" along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ; printf ("\n") ; return 0 ; } if (geteuid () != 0) { fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ; return 1 ; } // Initial test for /sys/class/gpio operations: /**/ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; } // Check for load command: if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; } // Gertboard commands if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; } if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; } // Check for -g argument if (strcasecmp (argv [1], "-g") == 0) { if (wiringPiSetupGpio () == -1) { fprintf (stderr, "%s: Unable to initialise GPIO mode.\n", argv [0]) ; exit (1) ; } for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_GPIO ; } // Check for -p argument for PiFace else if (strcasecmp (argv [1], "-p") == 0) { if (wiringPiSetupPiFaceForGpioProg () == -1) { fprintf (stderr, "%s: Unable to initialise PiFace.\n", argv [0]) ; exit (1) ; } for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_PIFACE ; } // Default to wiringPi mode else { if (wiringPiSetup () == -1) { fprintf (stderr, "%s: Unable to initialise wiringPi mode\n", argv [0]) ; exit (1) ; } wpMode = WPI_MODE_PINS ; } // Check for PWM or Pad Drive operations if (wpMode != WPI_MODE_PIFACE) { if (strcasecmp (argv [1], "pwm-bal") == 0) { doPwmMode (PWM_MODE_BAL) ; return 0 ; } if (strcasecmp (argv [1], "pwm-ms") == 0) { doPwmMode (PWM_MODE_MS) ; return 0 ; } if (strcasecmp (argv [1], "pwmr") == 0) { doPwmRange (argc, argv) ; return 0 ; } if (strcasecmp (argv [1], "pwmc") == 0) { doPwmClock (argc, argv) ; return 0 ; } if (strcasecmp (argv [1], "drive") == 0) { doPadDrive (argc, argv) ; return 0 ; } } // Check for wiring commands /**/ if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ; else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ; else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ; else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ; else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ; else { fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ; exit (1) ; } return 0 ; }
int main (int argc, char *argv []) { int i ; if (getenv ("WIRINGPI_DEBUG") != NULL) { printf ("gpio: wiringPi debug mode enabled\n") ; wiringPiDebug = TRUE ; } if (argc == 1) { fprintf (stderr, "%s\n", usage) ; return 1 ; } // Help if (strcasecmp (argv [1], "-h") == 0) { printf ("%s: %s\n", argv [0], usage) ; return 0 ; } // Sort of a special: if (strcmp (argv [1], "-R") == 0) { printf ("%d\n", piBoardRev ()) ; return 0 ; } // Version & Warranty if (strcmp (argv [1], "-V") == 0) { printf ("%d\n", piBoardRev ()) ; return 0 ; } if (strcmp (argv [1], "-v") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ; printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ; printf ("For details type: %s -warranty\n", argv [0]) ; printf ("\n") ; printf ("This Raspberry Pi is a revision %d board.\n", piBoardRev ()) ; return 0 ; } if (strcasecmp (argv [1], "-warranty") == 0) { printf ("gpio version: %s\n", VERSION) ; printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ; printf ("\n") ; printf (" This program is free software; you can redistribute it and/or modify\n") ; printf (" it under the terms of the GNU Leser General Public License as published\n") ; printf (" by the Free Software Foundation, either version 3 of the License, or\n") ; printf (" (at your option) any later version.\n") ; printf ("\n") ; printf (" This program is distributed in the hope that it will be useful,\n") ; printf (" but WITHOUT ANY WARRANTY; without even the implied warranty of\n") ; printf (" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") ; printf (" GNU Lesser General Public License for more details.\n") ; printf ("\n") ; printf (" You should have received a copy of the GNU Lesser General Public License\n") ; printf (" along with this program. If not, see <http://www.gnu.org/licenses/>.\n") ; printf ("\n") ; return 0 ; } if (geteuid () != 0) { fprintf (stderr, "%s: Must be root to run. Program should be suid root. This is an error.\n", argv [0]) ; return 1 ; } // Initial test for /sys/class/gpio operations: /**/ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; } else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; } // Check for load command: if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; } // Gertboard commands if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; } if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; } // Check for -g argument /**/ if (strcasecmp (argv [1], "-g") == 0) { wiringPiSetupGpio () ; for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_GPIO ; } // Check for -1 argument else if (strcasecmp (argv [1], "-1") == 0) { wiringPiSetupPhys () ; for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_PHYS ; } // Check for -p argument for PiFace else if (strcasecmp (argv [1], "-p") == 0) { piFaceSetup (200) ; for (i = 2 ; i < argc ; ++i) argv [i - 1] = argv [i] ; --argc ; wpMode = WPI_MODE_PIFACE ; } // Default to wiringPi mode else { wiringPiSetup () ; wpMode = WPI_MODE_PINS ; } // Check for -x argument to load in a new extension if (strcasecmp (argv [1], "-x") == 0) { if (argc < 3) { fprintf (stderr, "%s: -x missing extension specification.\n", argv [0]) ; exit (EXIT_FAILURE) ; } if (!doExtension (argv [0], argv [2])) // Prints its own error messages exit (EXIT_FAILURE) ; for (i = 3 ; i < argc ; ++i) argv [i - 2] = argv [i] ; argc -= 2 ; } if (argc <= 1) { fprintf (stderr, "%s: no command given\n", argv [0]) ; exit (EXIT_FAILURE) ; } // Core wiringPi functions /**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ; else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ; else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ; else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ; else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite (argc, argv) ; else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ; // GPIO Nicies else if (strcasecmp (argv [1], "toggle" ) == 0) doToggle (argc, argv) ; // Pi Specifics else if (strcasecmp (argv [1], "pwm-bal" ) == 0) doPwmMode (PWM_MODE_BAL) ; else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ; else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ; else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ; else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ; else if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ; else if (strcasecmp (argv [1], "i2cdetect") == 0) doI2Cdetect (argc, argv) ; else if (strcasecmp (argv [1], "i2cd" ) == 0) doI2Cdetect (argc, argv) ; else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ; else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ; else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ; else if (strcasecmp (argv [1], "wfi" ) == 0) doWfi (argc, argv) ; else { fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ; exit (EXIT_FAILURE) ; } return 0 ; }
void MFStream::handleReadyRead() { doRead(); }
int main(int argc,char **argv) { int c; int streams=1; int stats=0; int error=0; int help=0; struct timeval time,timeStart; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"streams",1,0,0}, {"statistics",0,0,0}, {"help",0,0,0}, {0,0,0,0} }; c = getopt_long(argc, argv, "",long_options,&option_index); if (c == -1) break; switch (c) { case 0: switch (option_index) { case 0: streams=atoi(optarg); if (streams < 1 || streams > 32) { printf("Invalid number of streams specified."); error=1; } break; case 1: stats=1; break; case 2: help=1; } break; default: printf("Invalid option specified."); error=1; } } if (error==0) { if (argc-optind != 2) { printf("Invalid number of arguments provided."); error=1; } else { char *srcfile=argv[optind]; char *destfile=argv[optind+1]; off_t inSize; void *buff; off_t offset = 0; struct mdsfile inFile,outFile; int status; if (stats) { gettimeofday(&time,0); timeStart=time; } status=doOpen(streams,srcfile,O_RDONLY,0,&inFile); if (status == -1) { printf("Error opening source file: %s\n",srcfile); return 1; } if (stats) printf("Time to open source file: %g\n",getSeconds(&time)); status=doOpen(streams,destfile,O_WRONLY | O_CREAT, 0777,&outFile); if (status == -1) { printf("Error opening destination file: %s\n",destfile); return 1; } if (stats) printf("Time to open destination file: %g\n",getSeconds(&time)); inSize=getSize(&inFile); if (inSize > 2000) { if (streams > 1) { if (inFile.socket != -1) MdsSetStreams(inFile.socket,streams); if (outFile.socket != -1) MdsSetStreams(outFile.socket,streams); if (stats) printf("Time to initialize parallel streams: %g\n",getSeconds(&time)); } } buff=malloc(inSize>MAX_IO_SIZE?MAX_IO_SIZE:inSize); while(offset < inSize) { off_t bytes_this_time = inSize-offset; off_t bytes; if (bytes_this_time > MAX_IO_SIZE) bytes_this_time = MAX_IO_SIZE; bytes=doRead(&inFile,bytes_this_time,buff); if (bytes != bytes_this_time) { fprintf(stderr,"Error reading from source file"); return 1; } bytes=doWrite(&outFile,bytes_this_time,buff); if (bytes != bytes_this_time) { fprintf(stderr,"Error writing to destination file"); return 1; } offset+=bytes_this_time; } doClose(&inFile); doClose(&outFile); if (stats) { float secs; printf("Time to copy files: %g\n",secs=getSeconds(&time)); printf("Total time to copy files: %g\n",getSeconds(&timeStart)); printf("Copy rate is %g MBytes/sec\n",inSize/1e6/secs); } } } if (error) { printf("\n\n"); printHelp(); return 1; } else if (help) { printHelp(); } return 0; }
int Connection::read(Message* message) { return doRead(message, [&] (int sfd, char* buffer, size_t toRead) { return ::read(sfd, buffer, toRead); }); }
void BoostConnection::listen() { doRead(); }
int main() { int listenfd; struct sockaddr_in serAddr; fd_set rdSet, allset; int fdArray[FD_SETSIZE] = {0}; int maxfd; int flag; FD_ZERO(&rdSet); serAddr.sin_family = AF_INET; serAddr.sin_addr.s_addr = htonl(INADDR_ANY); serAddr.sin_port = htons(12345); for(int i =0; i< FD_SETSIZE; i++) fdArray[i] = -1; listenfd = socket(AF_INET, SOCK_STREAM, 0); if(listenfd < 0) { perror("create socket failed.\n"); exit(-1); } if(flag = fcntl(listenfd,F_GETFL,0) < 0) { perror("FCNTL ERROR"); return -1; } flag |= O_NONBLOCK; if(fcntl(listenfd, F_SETFL, flag) < 0 ) { perror("fcntl set error"); return -1; } printf("max fd size = %d\n",FD_SETSIZE); /*一个端口释放后会等待两分钟之后才能再被使用,SO_REUSEADDR是让端口释放后立即就可以被再次使用。*/ int reuse = 1; if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) == -1) exit(-1); if(bind(listenfd, (struct sockaddr*)&serAddr, sizeof(serAddr)) < 0) { perror("bind error"); exit(-1); } if(listen(listenfd, 64) < 0) { perror("listen failed.\n"); exit(-1); } FD_SET(listenfd, &rdSet); fdArray[0] = listenfd; maxfd = listenfd; while(1) { allset = rdSet; //select每次检查前都必须重置描述符集 int n = select(maxfd+1, &allset, NULL, NULL, NULL); if(n < 0) { perror("select failed.\n"); exit(-1); } if(FD_ISSET(listenfd, &allset)) { int connfd = doaccept(listenfd); if(connfd < 0) exit(-1); if(flag = fcntl(connfd,F_GETFL,0) < 0) { perror("FCNTL ERROR"); return -1; } flag |= O_NONBLOCK; //如果不将客户端套接字设置为非阻塞服务器将阻塞在某一个客户端套接字 //的recv调用上,其他客户端的请求得不到响应 if(fcntl(connfd, F_SETFL, flag) < 0 ) { perror("fcntl set error"); return -1; } FD_SET(connfd, &rdSet); for(int i=0; i< FD_SETSIZE; i++) { if(fdArray[i] == -1) { fdArray[i] = connfd; break; } } //重置当前最大描述符字 maxfd = (maxfd > connfd ? maxfd:connfd); } for(int i = 1; i< maxfd; i++) { if(FD_ISSET(fdArray[i], &allset)) doRead(fdArray[i]); } } return 0; }
void TimedTextPlayer::doSeekAndRead(int64_t seekTimeUs) { MediaSource::ReadOptions options; options.setSeekTo(seekTimeUs, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC); doRead(&options); }
size32_t CThorContiguousRowBuffer::readSize() { size32_t value; doRead(sizeof(value), &value); return value; }
void TimedTextPlayer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatPause: { mPaused = true; break; } case kWhatResume: { mPaused = false; if (mPendingSeekTimeUs != kInvalidTimeUs) { seekToAsync(mPendingSeekTimeUs); mPendingSeekTimeUs = kInvalidTimeUs; } else { doRead(); } break; } case kWhatStart: { sp<MediaPlayerBase> listener = mListener.promote(); if (listener == NULL) { ALOGE("Listener is NULL when kWhatStart is received."); break; } mPaused = false; mPendingSeekTimeUs = kInvalidTimeUs; int32_t positionMs = 0; listener->getCurrentPosition(&positionMs); int64_t seekTimeUs = positionMs * 1000ll; notifyListener(); mSendSubtitleGeneration++; doSeekAndRead(seekTimeUs); break; } case kWhatRetryRead: { int32_t generation = -1; CHECK(msg->findInt32("generation", &generation)); if (generation != mSendSubtitleGeneration) { // Drop obsolete msg. break; } int64_t seekTimeUs; int seekMode; if (msg->findInt64("seekTimeUs", &seekTimeUs) && msg->findInt32("seekMode", &seekMode)) { MediaSource::ReadOptions options; options.setSeekTo( seekTimeUs, static_cast<MediaSource::ReadOptions::SeekMode>(seekMode)); doRead(&options); } else { doRead(); } break; } case kWhatSeek: { int64_t seekTimeUs = kInvalidTimeUs; // Clear a displayed timed text before seeking. notifyListener(); msg->findInt64("seekTimeUs", &seekTimeUs); if (seekTimeUs == kInvalidTimeUs) { sp<MediaPlayerBase> listener = mListener.promote(); if (listener != NULL) { int32_t positionMs = 0; listener->getCurrentPosition(&positionMs); seekTimeUs = positionMs * 1000ll; } } if (mPaused) { mPendingSeekTimeUs = seekTimeUs; break; } mSendSubtitleGeneration++; doSeekAndRead(seekTimeUs); break; } case kWhatSendSubtitle: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mSendSubtitleGeneration) { // Drop obsolete msg. break; } // If current time doesn't reach to the fire time, // re-post the message with the adjusted delay time. int64_t fireTimeUs = kInvalidTimeUs; if (msg->findInt64("fireTimeUs", &fireTimeUs)) { // TODO: check if fireTimeUs is not kInvalidTimeUs. int64_t delayUs = delayUsFromCurrentTime(fireTimeUs); if (delayUs > 0) { msg->post(delayUs); break; } } sp<RefBase> obj; if (msg->findObject("subtitle", &obj)) { sp<ParcelEvent> parcelEvent; parcelEvent = static_cast<ParcelEvent*>(obj.get()); notifyListener(&(parcelEvent->parcel)); doRead(); } else { notifyListener(); } break; } case kWhatSetSource: { mSendSubtitleGeneration++; sp<RefBase> obj; msg->findObject("source", &obj); if (mSource != NULL) { mSource->stop(); mSource.clear(); mSource = NULL; } // null source means deselect track. if (obj == NULL) { mPendingSeekTimeUs = kInvalidTimeUs; mPaused = false; notifyListener(); break; } mSource = static_cast<TimedTextSource*>(obj.get()); status_t err = mSource->start(); if (err != OK) { notifyError(err); break; } Parcel parcel; err = mSource->extractGlobalDescriptions(&parcel); if (err != OK) { notifyError(err); break; } notifyListener(&parcel); break; } } }
int main() { for (int i = 0; i < READER_COUNT; ++i) { createThread([&](){ g_mainWaiter.release(); g_threadsWaiter.wait(); double start = getTime(); for (int j = 0; j < READER_LOOP; ++j) { { #if USE_LOCK == LOCK_TYPE_RW ReaderGuard<ReaderWriterLock> guard(g_resRW); #elif USE_LOCK == LOCK_TYPE_RW2 ReaderGuard<ReaderWriterLock2> guard(g_resRW2); #elif USE_LOCK == LOCK_TYPE_POSIX_RW ReaderGuard<PosixReaderWriterLock> guard(g_posixResRW); #elif USE_LOCK == LOCK_TYPE_MUTEX MutexGuard<Mutex> guard(g_resMutex); #elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX MutexGuard<PosixMutex> guard(g_posixResMutex); #else #endif doRead(); } } double readerTime = getTime() - start; MutexGuard<Mutex> guard(g_gMutex); g_readerTime += readerTime; g_mainWaiter.release(); }); } for (int i = 0; i < WRITER_COUNT; ++i) { createThread([&](){ g_mainWaiter.release(); g_threadsWaiter.wait(); double start = getTime(); for (int j = 0; j < WRITER_LOOP; ++j) { sleep_us(10); { #if USE_LOCK == LOCK_TYPE_RW WriterGuard<ReaderWriterLock> guard(g_resRW); #elif USE_LOCK == LOCK_TYPE_RW2 WriterGuard<ReaderWriterLock2> guard(g_resRW2); #elif USE_LOCK == LOCK_TYPE_POSIX_RW WriterGuard<PosixReaderWriterLock> guard(g_posixResRW); #elif USE_LOCK == LOCK_TYPE_MUTEX MutexGuard<Mutex> guard(g_resMutex); #elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX MutexGuard<PosixMutex> guard(g_posixResMutex); #else #endif doWrite(); } } double writerTime = getTime() - start; MutexGuard<Mutex> guard(g_gMutex); g_writerTime += writerTime; g_mainWaiter.release(); }); } for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire(); g_threadsWaiter.signal(); for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire(); fprintf(stderr, "res=%d,res2=%d=\n", g_res, g_res2); printf("lockType=%s, R/W=%d, reader=%.3fs, writer=%.3fs\n", TYPE_NAME, READER_COUNT / WRITER_COUNT, g_readerTime / READER_COUNT, g_writerTime / WRITER_COUNT); }
size32_t CThorStreamDeserializerSource::read(size32_t len, void * ptr) { doRead(len, ptr); return len; }
void DiskIODriver::read(Buffer *const buffer) { doRead(); super::read(buffer); }
size32_t CThorStreamDeserializerSource::readSize() { size32_t value; doRead(sizeof(value), &value); return value; }
void WebSocketWorker::SetupSocket() { if (m_connectionType == kSSLServer) { #ifndef QT_NO_OPENSSL QSslSocket *pSslSocket = new QSslSocket(); if (pSslSocket->setSocketDescriptor(m_socketFD) && gCoreContext->CheckSubnet(pSslSocket)) { pSslSocket->setSslConfiguration(m_sslConfig); pSslSocket->startServerEncryption(); if (pSslSocket->waitForEncrypted(5000)) { LOG(VB_HTTP, LOG_INFO, "SSL Handshake occurred, connection encrypted"); LOG(VB_HTTP, LOG_INFO, QString("Using %1 cipher").arg(pSslSocket->sessionCipher().name())); } else { LOG(VB_HTTP, LOG_WARNING, "SSL Handshake FAILED, connection terminated"); delete pSslSocket; pSslSocket = nullptr; } } else { delete pSslSocket; pSslSocket = nullptr; } if (pSslSocket) m_socket = dynamic_cast<QTcpSocket *>(pSslSocket); else return; #else return; #endif } else // Plain old unencrypted socket { m_socket = new QTcpSocket(); m_socket->setSocketDescriptor(m_socketFD); if (!gCoreContext->CheckSubnet(m_socket)) { delete m_socket; m_socket = nullptr; return; } } m_socket->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1)); connect(m_socket, SIGNAL(readyRead()), SLOT(doRead())); connect(m_socket, SIGNAL(disconnected()), SLOT(CloseConnection())); // Setup heartbeat m_heartBeat->setInterval(20000); // 20 second m_heartBeat->setSingleShot(false); connect(m_heartBeat, SIGNAL(timeout()), SLOT(SendHeartBeat())); }
offset_t CThorStreamDeserializerSource::beginNested() { size32_t len; doRead(sizeof(len), &len); return len+in->tell(); }
char doRegular(char expand, char c) { char toReturn; int i; int done = 0; label doorinfo; toReturn = FALSE; for (i = 0; !expand && i < MAXEXTERN && extCmd[i].name[0]; ++i) { if (c == toupper(extCmd[i].name[0]) && (onConsole || !extCmd[i].local)) { done = 1; mPrintf("\b%s", extCmd[i].name); doCR(); if (changedir(cfg.aplpath) == ERROR) { mPrintf(" -- Can't find application directory.\n\n"); changedir(cfg.homepath); } /* apsystem(extCmd[i].command); */ sprintf(doorinfo, "DORINFO%d.DEF", onConsole ? 0 : userdat.apl_com); extFmtRun(extCmd[i].command, doorinfo); } } if (!done) { switch (c) { case 'S': if (gl_user.sysop && expand) { mPrintf("\b\bSysop Menu"); doCR(); doSysop(); } else { toReturn = TRUE; } break; case 'A': if (gl_user.aide) { doAide(expand, 'E'); } else { toReturn = TRUE; } break; case 'C': doChat(expand, '\0'); break; case 'D': doDownload(expand); break; case 'E': doEnter(expand, 'm'); break; case 'F': doRead(expand, 'f'); break; case 'G': doGoto(expand, FALSE); break; case 'H': doHelp(expand); break; case 'I': doIntro(); break; case 'J': mPrintf("\bJump back to "); unGotoRoom(); break; case 'K': doKnown(expand, 'r'); break; case 'L': if (!loggedIn) { doLogin(expand); } else { if (!getYesNo(confirm, 0)) break; doLogout(expand, 's'); doLogin(expand); } break; case 'N': case 'O': case 'R': doRead(expand, tolower(c)); break; case 'B': doGoto(expand, TRUE); break; case 'T': doLogout(expand, 'q'); break; case 'U': doUpload(expand); break; case 'X': if (!expand) { doEnter(expand, 'x'); } else { doXpert(); } break; case '=': case '+': doNext(); break; case '\b': mPrintf(" "); case '-': doPrevious(); break; case ']': case '>': doNextHall(); break; case '[': case '<': doPreviousHall(); break; case '~': mPrintf("\bAnsi %s\n ", gl_term.ansiOn ? gl_str.off : gl_str.on); gl_term.ansiOn = !gl_term.ansiOn; break; case '!': mPrintf("\bIBM Graphics %s\n ", gl_term.IBMOn ? gl_str.off:gl_str.on); gl_term.IBMOn = !gl_term.IBMOn; break; case '?': nextmenu("mainopt", &(cfg.cnt.mainopttut), 1); listExterns(); break; case 0: /* never gets here in shell mode... */ if (newCarrier) { greeting(); if (cfg.forcelogin) { doCR(); doCR(); i = 0; while (!loggedIn && gotCarrier()) { doLogin(2); if (++i > 3) { Initport(); toReturn = TRUE; break; } } } newCarrier = FALSE; } if (logBuf.lbflags.NODE && loggedIn) { net_slave(); haveCarrier = FALSE; modStat = FALSE; newCarrier = FALSE; justLostCarrier = FALSE; onConsole = FALSE; disabled = FALSE; callout = FALSE; delay(2000); Initport(); cfg.callno++; terminate(FALSE, FALSE); } if (justLostCarrier || ExitToMsdos) { justLostCarrier = FALSE; if (loggedIn) terminate(FALSE, FALSE); } break; /* irrelevant value */ default: toReturn = TRUE; break; } } /* if they get unverified online */ if (logBuf.VERIFIED) terminate(FALSE, FALSE); /* update25(); */ do_idle(0); return toReturn; }
data_chunk BIO::Read() const { return doRead(); }