DaemonSocketPDU::~DaemonSocketPDU() { MOZ_COUNT_DTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer); nsAutoArrayPtr<uint8_t> data(GetBuffer()); ResetBuffer(nullptr, 0, 0, 0); }
void UniformPool::Init() { _sizeOfBuffer = 1024 * 1024 * 4;//4MB _pBuffer = new uint8_t[_sizeOfBuffer]; _currentOffset = 0; ResetBuffer(); }
void FluidSystem::Reset ( int nmax ) { ResetBuffer ( 0, nmax ); m_DT = 0.003; // 0.001; // .001 = for point grav // Reset parameters m_Param [ MAX_FRAC ] = 1.0; m_Param [ POINT_GRAV ] = 0.0; m_Param [ PLANE_GRAV ] = 1.0; m_Param [ BOUND_ZMIN_SLOPE ] = 0.0; m_Param [ FORCE_XMAX_SIN ] = 0.0; m_Param [ FORCE_XMIN_SIN ] = 0.0; m_Toggle [ WRAP_X ] = false; m_Toggle [ WALL_BARRIER ] = false; m_Toggle [ LEVY_BARRIER ] = false; m_Toggle [ DRAIN_BARRIER ] = false; m_Param [ SPH_INTSTIFF ] = 1.00; m_Param [ SPH_VISC ] = 0.2; m_Param [ SPH_INTSTIFF ] = 0.50; m_Param [ SPH_EXTSTIFF ] = 20000; m_Param [ SPH_SMOOTHRADIUS ] = 0.01; m_Vec [ POINT_GRAV_POS ].Set ( 0, 0, 50 ); m_Vec [ PLANE_GRAV_DIR ].Set ( 0, 0, -9.8 ); m_Vec [ EMIT_POS ].Set ( 0, 0, 0 ); m_Vec [ EMIT_RATE ].Set ( 0, 0, 0 ); m_Vec [ EMIT_ANG ].Set ( 0, 90, 1.0 ); m_Vec [ EMIT_DANG ].Set ( 0, 0, 0 ); }
int main(int argc, char *argv[]) { int done = 0; int i,sx,sy; Uint8 *keys; Init_All(); gamesounds[0] = LoadSound("sounds/victory.wav",MIX_MAX_VOLUME/2); gamesounds[1] = LoadSound("sounds/failure.wav",MIX_MAX_VOLUME/2); GameOptions(&DeadGame,0); GiveInfo(); do { ResetBuffer(); SDL_PumpEvents(); Update_ALL(); Think_ALL(); keys = SDL_GetKeyState(NULL); if(keys[SDLK_ESCAPE] == 1)done = 1; if(keys[SDLK_F1] == 1)GameOptions(&DeadGame,1); Draw_ALL(); if(keys[SDLK_b] == 1)SDL_SaveBMP(screen,"screen0.bmp"); // ItsRaining(IndexColor(LightRed),10,200,-0.2); NextFrame(); }while(!done); exit(0); return 0; }
/** * @param nLength - new stream length. * @return new file length. */ int CFileStream::SetLength(int nLength) { CHECK_FILE_HANDLE(-1); int nDeltaPos; if (m_eBufferType == BT_READ) { nDeltaPos = m_nBufferLength - m_nBufferPos; ResetBuffer(); } else { nDeltaPos = 0; if (! FlushBuffer()) return -1; } m_bEndOfFile = false; DWORD dwFilePos = SetFilePointer(m_hFile, 0, NULL, FILE_CURRENT); CHECK_LAST_ERROR(-1); dwFilePos -= nDeltaPos; _ASSERTE((int)dwFilePos >= 0); // check 2GB limit SetFilePointer(m_hFile, nLength, NULL, FILE_BEGIN); CHECK_LAST_ERROR(-1); SetEndOfFile(m_hFile); CHECK_LAST_ERROR(-1); if ((int)dwFilePos > nLength) dwFilePos = nLength; SetFilePointer(m_hFile, dwFilePos, NULL, FILE_BEGIN); CHECK_LAST_ERROR(-1); return nLength; }
bool ReceiveOneBuffer() { size_t received = 0; while (received < size_) { boost::system::error_code ec; size_t remaining_size = size_ - received; socket_.send(boost::asio::buffer(&remaining_size, sizeof(remaining_size)), 0, ec); if (ec) { return false; } auto n = socket_.receive(boost::asio::buffer(one_buffer_), 0, ec); if (ec) { return false; } if (n == 0) { return false; } else { received += n; if (!CheckOneBuffer(n)) { return false; } ResetBuffer(); } } return received == size_; }
BOOL COverlappedSend::Push(char* pMsg,DWORD dwLen) { BOOL bResult = FALSE; DWORD dwTail; char* p; dwTail = m_dwExistPacketSize + m_dwEntryPosition; // °¡¿ë ¹öÆÛ »çÀÌÁî°¡ º¸³»°íÀÚ ÇÏ´Â »çÀÌÁ´Ù ÀûÀ» °æ¿ì ¿£Æ®¸® Æ÷Áö¼Ç ÀçÁ¶Á¤. // ±×·¯°íµµ dwLenº¸´Ù ºÎÁ·Çϸé false¸®ÅÏ if (dwTail + dwLen + 2 > m_dwMaxBufferSize) { if (ResetBuffer() < dwLen + 2) goto lb_return; } p = m_pBuffer + m_dwEntryPosition + m_dwExistPacketSize; *(WORD*)p = (WORD)dwLen; memcpy(p + 2,pMsg,dwLen); m_dwExistPacketSize += (dwLen + 2); bResult = TRUE; lb_return: // if( !bResult) // printf("Push Operation Error\n"); return bResult; }
DaemonSocketPDU::DaemonSocketPDU(size_t aPayloadSize) : mConsumer(nullptr) { MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer); size_t availableSpace = PDU_HEADER_SIZE + aPayloadSize; ResetBuffer(new uint8_t[availableSpace], 0, 0, availableSpace); }
status_t LinkReceiver::GetNextMessage(int32 &code, bigtime_t timeout) { fReadError = B_OK; int32 remaining = fDataSize - (fRecvStart + fReplySize); STRACE(("info: LinkReceiver GetNextReply() reports %ld bytes remaining in buffer.\n", remaining)); // find the position of the next message header in the buffer message_header *header; if (remaining <= 0) { status_t err = ReadFromPort(timeout); if (err < B_OK) return err; remaining = fDataSize; header = (message_header *)fRecvBuffer; } else { fRecvStart += fReplySize; // start of the next message fRecvPosition = fRecvStart; header = (message_header *)(fRecvBuffer + fRecvStart); } // check we have a well-formed message if (remaining < (int32)sizeof(message_header)) { // we don't have enough data for a complete header STRACE(("error info: LinkReceiver remaining %ld bytes is less than header size.\n", remaining)); ResetBuffer(); return B_ERROR; } fReplySize = header->size; if (fReplySize > remaining || fReplySize < (int32)sizeof(message_header)) { STRACE(("error info: LinkReceiver message size of %ld bytes smaller than header size.\n", fReplySize)); ResetBuffer(); return B_ERROR; } code = header->code; fRecvPosition += sizeof(message_header); STRACE(("info: LinkReceiver got header %ld [%ld %ld %ld] from port %ld.\n", header->code, fReplySize, header->code, header->flags, fReceivePort)); return B_OK; }
void SPIListener::Run() { Setup(); CheckRun(); // Run until terminated while (1) { // Let the thread sleep for 1/10th of a second. usleep(LISTENER_SLEEP_DELAY); // Check each bus for a signal ResetBuffer(); CheckSignal(SPI_BUS_CAR); ResetBuffer(); CheckSignal(SPI_BUS_RF); } }
void InitializePixels(int width, int height) { //initiialize pixels - 2D array Pixels = malloc(sizeof(char*)*height*width*3); DepthBuffer = malloc(sizeof(char*)*height*width); ResetBuffer(width, height); printf("Pixels Initialized!\n"); //done }
//------------------------------------------------- void SwitchMode() { if (pShMem->vietKey) pShMem->vietKey = 0; else pShMem->vietKey = 1; if (pShMem->iconShown) ModifyStatusIcon(); ResetBuffer(); /* if (!pShMem->vietKey && UsKeyboardLayout && ViKeyboardLayout && GetKeyboardLayout(0) == ViKeyboardLayout) ActivateKeyboardLayout(UsKeyboardLayout, 0); */ }
/** * @return true if file pointer has been synchronized. */ bool CFileStream::SynchronizeBuffer(void) { if (m_eBufferType == BT_READ) { _ASSERTE(m_hFile != INVALID_HANDLE_VALUE); if (m_nBufferPos < m_nBufferLength) { SetFilePointer(m_hFile, m_nBufferPos - m_nBufferLength, NULL, FILE_CURRENT); CHECK_LAST_ERROR(false); } ResetBuffer(); } return true; }
//============================================================================== int CEyeTrack::ConnectISCAN( ){ int iRet; if( IsRunning() ) { CP_printf("Error in m_InitSerialThread()! Thread is already running.\n"); return 1; } iRet = g_SysGrantIO( LPT_BASE ); if( iRet ) { iPortIO_Granted = 0; printf("Error: Cannot grant I/O access, error: %d\n", iRet ); return 1; } iPortIO_Granted = 1; PortOutput( LPT_CONTROL, RESET_ON); Sleep(1); PortOutput( LPT_CONTROL, GATE_OFF); Sleep(1); PortOutput( LPT_CONTROL, GATE_ON); CP_printf("Connecting to %s port\n", x_aszComNames[ m_iComPortIdx-1]); iRet = m_Serial.connect(x_aszComNames[ m_iComPortIdx-1], m_iBaudRate, m_iSerialParity); if(iRet) { CP_printf("Error in m_InitSerialThread, m_Serial.connect() failed\n"); return 1; } m_ReadCount = 0; m_iMissCount = 0; m_nMissedFrames = 0; m_iPrevFrame = 0; m_iReportSync = 1; // report next sync // Init sliding buffer SetBuffer(sizeof(IScanFrameStruct), ISCAN_BUFFER_SIZE); ResetBuffer(); ResetTime(); m_StartReadingThread( ); if( !IsRunning() ) { CP_printf("Error in m_InitSerialThread()! CreateThread() failed.\n"); PortOutput( LPT_CONTROL, GATE_OFF); RemoveBuffer(); return 1; } CP_printf("Connected ISCAN\n"); CP_printf("Expected number of parameters: %d\n", N_DATA_ITEMS); return 0; }
/** * @return true if buffer has been be flushed. */ bool CFileStream::FlushBuffer(void) { if (m_eBufferType == BT_WRITE) { _ASSERTE(m_hFile != INVALID_HANDLE_VALUE); if (m_nBufferLength > 0) { DWORD dwNumWritten = 0; WriteFile(m_hFile, m_pBuffer, m_nBufferLength, &dwNumWritten, NULL); CHECK_LAST_ERROR(false); } ResetBuffer(); } return true; }
//------------------------------------------------- void SetKeyMode(WORD mode, int inMethod, CodeInfo *pTable) { pShMem->keyMode = mode; pShMem->inMethod = inMethod; pShMem->codeTable = *pTable; ResetBuffer(); /* if (pShMem->keyMode != WINCP1258_CHARSET && UsKeyboardLayout && ViKeyboardLayout && GetKeyboardLayout(0) == ViKeyboardLayout) { ActivateKeyboardLayout(UsKeyboardLayout, 0); MessageBeep(MB_ICONASTERISK); } */ }
void wxStreamBuffer::SetBufferIO(void *start, size_t len, bool takeOwnership) { // start by freeing the old buffer FreeBuffer(); m_buffer_start = (char *)start; m_buffer_end = m_buffer_start + len; // if we own it, we free it m_destroybuf = takeOwnership; ResetBuffer(); }
/*notice the default arguments for main. SDL expects main to look like that, so don't change it*/ int main(int argc, char *argv[]) { debuginputs = 1,bsize = 5; /*defaults for placeholder reasons*/ c1 = DEBUG; c2 = DEBUG; stage = ST_PLATFORM; /**/ pause = 0; pausequeue = 0; fpress = 0; Init_All(); /* SaveCFG(&f2,"res/test.txt");*/ do { UpdateMouse(); if(pausequeue==1){ pausequeue=0; GamePause(); } pausetimer--; InputControl(); if(GameState==VERSUS){ DrawVersus(); UpdateVersus(); }else if(GameState==MAIN_MENU){ DrawMainMenu(); UpdateMenu(); }else if(GameState==C_SELECT){ DrawCharSel(); UpdateCharSel(); }else if(GameState==C_CREATOR){ DrawCharCr(); UpdateCharCr(); } NextFrame(); if(endgame){ done = 1; } ResetBuffer(); }while(!done); exit(0); /*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/ return 0; }
/** * @param nBufferSize - buffer size. */ void CFileStream::InitBuffer(int nBufferSize) { ResetBuffer(); m_nBufferSize = nBufferSize; if (nBufferSize > 0) { m_pBuffer = new BYTE[nBufferSize]; if (m_pBuffer == NULL) { m_nBufferSize = 0; RaiseException(STATUS_NO_MEMORY, 0, 0, NULL); } } else m_pBuffer = NULL; }
void GameOptions(Game *game,int options) /*new game, quit, select difficulty*/ { Uint8 *keys; Sprite *menu; int done = 0; menu = LoadSprite("images/menu.png",640,480); do { ResetBuffer(); SDL_PumpEvents(); MouseThink(); keys = SDL_GetKeyState(NULL); if(keys[SDLK_ESCAPE] == 1) { exit(0); } if(keys[SDLK_RETURN] == 1) { FreeSprite(menu); SDL_PumpEvents(); return; } if(keys[SDLK_F2] == 1) { NewGame(game); NewLevel(game,8,4); /*sets up a new level*/ done = 1; FreeSprite(menu); } DrawMessages(); DrawSprite(menu,screen,(screen->w - 640)/2,(screen->h - 480)/2,0); DrawText("New Game : F2",screen,(screen->w - 640)/2 + 50,(screen->h - 480)/2 + 160,IndexColor(LightGreen),F_Medium); DrawText("Quit : Escape",screen,(screen->w - 640)/2 + 50,(screen->h - 480)/2 + 200,IndexColor(LightGreen),F_Medium); if(options == 0) { DrawText("This Menu : F1",screen,(screen->w - 640)/2 + 50,(screen->h - 480)/2 + 180,IndexColor(LightGreen),F_Medium); } else { DrawText("Cancel : Enter",screen,(screen->w - 640)/2 + 50,(screen->h - 480)/2 + 180,IndexColor(LightGreen),F_Medium); DrawText("Game Paused",screen,(screen->w / 2) - 80,(screen->h - 480)/2 + 440,IndexColor(LightRed),F_Small); } DrawMouse(); NextFrame(); }while(!done); }
int pause_menu() { static int i = 0; SDL_Renderer *render; render = gt_graphics_get_active_renderer(); SDL_RenderClear(gt_graphics_get_active_renderer()); ResetBuffer(); mainScreen = loadSprite("images/pause_screen.png",800,600,1); selection = loadSprite("images/selection.png",149,53,1); if(i == 0) { drawSprite(mainScreen,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(selection,0,vec2d(311,294),vec2d(1,1),0,gt_graphics_get_active_renderer()); }else if(i ==1) { drawSprite(mainScreen,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(selection,0,vec2d(311,377),vec2d(1,1),0,gt_graphics_get_active_renderer()); } NextFrame(); SDL_PumpEvents(); keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } if(keys[SDL_SCANCODE_DOWN]) { i = 1; } if(keys[SDL_SCANCODE_UP]) { i = 0; } if(keys[SDL_SCANCODE_RETURN]) { if(i == 0) { gameState = 1; } else { done = 1; } } return 1; }
// WARNING: This function is called in another thread BOOL GDisplay::Update( GraphData* pGraphData) { #ifndef _NO_INTEL_ADVISOR ANNOTATE_SITE_BEGIN(UpdateGDisplayData); #endif Lock lock(&g_csSimData); if (pGraphData->GetSize() >= m_nScreenBufferSize) { ResetBuffer(INIT_BUFFER_VALUE); pGraphData->SetSize(0); } for (int k = 0; k < MAX_CHART_COUNT; k++) { #ifndef _NO_INTEL_ADVISOR ANNOTATE_ITERATION_TASK(ExternalLoop); #endif for (int i = 0; i < MAX_BUFFER_SIZE; i++) { #ifndef _NO_INTEL_ADVISOR ANNOTATE_ITERATION_TASK(InternalLoop); #endif m_dScreenBuffer[k][i] = pGraphData->GetBufferValue(k, i); } } m_xUpdatePosition = pGraphData->GetSize()*m_xMinStep; lock.Release(); #ifndef _NO_INTEL_ADVISOR ANNOTATE_SITE_END(); #endif // TODO: This call failed when m_hWnd == NULL // before window is created InvalidateRect(NULL, FALSE); return TRUE; }
status_t LinkReceiver::ReadFromPort(bigtime_t timeout) { // we are here so it means we finished reading the buffer contents ResetBuffer(); status_t err = AdjustReplyBuffer(timeout); if (err < B_OK) return err; int32 code; ssize_t bytesRead; STRACE(("info: LinkReceiver reading port %ld.\n", fReceivePort)); while (true) { if (timeout != B_INFINITE_TIMEOUT) { do { bytesRead = read_port_etc(fReceivePort, &code, fRecvBuffer, fRecvBufferSize, B_TIMEOUT, timeout); } while (bytesRead == B_INTERRUPTED); } else { do { bytesRead = read_port(fReceivePort, &code, fRecvBuffer, fRecvBufferSize); } while (bytesRead == B_INTERRUPTED); } STRACE(("info: LinkReceiver read %ld bytes.\n", bytesRead)); if (bytesRead < B_OK) return bytesRead; // we just ignore incorrect messages, and don't bother our caller if (code != kLinkCode) { STRACE(("wrong port message %lx received.\n", code)); continue; } // port read seems to be valid break; } fDataSize = bytesRead; return B_OK; }
static int __gz_lines_iterator (lua_State *L) { gzFile zf = (gzFile) lua_topointer (L, lua_upvalueindex(1)); int ch = '\0'; char* ret; if (content_buffer_length == 0) ExtendBuffer (); else ResetBuffer (); #ifdef READ_LINE_ONE_BY_ONE while ( (ch = gzgetc(zf)) != -1 && ch != '\n') { AddToBuffer ((char) ch); } #else do { ret = gzgets (zf, content_buffer + BufferFill (), BufferFree ()); if (ret == Z_NULL) break; int l = strlen (content_buffer); content_length = l; if (l > 0) { ch = content_buffer[l - 1]; if (ch != '\n') ExtendBuffer (); else content_buffer[l-1] = '\0'; } } while (ret && ch != '\n'); #endif if (ch == '\n' || BufferFill () > 0) { if (ch == '\n') lua_pushstring (L, FinishBuffer ()); return 1; } else { return pushresult(L, &zf, NULL); } }
/** * @brief wifi_file_erase_external_flash * This API allows to erase the content of the external flash * @param None * @retval WiFi_Status_t */ WiFi_Status_t wifi_file_erase_external_flash() { WiFi_Status_t status = WiFi_MODULE_SUCCESS; Reset_AT_CMD_Buffer(); ResetBuffer(); /* AT+S.HTTPDFSUPDATE=%s,/outfile.img */ sprintf((char*)(char*)WiFi_AT_Cmd_Buff,AT_ERASE_FLASH_MEMORY); status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); /* Soft reset the module */ SET_Power_State(PowerSave_State); return status; }
DaemonSocketPDU::DaemonSocketPDU(uint8_t aService, uint8_t aOpcode, uint16_t aPayloadSize) : mConsumer(nullptr) { MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer); // Allocate memory size_t availableSpace = PDU_HEADER_SIZE + aPayloadSize; ResetBuffer(new uint8_t[availableSpace], 0, 0, availableSpace); // Reserve PDU header uint8_t* data = Append(PDU_HEADER_SIZE); MOZ_ASSERT(data); // Setup PDU header data[PDU_OFF_SERVICE] = aService; data[PDU_OFF_OPCODE] = aOpcode; memcpy(data + PDU_OFF_LENGTH, &aPayloadSize, sizeof(aPayloadSize)); }
void BinaryBufferBuilder::FlushBufferToFile(const std::string& filePath, bool refreshBuffer/*=false*/) { FILE* file; fopen_s(&file, filePath.c_str(), "wb+"); if (!file) { CreateDirectoriesForFilePath(filePath); } if (file) fwrite(m_charsToWrite.data(), 1, m_charsToWrite.size(), file); if (refreshBuffer) ResetBuffer(); fclose(file); }
/** * @param arrBytes - array of bytes. * @param nCount - size of the array. * @return number of written bytes. */ int CFileStream::WriteBytes(const unsigned char* arrBytes, int nCount) { CHECK_FILE_HANDLE(-1); if (m_pBuffer != NULL) { if (! SynchronizeBuffer()) return -1; int nTotalLength = 0; for (;;) { int nNumBytes = m_nBufferSize - m_nBufferLength; if (nNumBytes > nCount) nNumBytes = nCount; if (nNumBytes > 0) { m_eBufferType = BT_WRITE; CopyMemory(m_pBuffer + m_nBufferLength, arrBytes, nNumBytes); arrBytes += nNumBytes; nTotalLength += nNumBytes; nCount -= nNumBytes; m_nBufferLength += nNumBytes; } if (nCount == 0) break; _ASSERTE(m_nBufferLength == m_nBufferSize); DWORD dwNumWritten = 0; WriteFile(m_hFile, m_pBuffer, m_nBufferSize, &dwNumWritten, NULL); m_lLastError = GetLastError(); ResetBuffer(); if (m_lLastError != NOERROR) break; } return nTotalLength; } else { DWORD dwNumWritten = 0; WriteFile(m_hFile, arrBytes, nCount, &dwNumWritten, NULL); m_lLastError = GetLastError(); return (int)dwNumWritten; } }
/*notice the default arguments for main. SDL expects main to look like that, so don't change it*/ int main(int argc, char *argv[]) { SDL_Surface *temp = NULL; int i; int done; int tx = 0,ty = 0; const Uint8 *keys; char imagepath[512]; SDL_Rect srcRect={0,0,800,600}; Init_All(); temp = IMG_Load("images/bgtest.png");/*notice that the path is part of the filename*/ //if(temp != NULL) //{ // for(i = 0;i < 12;i++) // { // drawSprite(tile,buffer,(i * tile->w) + tx,ty,0); // SDL_FreeSurface(temp); // } //} slog("got here"); gt_graphics_render_surface_to_screen(temp,srcRect,0,0); SDL_FreeSurface(temp); slog("got here"); done = 0; do { ResetBuffer(); NextFrame(); SDL_PumpEvents(); keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } }while(!done); slog("got here"); exit(0); /*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/ return 0; }
/** * @param nOffset - offset from start point. * @param nMoveMethod - start point. * @return new position value. */ int CFileStream::SetPosition(int nOffset, int nMoveMethod) { CHECK_FILE_HANDLE(-1); m_bEndOfFile = false; int nDeltaPos = 0; if (m_eBufferType == BT_READ) { if (nMoveMethod == FILE_CURRENT) nDeltaPos = m_nBufferLength - m_nBufferPos; ResetBuffer(); } else { if (! FlushBuffer()) return -1; } DWORD dwFilePos = SetFilePointer(m_hFile, nOffset - nDeltaPos, NULL, nMoveMethod); CHECK_LAST_ERROR(-1); _ASSERTE((int)dwFilePos >= 0); // check 2GB limit return (int)dwFilePos; }