bool SocketIOClient::readHandshake() { if (!waitForInput()) return false; // check for happy "HTTP/1.1 200" response readLine(); if (atoi(&databuffer[9]) != 200) { while (client.available()) readLine(); client.stop(); return false; } eatHeader(); readLine(); // read first line of response readLine(); // read sid : transport : timeout char *iptr = databuffer; char *optr = sid; while (*iptr && (*iptr != ':') && (optr < &sid[SID_LEN-2])) *optr++ = *iptr++; *optr = 0; Serial.print(F("Connected. SID=")); Serial.println(sid); // sid:transport:timeout while (client.available()) readLine(); client.stop(); delay(1000); // reconnect on websocket connection Serial.print(F("WS Connect...")); if (!client.connect(hostname, port)) { Serial.print(F("Reconnect failed.")); return false; } Serial.println(F("Reconnected.")); client.print(F("GET /socket.io/1/websocket/")); client.print(sid); client.println(F(" HTTP/1.1")); client.print(F("Host: ")); client.println(hostname); client.println(F("Origin: ArduinoSocketIOClient")); client.println(F("Upgrade: WebSocket")); // must be camelcase ?! client.println(F("Connection: Upgrade\r\n")); if (!waitForInput()) return false; readLine(); if (atoi(&databuffer[9]) != 101) { while (client.available()) readLine(); client.stop(); return false; } eatHeader(); monitor(); // treat the response as input return true; }
void M_Utils::dispBlobOCRRes(BLOBNBOX* blob, PIX* im, Tesseract* ocrengine) { BOX* box_ = getBlobBoxImCoords(blob, im); PIX* bboxim = pixClipRectangle(im, box_, NULL); pixDisplay(bboxim, 100, 100); BLOB_CHOICE* ocr_res = runBlobOCR(blob, ocrengine); const char* const unicode_res = getBlobChoiceUnicode(ocr_res, ocrengine); cout << "OCR result: " << unicode_res << endl; cout << "certainty: " << ocr_res->certainty() << endl; waitForInput(); }
Common::Error AGOSEngine::go() { #ifdef ENABLE_AGOS2 loadArchives(); #endif loadGamePcFile(); addTimeEvent(0, 1); if (getFileName(GAME_GMEFILE) != NULL) { openGameFile(); } if (getGameType() == GType_FF) { loadIconData(); } else if (getFileName(GAME_ICONFILE) != NULL) { loadIconFile(); } if (getFileName(GAME_MENUFILE) != NULL) { loadMenuFile(); } vc34_setMouseOff(); if (getGameType() != GType_PP && getGameType() != GType_FF) { uint16 count = (getGameType() == GType_SIMON2) ? 5 : _frameCount; addVgaEvent(count, ANIMATE_INT, NULL, 0, 0); } if (getGameType() == GType_ELVIRA1 && getPlatform() == Common::kPlatformAtariST && (getFeatures() & GF_DEMO)) { setWindowImage(3, 9900); while (!shouldQuit()) delay(0); } if (getGameType() == GType_ELVIRA1 && getPlatform() == Common::kPlatformAmiga && (getFeatures() & GF_DEMO)) { playMusic(0, 0); } runSubroutine101(); permitInput(); while (!shouldQuit()) { waitForInput(); handleVerbClicked(_verbHitArea); delay(100); } return Common::kNoError; }
int testLogin(sgs_connection *connection) { sgs_connection_login(connection, "kickme", "password1"); waitForInput(connection); if (loginFailFail == 1){ printf("Log in failure test failed\n"); } else { printf("Log in failure test passed\n"); } sgs_connection_login(connection, "discme", "password2"); waitForInput(connection); if (loginDisconnectFail == 1){ printf("Log in disconnect test failed\n"); } else { printf("Log in disconnect test passed\n"); } if (loginFailFail || loginDisconnectFail){ return 1; } else { return 0; } }
int read (char* destBuffer, int maxBytesToRead, int timeOutMilliseconds) { int bytesRead = -1; blocked = true; const uint32 timeoutEnd = getTimeoutEnd (timeOutMilliseconds); if (pipeIn == -1) { pipeIn = openPipe (createdPipe ? pipeInName : pipeOutName, O_RDWR | O_NONBLOCK, timeoutEnd); if (pipeIn == -1) { blocked = false; return -1; } } bytesRead = 0; while (bytesRead < maxBytesToRead) { const int bytesThisTime = maxBytesToRead - bytesRead; const int numRead = (int) ::read (pipeIn, destBuffer, bytesThisTime); if (numRead <= 0) { if (errno != EWOULDBLOCK || stopReadOperation || hasExpired (timeoutEnd)) { bytesRead = -1; break; } const int maxWaitingTime = 30; waitForInput (pipeIn, timeoutEnd == 0 ? maxWaitingTime : jmin (maxWaitingTime, (int) (timeoutEnd - Time::getMillisecondCounter()))); continue; } bytesRead += numRead; destBuffer += numRead; } blocked = false; return bytesRead; }
static void mainLoop() { addCallbacks(retracer); long long startTime = 0; frameNo = 0; startTime = os::getTime(); if (singleThread) { trace::Call *call; while ((call = parser->parse_call())) { retraceCall(call); delete call; } } else { RelayRace race; race.run(); } finishRendering(); long long endTime = os::getTime(); float timeInterval = (endTime - startTime) * (1.0 / os::timeFrequency); if ((retrace::verbosity >= -1) || (retrace::profiling)) { std::cout << "Rendered " << frameNo << " frames" " in " << timeInterval << " secs," " average of " << (frameNo/timeInterval) << " fps\n"; } if (waitOnFinish) { waitForInput(); } else { return; } }
unsigned int CNetworkClient::read() { unsigned int bytesAvail = waitForInput(); if (bytesAvail > 0) { bool endOfLine = false; bool endOfStream = false; if ( MaxBufferSize <= bytesAvail ) { //throw error return 0; // this is error so handle it as such at some point } while ( m_pullBuffer.m_usedSize < bytesAvail && (!endOfLine) && (!endOfStream) ) { m_pullBuffer.m_usedSize += m_socket->read( m_pullBuffer.m_buffer + m_pullBuffer.m_usedSize, MaxBufferSize - m_pullBuffer.m_usedSize ); } } return m_pullBuffer.m_usedSize; }
static void mainLoop() { addCallbacks(retracer); long long startTime = 0; frameNo = 0; startTime = os::getTime(); if (singleThread) { trace::Call *call; while ((call = parser.parse_call())) { retraceCall(call); delete call; }; } else { RelayRace race; race.run(); } finishRendering(); long long endTime = os::getTime(); float timeInterval = (endTime - startTime) * (1.0 / os::timeFrequency); if ((retrace::verbosity >= -1) || (retrace::profiling)) { std::cout << "Rendered " << frameNo << " frames" " in " << timeInterval << " secs," " average of " << (frameNo/timeInterval) << " fps\n"; std::cout << std::endl; std::cout << "Total number of calls: " << nCalls.tot() << std::endl; std::cout << "Average number of calls: " << nCalls.avg() << std::endl; std::cout << "Minimum number of calls: " << nCalls.min() << std::endl; std::cout << "Maximum number of calls: " << nCalls.max() << std::endl; std::cout << std::endl; std::cout << "Total number of render calls: " << nRenderCalls.tot() << std::endl; std::cout << "Average number of render calls: " << nRenderCalls.avg() << std::endl; std::cout << "Minimum number of render calls: " << nRenderCalls.min() << std::endl; std::cout << "Maximum number of render calls: " << nRenderCalls.max() << std::endl; std::cout << std::endl; std::cout << "Total texel uploads: " << texUploads.tot() << std::endl; std::cout << "Average texel uploads: " << texUploads.avg() << std::endl; std::cout << "Minimum texel uploads: " << texUploads.min() << std::endl; std::cout << "Maximum texel uploads: " << texUploads.max() << std::endl; std::cout << std::endl; std::cout << "Total number of triangles: " << nTriangles.tot() << std::endl; std::cout << "Average number of triangles: " << nTriangles.avg() << std::endl; std::cout << "Minimum number of triangles: " << nTriangles.min() << std::endl; std::cout << "Maximum number of triangles: " << nTriangles.max() << std::endl; std::cout << std::endl; std::cout << "Total number of vertices: " << nVertices.tot() << std::endl; std::cout << "Average number of vertices: " << nVertices.avg() << std::endl; std::cout << "Minimum number of vertices: " << nVertices.min() << std::endl; std::cout << "Maximum number of vertices: " << nVertices.max() << std::endl; } if (waitOnFinish) { waitForInput(); } else { return; } }
//----------------------------------------------------------------------------- unsigned int LIVE_LOOP_CALL liveLoop( void* pData ) //----------------------------------------------------------------------------- { HDRV hDrv; TDMR_ERROR result; ImageBuffer* pIB; RequestResult ReqRes; int frameCount; double fps; int requestNr; int lastRequestNr; CaptureParameter* pCaptureParameter; pCaptureParameter = ( ( CaptureParameter* )pData ); hDrv = pCaptureParameter->hDrv; pIB = 0; frameCount = 0; fps = 0.0; requestNr = -1; // we always have to keep at least 2 images as the display module might want to repaint the image, thus we // can free it unless we have a assigned the display to a new buffer. lastRequestNr = -1; // pre-fill the default capture queue while( ( result = DMR_ImageRequestSingle( hDrv, 0, 0 ) ) == DMR_NO_ERROR ); if( result != DEV_NO_FREE_REQUEST_AVAILABLE ) { printf( "DMR_ImageRequestSingle: Unexpected error(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) ); } manuallyStartAcquisitionIfNeeded( hDrv ); // run thread loop while( !g_boTerminated ) { // please note that the value stored in the property 'ImageRequestTimeout_ms' specifies the // maximum time a request will remain in the queue. If no complete image has been taken until // then, RequestResult.result will contain 'rrTimeout', so to allow long wait times, this // property needs to be modified as well, as its default is 2000 ms. // In this sample this can be achieved by calling 'getSettingProp( hDrv, "Base", "ImageRequestTimeout_ms" )' result = DMR_ImageRequestWaitFor( hDrv, 500, 0, &requestNr ); if( result == DMR_NO_ERROR ) { // check if the request contains a valid image result = DMR_GetImageRequestResultEx( hDrv, requestNr, &ReqRes, sizeof( ReqRes ), 0, 0 ); if( ( result == DMR_NO_ERROR ) && ( ReqRes.result == rrOK ) ) { // display statistical information every 100th image frameCount = frameCount + 1; if( ( frameCount % 100 ) == 0 ) { OBJ_GetF( pCaptureParameter->hFramesPerSecond, &fps, 0 ); printf( "frames per second: %.5f.\n", fps ); } if( ( result = DMR_GetImageRequestBuffer( hDrv, requestNr, &pIB ) ) == DMR_NO_ERROR ) { #ifdef USE_MV_DISPLAY_LIB // display the captured image mvDispSetImageFromImageBuffer( pCaptureParameter->pDisp, pIB ); mvDispUpdate( pCaptureParameter->pDisp ); #endif // #ifdef USE_MV_DISPLAY_LIB checkCaptureBufferAddress( pCaptureParameter->ppRequests[requestNr], pCaptureParameter->boUserSuppliedMemoryUsed, pCaptureParameter->pFirstHeapBuffer ); } else { printf( "DMR_GetImageRequestBuffer: ERROR! Code %d\n", result ); } } else { // this can happen e.g. when a triggered acquisition timed out (missing trigger signal) // A request does not remain in teh queue forever, but is removed after the max. queue time has elapsed. This timeout // is defined by the 'ImageRequestTimeout_ms' property. If this timeout has elapsed and no // image has been captured, the RequestResult.result parameter will not contain 'rrOK', but the // request still needs to be unlocked for the driver as it has been returned to the user. printf( "DMR_GetImageRequestResult: ERROR! Return value: %d, request result: %d.\n", result, ReqRes.result ); } if( lastRequestNr >= 0 ) { // this image has been displayed thus the buffer is no longer needed... DMR_ImageRequestUnlock( hDrv, lastRequestNr ); } lastRequestNr = requestNr; DMR_ImageRequestSingle( hDrv, 0, 0 ); } else { printf( "DMR_ImageRequestWaitFor: ERROR! Code %d\n", result ); } #ifdef linux g_boTerminated = waitForInput( 0, STDOUT_FILENO ) == 0 ? 0 : 1; // break by STDIN #endif // #ifndef _WIN32 } manuallyStopAcquisitionIfNeeded( hDrv ); #ifdef USE_MV_DISPLAY_LIB // remove the displays reference to memory that is about to be freed mvDispSetImage( pCaptureParameter->pDisp, 0, 0, 0, 0, 0 ); #endif // #ifdef USE_MV_DISPLAY_LIB // free the last potential locked request if( requestNr >= 0 ) { DMR_ImageRequestUnlock( hDrv, requestNr ); } // clear the request queue if( ( result = DMR_ImageRequestReset( hDrv, 0, 0 ) ) != DMR_NO_ERROR ) { printf( "Calling DMR_ImageRequestReset returned an error: %s.\n", DMR_ErrorCodeToString( result ) ); } // extract and unlock all requests that are now returned as 'aborted' while( DMR_ImageRequestWaitFor( hDrv, 0, 0, &requestNr ) == DMR_NO_ERROR ) { DMR_ImageRequestUnlock( hDrv, requestNr ); } if( ( result = DMR_ReleaseImageRequestBufferDesc( &pIB ) ) != DMR_NO_ERROR ) { printf( "Calling DMR_ReleaseImageRequestBufferDesc returned an error: %s.\n", DMR_ErrorCodeToString( result ) ); } return 0; }
void parent(int pid, int pty) { unsigned char buf[BUFFER_SIZE]; int i; int val; int rc; if(verbose) { reportIso2022(outputState); } #ifdef SIGWINCH installHandler(SIGWINCH, sigwinchHandler); #endif installHandler(SIGCHLD, sigchldHandler); rc = copyTermios(0, pty); if(rc < 0) FatalError("Couldn't copy terminal settings\n"); rc = setRawTermios(); if(rc < 0) FatalError("Couldn't set terminal to raw\n"); val = fcntl(0, F_GETFL, 0); if(val >= 0) { fcntl(0, F_SETFL, val | O_NONBLOCK); } val = fcntl(pty, F_GETFL, 0); if(val >= 0) { fcntl(pty, F_SETFL, val | O_NONBLOCK); } setWindowSize(0, pty); for(;;) { rc = waitForInput(0, pty); if(sigwinch_queued) { sigwinch_queued = 0; setWindowSize(0, pty); } if(sigchld_queued && exitOnChild) break; if(rc > 0) { if(rc & 2) { i = read(pty, buf, BUFFER_SIZE); if((i == 0) || ((i < 0) && (errno != EAGAIN))) break; if(i > 0) copyOut(outputState, 0, buf, i); } if(rc & 1) { i = read(0, buf, BUFFER_SIZE); if((i == 0) || ((i < 0) && (errno != EAGAIN))) break; if(i > 0) copyIn(inputState, pty, buf, i); } } } restoreTermios(); }
int main(int argc, char** argv) { sgs_context *context; sgs_connection *connection; sgs_connection *session; /* Begin by initializing the read sets for reading, * writing, and exceptions; these sets are all sets * of file descriptors */ FD_ZERO(&g_master_readset); FD_ZERO(&g_master_writeset); FD_ZERO(&g_master_exceptset); /* Now, initialize all of the flags that will be * used to keep track of which tests pass and which * tests fail */ loginFailFail = loginDisconnectFail = loginFail = 1; channelJoinFail = channelLeaveFail = channelMessageFail = 1; sessionMessageFail = 1; /* Get any command line argumentss, and * set the appropriate (global) variables. Currently, * the command line can only specify the host and port * of the server, and ask for the usage message * to be printed */ g_hostname = DEFAULT_HOST; g_port = DEFAULT_PORT; getCommandArgs(argc, argv); /* Create a context object, and load it up with the right set * of callbacks. The register_fd and unregister_fd callbacks * are loaded as part of the create call for historical purposes */ context = sgs_ctx_create(g_hostname, g_port, register_fd_cb, unregister_fd_cb); if (context == NULL) { printf("error in context create\n"); exit(1); } loadContext(context); /*Now, create a connection to the server; if this doesn't work things * are messed up enough to require simply printing an error message * and getting out */ connection = sgs_connection_create(context); if (connection == NULL){ printf ("error in creating a connection to the server\n"); exit(1); } if (testLogin(connection) != 0) { printf ("Failed at least one login test\n"); exit(1); } sgs_connection_login(connection, loginName, loginName); waitForInput(connection); return(printResults()); }