//Flush DNS cache FIFO Monitor bool FlushDNSFIFOMonitor( void) { //Initialization unlink(FIFO_PATH_NAME); std::shared_ptr<char> Buffer(new char[PACKET_MAXSIZE]()); memset(Buffer.get(), 0, PACKET_MAXSIZE); int FIFO_FD = 0; //Create FIFO. if (mkfifo(FIFO_PATH_NAME, O_CREAT) < EXIT_SUCCESS || chmod(FIFO_PATH_NAME, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) < EXIT_SUCCESS) { PrintError(LOG_ERROR_SYSTEM, L"Create FIFO error", errno, nullptr, 0); unlink(FIFO_PATH_NAME); return false; } //Open FIFO. FIFO_FD = open(FIFO_PATH_NAME, O_RDONLY, 0); if (FIFO_FD < EXIT_SUCCESS) { PrintError(LOG_ERROR_SYSTEM, L"Create FIFO error", errno, nullptr, 0); unlink(FIFO_PATH_NAME); return false; } //FIFO Monitor for (;;) { memset(Buffer.get(), 0, PACKET_MAXSIZE); if (read(FIFO_FD, Buffer.get(), PACKET_MAXSIZE) > 0 && memcmp(Buffer.get(), FIFO_MESSAGE_FLUSH_DNS, strlen(FIFO_MESSAGE_FLUSH_DNS)) == EXIT_SUCCESS) FlushAllDNSCache(); Sleep(LOOP_INTERVAL_TIME_MONITOR); } //Monitor terminated close(FIFO_FD); unlink(FIFO_PATH_NAME); PrintError(LOG_ERROR_SYSTEM, L"FIFO module Monitor terminated", 0, nullptr, 0); return true; }
ICQFullInfo::AddressItemList ICQFullInfo::parseAddressItemList( const QByteArray& data ) const { Buffer buffer( data ); AddressItemList infoList; int count = buffer.getWord(); while ( (count--) > 0 ) { QList<TLV> tlvList = Buffer( buffer.getBSTR() ).getTLVList(); AddressItem info; QList<TLV>::const_iterator it; for ( it = tlvList.constBegin(); it != tlvList.constEnd(); ++it ) { switch ( (*it).type ) { case 0x0064: info.address = (*it).data; break; case 0x006E: info.city = (*it).data; break; case 0x0078: info.state = (*it).data; break; case 0x0082: info.zip = (*it).data; break; case 0x008C: { Buffer b( (*it).data ); info.country = b.getDWord(); } break; default: kDebug(OSCAR_RAW_DEBUG) << "Unhandled tlv: " << hex << (*it).type << " data: " << hex << (*it).data; break; } } infoList.append( info ); } return infoList; }
bool produce_one() { ssize_t n = getline(&buffer_, &cap_, file_); if (n <= 0) { return false; } if (buffer_[n-1] == '\n') { buffer_[n-1] = '\0'; n--; } emit(Buffer(buffer_, n)); return true; }
//IDを生成・ロードする std::string GetID() { std::vector<wchar_t> Buffer(MAX_PATH,0); std::string IDString; bool OldIDFileExist=false; SHGetSpecialFolderPath(nullptr,Buffer.data(),CSIDL_APPDATA,false); std::wstring IDFile(Buffer.data()); IDFile=IDFile+L"\\81Gyazo"+L"\\id.txt"; //まずはファイルから ID をロード std::ifstream IDFileStream; IDFileStream.open(IDFile); if(!!IDFileStream){ //IDを読み込む IDFileStream>>IDString; IDFileStream.close(); }
/** read: * read data from the current bufer to a new buffer object * * @param int togo * bytes to be read * * @return object * New Buffer containing the read data */ void CJSBuffer::FxRead(const v8::FunctionCallbackInfo<v8::Value> &args) { v8::HandleScope HandleScope(v8::Isolate::GetCurrent()); CJSBuffer* jBuffer = GetJSObject<CJSBuffer>(args.Holder()); CBufferObj* pBuffer = jBuffer->m_pBuffer; if (args.Length() < 1) { args.GetIsolate()->ThrowException(v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), (uint8_t*)"Invalid Argument")); return; } BUFFER_TRY size_t ToGo = args[0]->Uint32Value(); CBuffer Buffer(ToGo); Buffer.WriteData(pBuffer->ReadData(ToGo), ToGo); CJSObject* jObject = CJSBuffer::New(new CBufferObj(Buffer), jBuffer->m_pScript); args.GetReturnValue().Set(jObject->GetInstance()); BUFFER_CATCH }
GMPErr GMPPlaneImpl::Copy(const GMPPlane& aPlane) { auto& planeimpl = static_cast<const GMPPlaneImpl&>(aPlane); GMPErr err = MaybeResize(planeimpl.mSize); if (err != GMPNoErr) { return err; } if (planeimpl.Buffer() && planeimpl.mSize > 0) { memcpy(Buffer(), planeimpl.Buffer(), mSize); } mSize = planeimpl.mSize; mStride = planeimpl.mStride; return GMPNoErr; }
// Buffer a block of data int LineBuffer:: Buffer( const char ** buf, int *nptr ) { const char *bptr = *buf; int nbytes = *nptr; // Loop through the whole input buffer while( nbytes-- ) { int status = Buffer( *bptr++ ); if ( status ) { *buf = bptr; *nptr = nbytes; return status; } } *nptr = 0; return 0; }
void Connection::start() { LOG_DEBUG(socket().native() << ": start()"); request_parser_.reset(); request_.reset(); try { request_.remoteIP = socket().remote_endpoint().address().to_string(); request_.port = socket().local_endpoint().port(); } catch (std::exception& e) { LOG_ERROR("remote_endpoint() threw: " << e.what()); } asio_error_code ignored_ec; socket().set_option(asio::ip::tcp::no_delay(true), ignored_ec); rcv_buffers_.push_back(Buffer()); startAsyncReadRequest(rcv_buffers_.back(), CONNECTION_TIMEOUT); }
Buffer RDMACMSocket::get_send_buf() { if (send_bufs.empty()) { struct ibv_wc wc[PACKET_WINDOW_SIZE]; int ret = poll_send_cq(PACKET_WINDOW_SIZE, wc); for (int i = 1; i < ret; ++i) { send_bufs.push_back(Buffer(reinterpret_cast<char*>(wc[i].wr_id), PACKET_SIZE)); } Buffer buf(reinterpret_cast<char*>(wc[0].wr_id), PACKET_SIZE); buf.clear(); return buf; } Buffer ret = send_bufs.front(); send_bufs.pop_front(); ret.clear(); return ret; }
void ImmutableIndexWriter::Finalize() { FlushBuffer(); if (!index_offsets.empty()) { WriteData(Buffer(&index_offsets[0], index_offsets.size() * sizeof(offset_t)), RECORD_TYPE_INDEX_OFFSETS); for(vector<Buffer>::iterator i = index_keys.begin(); i != index_keys.end(); ++i) { WriteData(*i, RECORD_TYPE_INDEX_KEY); } } else { WriteData(Buffer::Empty(), RECORD_TYPE_INDEX_OFFSETS); } WriteData(Buffer::Empty(), RECORD_TYPE_FILE_FOOTER); storage.commit(); storage.truncate(); storage.close(); }
long File::Copy(File &Dest,Int64 Length) { Array<char> Buffer(0x10000); long CopySize=0; bool CopyAll=(Length==INT64ERR); while (CopyAll || Length>0) { Wait(); int SizeToRead=(!CopyAll && Length<Buffer.Size()) ? int64to32(Length):Buffer.Size(); int ReadSize=Read(&Buffer[0],SizeToRead); if (ReadSize==0) break; Dest.Write(&Buffer[0],ReadSize); CopySize+=ReadSize; if (!CopyAll) Length-=ReadSize; } return(CopySize); }
/** this is not needed for bulk_extractor */ int64 File::Copy(File &Dest,int64 Length) { //This file is not called in bulk_extractor Array<char> Buffer(0x10000); int64 CopySize=0; bool CopyAll=(Length==INT64NDF); while (CopyAll || Length>0) { Wait(); size_t SizeToRead=(!CopyAll && Length<(int64)Buffer.Size()) ? (size_t)Length:Buffer.Size(); int ReadSize=Read(&Buffer[0],SizeToRead); if (ReadSize==0) break; Dest.Write(&Buffer[0],ReadSize); CopySize+=ReadSize; if (!CopyAll) Length-=ReadSize; } return(CopySize); }
bool IComplexDatum::DeserializeJSON (const CString &sTypename, const TArray<CDatum> &Data) // DeserializeJSON // // Deserialize from JSON { if (Data.GetCount() == 0 || Data[0].GetBasicType() != CDatum::typeString) return false; // LATER: Handle serialization/deserialization of struct-based objects // Default deserialization CStringBuffer Buffer(Data[0]); CBase64Decoder Decoder(&Buffer); if (!OnDeserialize(CDatum::formatJSON, sTypename, Decoder)) return false; return true; }
//読み取り元ファイルを書き込み先ファイルのseekのある箇所から後にコピーして書き込む //戻り値はエラーなしなら0,読み取りエラーは1,書き込みエラーは-1 int UtilAppendFile(HANDLE hWriteTo,HANDLE hReadFrom) { //16KBずつコピー DWORD dwRead=0,dwWrite=0; std::vector<BYTE> Buffer(16*1024); for(;;){ if(!ReadFile(hReadFrom,&Buffer.at(0),16*1024,&dwRead,NULL)){ return 1; } if(0==dwRead){ break; } if(!WriteFile(hWriteTo,&Buffer.at(0),dwRead,&dwWrite,NULL)){ return -1; } if(dwRead!=dwWrite){ return -1; } } return 0; }
void WriteHandler::handle(Event& evt){ EpollEvent& eref = static_cast<EpollEvent&>(evt); logger.log("do write handle for fd: "); int fd = eref.getFd(); logger.log(fd); if(handleTable.find(fd) == handleTable.end()){ handleTable[fd] = Buffer(); } Buffer& buffer =handleTable[fd]; const char* buf = "say server"; size_t num = Sockets::write(fd,buf,strlen(buf),0); if(num == -1){ logger.log("write data to connection error"); } }
// /// Loads a "hand" cursor from the winhlp32.exe module. // /// \note It appeared in Paul DiLascia's Jan 1998 MSJ articles. void TUrlLink::SetupCursor() { SetCursor(GetModule(), IDC_HANDCURSOR); if(HCursor == 0){ // if was problem try load cursor from winhlp32.exe // Get the windows directory TAPointer<tchar> Buffer(new tchar[MAX_PATH]); ::GetWindowsDirectory(Buffer, MAX_PATH); _tcscat(Buffer,_T("\\winhlp32.exe")); // This retrieves cursor #106 from winhlp32.exe, which is a hand pointer HMODULE hModule = ::LoadLibrary(Buffer); if (hModule) { HCURSOR hHandCursor = ::LoadCursor(hModule, TResId(106)); if (hHandCursor) HCursor = CopyCursor(hHandCursor); // it is a macro in Win32 ::FreeLibrary(hModule); } } }
bool CampTools::SetCamp(DWORD dwPlayerID, BYTE bCamp) { S2R_APPLY_SET_CAMP_REQUEST Request; Request.wProtocolID = s2r_apply_set_camp_request; Request.dwPlayerID = dwPlayerID; Request.byNewCamp = bCamp; m_pGS->Send(&Request, sizeof(Request)); SCOPEPROTOCOL(m_pGS, r2s_apply_set_camp_respond); BufferScopedPrt Buffer(m_pGS->ReceiveDataOnce(r2s_apply_set_camp_respond)); if (!Buffer.get()) { return false; } R2S_APPLY_SET_CAMP_RESPOND* pRespond = (R2S_APPLY_SET_CAMP_RESPOND*)Buffer->GetData(); if ((pRespond->byResult == crtSuccess) && (pRespond->dwPlayerID = dwPlayerID)) { return true; } return false; }
bool GLSLShader::validateProgram() { if(!*m_program_object) return false; glValidateProgram(*m_program_object); GLint Result = GL_FALSE; glGetProgramiv(*m_program_object, GL_VALIDATE_STATUS, &Result); if(Result == GL_FALSE) { CGoGNout << "Validate program:" << CGoGNendl; int InfoLogLength; glGetProgramiv(*m_program_object, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> Buffer(InfoLogLength); glGetProgramInfoLog(*m_program_object, InfoLogLength, NULL, &Buffer[0]); CGoGNout << &(Buffer[0]) << CGoGNendl; return false; } return true; }
QPixmap* SlippyMapCache::getDirty(int x, int y, int Zoom) { if (Zoom == MINZOOMLEVEL) return 0; QMap<Coord,QByteArray>::iterator i = Dirties.find(Coord(x,y,Zoom)); if (i != Dirties.end()) { QPixmap* img = new QPixmap; img->loadFromData(i.value()); return img; } QPixmap* img = getImage(x/2,y/2,Zoom-1); if (!img) return 0; QPixmap* pm = new QPixmap(img->copy((x%2)*TILESIZE/2,(y%2)*TILESIZE/2,TILESIZE/2,TILESIZE/2).scaled(TILESIZE,TILESIZE)); delete img; QByteArray Data; QBuffer Buffer(&Data); Buffer.open(QIODevice::WriteOnly); pm->save(&Buffer,"PNG"); Coord C(x,y,Zoom); Dirties[C] = Data; return pm; }
BOOL UtilMoveFileToRecycleBin(const std::list<CString> &fileList) { ASSERT(!fileList.empty()); if(fileList.empty())return false; //引数作成 CString Param; for(std::list<CString>::const_iterator ite=fileList.begin();ite!=fileList.end();++ite){ Param+=*ite; Param+=_T('|'); } Param+=_T('|'); std::vector<TCHAR> Buffer(Param.GetLength()+1); UtilMakeFilterString(Param,&Buffer[0],Buffer.size()); SHFILEOPSTRUCT shfo={0}; shfo.wFunc=FO_DELETE; //削除 shfo.pFrom=&Buffer[0];//ファイル名のリスト末尾は\0\0で終わる必要有り shfo.fFlags=FOF_SILENT/*進捗状況を表示しない*/|FOF_ALLOWUNDO/*UNDO情報付加;ごみ箱へ*/|FOF_NOCONFIRMATION/*確認ダイアログを表示しない*/; return SHFileOperation(&shfo); }
int RTCPCompoundPacketBuilder::AddReportBlock(uint32_t ssrc,uint8_t fractionlost,int32_t packetslost,uint32_t exthighestseq, uint32_t jitter,uint32_t lsr,uint32_t dlsr) { if (!arebuilding) return ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING; if (report.headerlength == 0) return ERR_RTP_RTCPCOMPPACKBUILDER_REPORTNOTSTARTED; #ifndef RTP_SUPPORT_RTCPUNKNOWN size_t totalothersize = byesize+appsize+sdes.NeededBytes(); #else size_t totalothersize = byesize+appsize+unknownsize+sdes.NeededBytes(); #endif // RTP_SUPPORT_RTCPUNKNOWN size_t reportsizewithextrablock = report.NeededBytesWithExtraReportBlock(); if ((totalothersize+reportsizewithextrablock) > maximumpacketsize) return ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT; uint8_t *buf = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTCPRECEIVERREPORT) uint8_t[sizeof(RTCPReceiverReport)]; if (buf == 0) return ERR_RTP_OUTOFMEM; RTCPReceiverReport *rr = (RTCPReceiverReport *)buf; uint32_t *packlost = (uint32_t *)&packetslost; uint32_t packlost2 = (*packlost); rr->ssrc = htonl(ssrc); rr->fractionlost = fractionlost; rr->packetslost[2] = (uint8_t)(packlost2&0xFF); rr->packetslost[1] = (uint8_t)((packlost2>>8)&0xFF); rr->packetslost[0] = (uint8_t)((packlost2>>16)&0xFF); rr->exthighseqnr = htonl(exthighestseq); rr->jitter = htonl(jitter); rr->lsr = htonl(lsr); rr->dlsr = htonl(dlsr); report.reportblocks.push_back(Buffer(buf,sizeof(RTCPReceiverReport))); return 0; }
inline bool Read(HANDLE Pipe, string& Data) { bool Result=false; size_t DataSize = 0; if(ReadPipe(Pipe, &DataSize, sizeof(DataSize))) { if(DataSize) { wchar_t_ptr Buffer(DataSize / sizeof(wchar_t) ); if(ReadPipe(Pipe, Buffer.get(), DataSize)) { Data.assign(Buffer.get(), Buffer.size() - 1); Result=true; } } else { Result=true; } } return Result; }
void LogSinkImpl::rotate(std::time_t time) { if (_prog.empty()) return; std::time_t day = time - time % (60*60*24); if (day == _time) return; MUTEX_GUARD(_mutex); if (day == _time) return; const bool print_msg = _time; _time = day; # ifdef LINKO_LOG_THREAD if (_thread) { _queue.push(Buffer()); _cond.notify_one(); return; } # endif mx_rotate(print_msg); }
KMAIL_RESULT_CODE MailTools::DeleteMail(DWORD dwPlayerID, DWORD dwMailID) { S2R_DELETE_MAIL DeleteMailRequest; DeleteMailRequest.wProtocolID = s2r_delete_mail; DeleteMailRequest.dwPlayerID = dwPlayerID; DeleteMailRequest.dwMailID = dwMailID; m_pGS->Send(DeleteMailRequest); BufferScopedPrt Buffer(m_pGS->ReceiveDataOnceTime(r2s_mail_general_respond, 3)); if (!Buffer.get()) { return mrcFailed; } R2S_MAIL_GENERAL_RESPOND* pRespond = (R2S_MAIL_GENERAL_RESPOND*)Buffer->GetData(); if (pRespond->dwPlayerID != dwPlayerID || pRespond->dwMailID != dwMailID) { return mrcFailed; } return (KMAIL_RESULT_CODE)pRespond->byRespond; }
/* Updates the client by retrieving all the data send by the client and processing it. */ void SquareSession::Update() { int received = mSocket->Receive( &mBufferIn ); if (received == SOCKET_ERROR) return; /* If we receive no data for a specific period of time close the connection. */ time_t current = time(NULL); if ( received == 0 && ( current - mLastUpdate ) >= MAX_IDLE_TIME ) { mSocket->Disconnect(); mEOF = true; return; } else if (received > 0) mLastUpdate = current; /* Process all packets in the incoming data buffer. */ while ( mBufferIn.Size() >= 2 ) { size_t len = mBufferIn[0] | (mBufferIn[1] << 8); if ( len <= mBufferIn.Size() ) { char *data = (char *)malloc( len ); mBufferIn.Slice( data, len, 0 ); Process( Buffer( data, len ) ); free( data ); } else break; } /* Send the content of the outgoing buffer to the square server. */ if ( mBufferOut.Size() > 0 ) { mSocket->Send( (char *)mBufferOut.Content(), mBufferOut.Size() ); mBufferOut.Clear(); } }
int RTCPCompoundPacketBuilder::AddUnknownPacket(uint8_t payload_type, uint8_t subtype, uint32_t ssrc, const void *data, size_t len) { if (!arebuilding) return ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING; size_t datawords = len/4; if ((datawords+2) > 65535) return ERR_RTP_RTCPCOMPPACKBUILDER_APPDATALENTOOBIG; size_t packsize = sizeof(RTCPCommonHeader)+sizeof(uint32_t)+len; size_t totalotherbytes = appsize+unknownsize+byesize+sdes.NeededBytes()+report.NeededBytes(); if ((totalotherbytes + packsize) > maximumpacketsize) return ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT; uint8_t *buf = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTCPUNKNOWNPACKET) uint8_t[packsize]; if (buf == 0) return ERR_RTP_OUTOFMEM; RTCPCommonHeader *hdr = (RTCPCommonHeader *)buf; hdr->version = 2; hdr->padding = 0; hdr->count = subtype; hdr->length = htons((uint16_t)(datawords+1)); hdr->packettype = payload_type; uint32_t *source = (uint32_t *)(buf+sizeof(RTCPCommonHeader)); *source = htonl(ssrc); if (len > 0) memcpy((buf+sizeof(RTCPCommonHeader)+sizeof(uint32_t)),data,len); unknownpackets.push_back(Buffer(buf,packsize)); unknownsize += packsize; return 0; }
int FindIndex(SOCKET Socket) { int ItemIndex = SendMessage(lsClients, LB_GETCOUNT, 0, 0) - 1; if (ItemIndex < 0) return 0; // Loop through the list in reverse until a match is found while (ItemIndex >= 0) { int Length = (int)SendMessage(lsClients, LB_GETTEXTLEN, (WPARAM)ItemIndex, 0); if (Length > 0) { // Get text of item std::vector<WCHAR> Buffer(Length + 1); SendMessage(lsClients, LB_GETTEXT, (WPARAM)ItemIndex, (LPARAM)&Buffer[0]); std::wstring ItemText(&Buffer[0]); // Add space to avoid errors ItemText += L" "; // Separate first word int Space = ItemText.find(L" "); std::string StrSocket(ItemText.begin(), ItemText.begin() + Space); // Convert word and SOCKET to integars to compare int iSocket = atoi(StrSocket.c_str()); if (iSocket == (int)Socket) return ItemIndex; } --ItemIndex; } return 0; };
/*=========================================================================== * * Class CSrResourceFolder Method - CSrResourceFile* FindFullFile (pFilename); * *=========================================================================*/ CSrResourceFile* CSrResourceFolder::FindFullFile (const char* pFilename) { CSrResourceBase* pBase; CSString Buffer(pFilename); int Index; Index = Buffer.FindChar('\\'); /* Find a file if no more path left */ if (Index < 0) { pBase = FindFile(Buffer); if (pBase == NULL || pBase->IsFolder()) return (NULL); return (CSrResourceFile *) pBase; } CSString SubPath(Buffer); SubPath.Truncate(Index); Buffer.Delete(0, Index + 1); pBase = FindSubFolder(SubPath); if (pBase == NULL || !pBase->IsFolder()) return (NULL); return ((CSrResourceFolder *) pBase)->FindFullFile(Buffer); }
int32_t ExecuteRequest::encode_batch(int version, BufferVec* bufs, Handler* handler) const { int32_t length = 0; const std::string& id(prepared_->id()); // <kind><id><n><value_1>...<value_n> ([byte][short bytes][short][bytes]...[bytes]) int buf_size = sizeof(uint8_t) + sizeof(uint16_t) + id.size() + sizeof(uint16_t); bufs->push_back(Buffer(buf_size)); length += buf_size; Buffer& buf = bufs->back(); size_t pos = buf.encode_byte(0, kind()); pos = buf.encode_string(pos, id.data(), id.size()); buf.encode_uint16(pos, elements_count()); if (elements_count() > 0) { int32_t result = copy_buffers(version, bufs, handler); if (result < 0) return result; length += result; } return length; }
CFilePath &CFilePath::ShrinkXXLPath() { if (msPath.GetLength() >= 6 && _tcsncmp(msPath, L"\\\\?\\", 4) == 0) { LPCTSTR psPath = msPath; if (GetDriveLetter(psPath[4]) != 0 && psPath[5] == ':') { msPath = msPath.Mid(4); } else if (msPath.GetLength() >= 8) { if (_tcsnicmp(psPath + 4, L"UNC\\", 4) == 0) { int nLen = msPath.GetLength() - 8; CStringLock Buffer(msPath); memmove(Buffer + 2, Buffer + 8, nLen * sizeof(TCHAR)); Buffer.Release(nLen + 2); } } } return *this; }