void LLVOCache::readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::vocache_entry_map_t& cache_entry_map) { llassert_always(mInitialized); handle_entry_map_t::iterator iter = mHandleEntryMap.find(handle) ; if(iter == mHandleEntryMap.end()) //no cache { return ; } std::string filename; getObjectCacheFilename(handle, filename); LLAPRFile* apr_file = new LLAPRFile(filename, APR_READ|APR_BINARY, mLocalAPRFilePoolp); LLUUID cache_id ; if(!checkRead(apr_file, cache_id.mData, UUID_BYTES)) { return ; } if(cache_id != id) { llinfos << "Cache ID doesn't match for this region, discarding"<< llendl; delete apr_file ; return ; } S32 num_entries; if(!checkRead(apr_file, &num_entries, sizeof(S32))) { return ; } for (S32 i = 0; i < num_entries; i++) { LLVOCacheEntry* entry = new LLVOCacheEntry(apr_file); if (!entry->getLocalID()) { llwarns << "Aborting cache file load for " << filename << ", cache file corruption!" << llendl; delete entry ; break; } cache_entry_map[entry->getLocalID()] = entry; } num_entries = cache_entry_map.size() ; delete apr_file ; return ; }
OrientationSphere::OrientationSphere(const ActionOptions&ao): Action(ao), MultiColvarFunction(ao) { // Resize everything that stores a vector now that we know the // number of components unsigned ncomponents=getBaseMultiColvar(0)->getNumberOfQuantities() - 5; catom_orient.resize( ncomponents ); catom_der.resize( ncomponents ); this_orient.resize( ncomponents ); // Weight of this does not have derivatives weightHasDerivatives=false; // Read in the switching function std::string sw, errors; parse("SWITCH",sw); if(sw.length()>0){ switchingFunction.set(sw,errors); } else { double r_0=-1.0, d_0; int nn, mm; parse("NN",nn); parse("MM",mm); parse("R_0",r_0); parse("D_0",d_0); if( r_0<0.0 ) error("you must set a value for R_0"); switchingFunction.set(nn,mm,r_0,d_0); } log.printf(" degree of overlap in orientation between central molecule and those within %s\n",( switchingFunction.description() ).c_str() ); // Set the link cell cutoff setLinkCellCutoff( 2.*switchingFunction.inverse( getTolerance() ) ); // Finish the setup of the object buildSymmetryFunctionLists(); // And check everything has been read in correctly checkRead(); }
void GaduSocketNotifiers::createSocketNotifiers() { kdebugf(); deleteSocketNotifiers(); if (0 >= Socket) return; ReadNotifier = new QSocketNotifier(Socket, QSocketNotifier::Read, this); connect(ReadNotifier, SIGNAL(activated(int)), this, SLOT(dataReceived())); if (!checkRead()) ReadNotifier->setEnabled(false); WriteNotifier = new QSocketNotifier(Socket, QSocketNotifier::Write, this); connect(WriteNotifier, SIGNAL(activated(int)), this, SLOT(dataSent())); if (!checkWrite()) WriteNotifier->setEnabled(false); TimeoutTimer = new QTimer(); TimeoutTimer->setSingleShot(true); connect(TimeoutTimer, SIGNAL(timeout()), this, SLOT(socketTimeout())); Started = true; int tout = timeout(); if (0 < tout) TimeoutTimer->start(tout); kdebugf2(); }
bool CTun::CollectPacket(IpPacket* p_poPacket) { if (!checkRead(10000)) { return false; } ssize_t br = read(m_nTunHandle, p_poPacket, MAX_IP_PACKET_SIZE); if(br < 0) { PERR("CTun::CollectPacket, read "TUN_INTERFACE); return false; } NLOG_DBG("CollectPacket, if:%s, sz:%d, data[%s%s]", m_szTunName, br, GET_HEX_LIMITED(&p_poPacket, (size_t)br, m_uHexLimit)); if (br < 1) { NLOG_WARN("CTun::CollectPacket, IP header too small: expected(1), received(0)"); return false; } int nIPversion = p_poPacket->Version(); switch(nIPversion){ case 4: return collectIp4Packet(&p_poPacket->m_stIp4, br); case 6: return collectIp6Packet(&p_poPacket->m_stIp6, br); default: return false; } }
uint64 InputMessage::getU64() { checkRead(8); uint64 v = stdext::readULE64(m_buffer + m_readPos); m_readPos += 8; return v; }
uint32 InputMessage::getU32() { checkRead(4); uint32 v = stdext::readULE32(m_buffer + m_readPos); m_readPos += 4; return v; }
uint16 InputMessage::getU16() { checkRead(2); uint16 v = stdext::readULE16(m_buffer + m_readPos); m_readPos += 2; return v; }
uint8 InputMessage::getU8() { checkRead(1); uint8 v = m_buffer[m_readPos]; m_readPos += 1; return v; }
std::string InputMessage::getString() { uint16 stringLength = getU16(); checkRead(stringLength); char* v = (char*)(m_buffer + m_readPos); m_readPos += stringLength; return std::string(v, stringLength); }
void LLVOCache::readCacheHeader() { //clear stale info. clearCacheInMemory(); if (LLAPRFile::isExist(mHeaderFileName, mLocalAPRFilePoolp)) { LLAPRFile* apr_file = new LLAPRFile(mHeaderFileName, APR_READ|APR_BINARY, mLocalAPRFilePoolp); //read the meta element if(!checkRead(apr_file, &mMetaInfo, sizeof(HeaderMetaInfo))) { return ; } HeaderEntryInfo* entry ; mNumEntries = 0 ; while(mNumEntries < MAX_NUM_OBJECT_ENTRIES) { entry = new HeaderEntryInfo() ; if(!checkRead(apr_file, entry, sizeof(HeaderEntryInfo))) { delete entry ; return ; } else if(!entry->mTime) //end of the cache. { delete entry ; return ; } entry->mIndex = mNumEntries++ ; mHeaderEntryQueue.insert(entry) ; mHandleEntryMap[entry->mHandle] = entry ; } delete apr_file ; } else { writeCacheHeader() ; } }
static VALUE memory_op_get_strptr(AbstractMemory* ptr, long offset) { void* tmp = NULL; if (ptr != NULL && ptr->address != NULL) { checkRead(ptr); checkBounds(ptr, offset, sizeof(tmp)); memcpy(&tmp, ptr->address + offset, sizeof(tmp)); } return tmp != NULL ? rb_tainted_str_new2(tmp) : Qnil; }
IMD::IMD(const ActionOptions& ao): Action(ao), ActionAtomistic(ao), ActionPilot(ao), host("localhost"), port(0), wait(false), wrap(false), sock(NULL), clientsock(NULL), connected(false), transferRate(100), fscale(1.0) { natoms=plumed.getAtoms().getNatoms(); std::vector<AtomNumber> index(natoms); for(int i=0;i<natoms;i++) index[i].setIndex(i); requestAtoms(index); coord.resize(natoms*3,float(0.0)); forces.resize(natoms*3,0.0); parseFlag("WAIT",wait); bool nowait=false; parseFlag("NOWAIT",nowait); if(nowait)wait=false; parseFlag("WRAP",wrap); parse("PORT",port); parse("HOST",host); parse("FSCALE",fscale); checkRead(); log.printf(" with host %s\n",host.c_str()); log.printf(" with port %d\n",port); if(wait) log.printf(" waiting for a connection\n"); else log.printf(" not waiting for a connection\n"); if(wrap) log.printf(" wrapping atoms\n"); else log.printf(" not wrapping atoms\n"); log.printf(" WMD forces will be scaled by %f\n",fscale); if(comm.Get_rank()==0){ vmdsock_init(); sock = vmdsock_create(); vmdsock_bind(sock, port); vmdsock_listen(sock); } connect(); }
static VALUE memory_get_bytes(VALUE self, VALUE offset, VALUE length) { AbstractMemory* ptr = MEMORY(self); long off, len; off = NUM2LONG(offset); len = NUM2LONG(length); checkRead(ptr); checkBounds(ptr, off, len); return rb_tainted_str_new((char *) ptr->address + off, len); }
void GaduSocketNotifiers::enable() { kdebugf(); if (!Started || Lock) return; if (checkRead()) ReadNotifier->setEnabled(true); if (checkWrite()) WriteNotifier->setEnabled(true); int tout = timeout(); if (0 < tout) TimeoutTimer->start(tout); }
bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d) { if (!checkRead(d)) return false; // don't bother if (d->ref.load() == 1) return true; // no need to detach QDBusDemarshaller *dd = new QDBusDemarshaller(d->capabilities); dd->message = q_dbus_message_ref(d->message); dd->iterator = static_cast<QDBusDemarshaller*>(d)->iterator; if (!d->ref.deref()) delete d; d = dd; return true; }
static VALUE memory_get_string(int argc, VALUE* argv, VALUE self) { VALUE length = Qnil, offset = Qnil; AbstractMemory* ptr = MEMORY(self); long off, len; char* end; int nargs = rb_scan_args(argc, argv, "11", &offset, &length); off = NUM2LONG(offset); len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off); checkRead(ptr); checkBounds(ptr, off, len); end = memchr(ptr->address + off, 0, len); return rb_tainted_str_new((char *) ptr->address + off, (end != NULL ? end - ptr->address - off : len)); }
bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d) { if (!checkRead(d)) return false; // don't bother if (d->ref == 1) return true; // no need to detach QDBusDemarshaller *dd = new QDBusDemarshaller; dd->message = dbus_message_ref(d->message); dd->iterator = static_cast<QDBusDemarshaller*>(d)->iterator; QDBusArgumentPrivate *old = qAtomicSetPtr(&d, static_cast<QDBusArgumentPrivate *>(dd)); if (!old->ref.deref()) delete old; return true; }
ExifStatus ExifStripImage::readImage( ExifImageDesc &imgDesc ) { if (checkRead(0) != EXIF_OK) return EXIF_FILE_READ_ERROR ; ExifStatus status = EXIF_OK ; exif_uint32 length = imgDesc.numberOfRows ; uint8* buf = imgDesc.components[0].theData ; for (unsigned int row=0; row<length; row++) { if( (status = readScanline(buf, row) ) != EXIF_OK ) return status ; buf += imgDesc.components[0].lineStride ; } return status ; }
/* * call-seq: []=(index, value) * @param [Numeric] index * @param [Type, Struct] * @return [value] */ static VALUE inline_array_aset(VALUE self, VALUE rbIndex, VALUE rbValue) { InlineArray* array; Data_Get_Struct(self, InlineArray, array); if (array->op != NULL) { if (unlikely(array->componentType->nativeType == NATIVE_MAPPED)) { rbValue = rb_funcall(((MappedType *) array->componentType)->rbConverter, rb_intern("to_native"), 2, rbValue, Qnil); } array->op->put(array->memory, inline_array_offset(array, NUM2INT(rbIndex)), rbValue); } else if (array->componentType->nativeType == NATIVE_STRUCT) { int offset = inline_array_offset(array, NUM2INT(rbIndex)); Struct* s; if (!rb_obj_is_kind_of(rbValue, rbffi_StructClass)) { rb_raise(rb_eTypeError, "argument not an instance of struct"); return Qnil; } checkWrite(array->memory); checkBounds(array->memory, offset, array->componentType->ffiType->size); Data_Get_Struct(rbValue, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(array->memory->address + offset, s->pointer->address, array->componentType->ffiType->size); } else { ArrayType* arrayType; Data_Get_Struct(array->field->rbType, ArrayType, arrayType); rb_raise(rb_eArgError, "set not supported for %s", rb_obj_classname(arrayType->rbComponentType)); return Qnil; } return rbValue; }
static VALUE memory_get_array_of_string(int argc, VALUE* argv, VALUE self) { VALUE offset = Qnil, countnum = Qnil, retVal = Qnil; AbstractMemory* ptr; long off; int count; rb_scan_args(argc, argv, "11", &offset, &countnum); off = NUM2LONG(offset); count = (countnum == Qnil ? 0 : NUM2INT(countnum)); retVal = rb_ary_new2(count); Data_Get_Struct(self, AbstractMemory, ptr); checkRead(ptr); if (countnum != Qnil) { int i; checkBounds(ptr, off, count * sizeof (char*)); for (i = 0; i < count; ++i) { const char* strptr = *((const char**) (ptr->address + off) + i); rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr))); } } else { checkBounds(ptr, off, sizeof (char*)); for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) { const char* strptr = *(const char**) (ptr->address + off); if (strptr == NULL) { break; } rb_ary_push(retVal, rb_tainted_str_new2(strptr)); } } return retVal; }
char* readFromClient(int sockfd) { const int toRead = 256; int bytesRead = 0; int bufSize = 256; int read = 0; char* retval = NULL; struct timeval timeo; fd_set readset; timeo.tv_sec = 5; /* Wait 5s */ timeo.tv_usec = 0; retval = (char*)malloc(bufSize*sizeof(char)); while(1) { FD_ZERO(&readset); FD_SET(sockfd, &readset); select(sockfd+1, &readset, NULL, NULL, &timeo); if(FD_ISSET(sockfd, &readset)) { read = recv(sockfd, retval+bytesRead, toRead, 0); if(read < 1) break; bytesRead += read; resizeBuffer(&retval, &bufSize, toRead, bytesRead); } else if(bytesRead == 0) { free(retval); return NULL; } else { retval[bytesRead] = '\0'; if(checkRead(retval)) break; /* Nothing to be read & valid ending - assume we go everything? */ } } return retval; }
bool InputMessage::decryptRsa(int size) { checkRead(size); g_crypt.rsaDecrypt((unsigned char*)m_buffer + m_readPos, size); return (getU8() == 0x00); }
/* * call-seq: put(pointer, value) * @param [AbstractMemory] pointer pointer on a {Struct} * @param [String, Array] value +value+ may be a String only if array's type is a kind of +int8+ * @return [value] * Set an array in a {Struct}. */ static VALUE array_field_put(VALUE self, VALUE pointer, VALUE value) { StructField* f; ArrayType* array; Data_Get_Struct(self, StructField, f); Data_Get_Struct(f->rbType, ArrayType, array); if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) { VALUE argv[2]; argv[0] = INT2FIX(f->offset); argv[1] = value; rb_funcall2(pointer, rb_intern("put_string"), 2, argv); } else { #ifdef notyet MemoryOp* op; int count = RARRAY_LEN(value); int i; AbstractMemory* memory = MEMORY(pointer); if (count > array->length) { rb_raise(rb_eIndexError, "array too large"); } /* clear the contents in case of a short write */ checkWrite(memory); checkBounds(memory, f->offset, f->type->ffiType->size); if (count < array->length) { memset(memory->address + f->offset + (count * array->componentType->ffiType->size), 0, (array->length - count) * array->componentType->ffiType->size); } /* now copy each element in */ if ((op = get_memory_op(array->componentType)) != NULL) { for (i = 0; i < count; ++i) { (*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i)); } } else if (array->componentType->nativeType == NATIVE_STRUCT) { for (i = 0; i < count; ++i) { VALUE entry = rb_ary_entry(value, i); Struct* s; if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) { rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct"); break; } Data_Get_Struct(entry, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size), s->pointer->address, array->componentType->ffiType->size); } } else { rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType)); } #else rb_raise(rb_eNotImpError, "cannot set array field"); #endif } return value; }
void Cluster::addRead(int read) { if (!checkRead(read)) { Cluster::reads.push_back(read); } }