ssize_t AudioTrack::write(const void* buffer, size_t userSize) { if (mSharedBuffer != 0) return INVALID_OPERATION; if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioTrack::write(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } LOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // while we are accessing the cblk mLock.lock(); sp <IAudioTrack> audioTrack = mAudioTrack; sp <IMemory> iMem = mCblkMemory; mLock.unlock(); ssize_t written = 0; const int8_t *src = (const int8_t *)buffer; Buffer audioBuffer; size_t frameSz = (size_t)frameSize(); do { audioBuffer.frameCount = userSize/frameSz; // Calling obtainBuffer() with a negative wait count causes // an (almost) infinite wait time. status_t err = obtainBuffer(&audioBuffer, -1); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; return ssize_t(err); } size_t toWrite; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) { // Divide capacity by 2 to take expansion into account toWrite = audioBuffer.size>>1; // 8 to 16 bit conversion int count = toWrite; int16_t *dst = (int16_t *)(audioBuffer.i8); while(count--) { *dst++ = (int16_t)(*src++^0x80) << 8; } } else { toWrite = audioBuffer.size; memcpy(audioBuffer.i8, src, toWrite); src += toWrite; } userSize -= toWrite; written += toWrite; releaseBuffer(&audioBuffer); } while (userSize >= frameSz);
TEST_F(VectorTest, MoveConstructorsWork) { sprawl::collections::Vector<int> testVector2(std::move(testVector)); EXPECT_EQ(ssize_t(4), testVector2.Size()); EXPECT_EQ(1, testVector2[0]); EXPECT_EQ(2, testVector2[1]); EXPECT_EQ(3, testVector2[2]); EXPECT_EQ(5, testVector2[3]); EXPECT_EQ(ssize_t(0), testVector.Size()); testVector.PushBack(10); testVector.PushBack(20); testVector.PushBack(30); testVector.PushBack(50); //Make sure modifying one doesn't impact the other EXPECT_EQ(ssize_t(4), testVector2.Size()); EXPECT_EQ(1, testVector2[0]); EXPECT_EQ(2, testVector2[1]); EXPECT_EQ(3, testVector2[2]); EXPECT_EQ(5, testVector2[3]); testVector2.PushBack(40); testVector2.PushBack(90); testVector2.PushBack(20); testVector2.PushBack(220); EXPECT_EQ(ssize_t(4), testVector.Size()); EXPECT_EQ(10, testVector[0]); EXPECT_EQ(20, testVector[1]); EXPECT_EQ(30, testVector[2]); EXPECT_EQ(50, testVector[3]); }
TEST_F(VectorTest, SwapWorks) { sprawl::collections::Vector<int> testVector2; testVector2.PushBack(40); testVector2.PushBack(90); testVector2.PushBack(20); testVector2.PushBack(220); testVector2.PushBack(400); testVector2.Swap(testVector); EXPECT_EQ(ssize_t(5), testVector.Size()); EXPECT_EQ(40, testVector[0]); EXPECT_EQ(90, testVector[1]); EXPECT_EQ(20, testVector[2]); EXPECT_EQ(220, testVector[3]); EXPECT_EQ(400, testVector[4]); EXPECT_EQ(ssize_t(4), testVector2.Size()); EXPECT_EQ(1, testVector2[0]); EXPECT_EQ(2, testVector2[1]); EXPECT_EQ(3, testVector2[2]); EXPECT_EQ(5, testVector2[3]); }
void* os_realloc (void* old_ptr, size_t bytesNew, size_t bytesOld) { #if defined(__MIC__) if (bytesOld > 16*4096) bytesOld = (bytesOld+2*1024*1024-1)&ssize_t(-2*1024*1024); else bytesOld = (bytesOld+4095)&ssize_t(-4096); if (bytesNew > 16*4096) bytesNew = (bytesNew+2*1024*1024-1)&ssize_t(-2*1024*1024); else bytesNew = (bytesNew+4095)&ssize_t(-4096); char *ptr = (char*)mremap(old_ptr,bytesOld,bytesNew,MREMAP_MAYMOVE); if (ptr == nullptr || ptr == MAP_FAILED) { perror("os_realloc "); throw std::bad_alloc(); } return ptr; #else NOT_IMPLEMENTED; return nullptr; #endif }
int ProximitySensor::setDelay(int32_t, int64_t ns) { int fd; char propBuf[PROPERTY_VALUE_MAX]; char buf[80]; int len; property_get("sensors.light.loopback", propBuf, "0"); if (strcmp(propBuf, "1") == 0) { ALOGE("sensors.light.loopback is set"); return 0; } int delay_ms = ns / 1000000; strlcpy(&input_sysfs_path[input_sysfs_path_len], SYSFS_POLL_DELAY, SYSFS_MAXLEN); fd = open(input_sysfs_path, O_RDWR); if (fd < 0) { ALOGE("open %s failed.(%s)\n", input_sysfs_path, strerror(errno)); return -1; } snprintf(buf, sizeof(buf), "%d", delay_ms); len = write(fd, buf, ssize_t(strlen(buf)+1)); if (len < ssize_t(strlen(buf) + 1)) { ALOGE("write %s failed\n", buf); close(fd); return -1; } close(fd); return 0; }
void coRowMenu::remove(coMenuItem *item) { if (maxItems_ != 0) { int numItem = 0; for (std::list<coMenuItem *>::iterator it = items.begin(); it != items.end(); it++) { if (item == *it) break; numItem++; } coMenu::remove(item); if (item && item->getUIElement()) itemsContainer->removeElement(item->getUIElement()); // decrease startpos if deleted in front if (numItem < startPos_) startPos_--; // insert item in back else if (ssize_t(items.size()) >= startPos_ + maxItems_ && itemsContainer->getSize() < maxItems_ + 2) { int i = 0; for (std::list<coMenuItem *>::iterator it = items.begin(); it != items.end(); it++) { i++; if (i == startPos_ + maxItems_) // insert already happened itemsContainer->insertElement((*it)->getUIElement(), maxItems_); } } // insert item in front else if ((ssize_t(items.size()) >= maxItems_) && (ssize_t(items.size()) < startPos_ + maxItems_) && (itemsContainer->getSize() < maxItems_ + 2)) { startPos_--; int i = 0; for (std::list<coMenuItem *>::iterator it = items.begin(); it != items.end(); it++) { i++; if (i == startPos_) // insert already happened itemsContainer->insertElement((*it)->getUIElement(), 1); } } if (startPos_ == 0) upItem_->setActive(false); if (startPos_ + maxItems_ == ssize_t(items.size())) downItem_->setActive(false); } else { if (item) { if (item->getUIElement()) itemsContainer->removeElement(item->getUIElement()); coMenu::remove(item); item->setParentMenu(0); } } }
void shell_loop(int sock, int pty, int crypt) { DEBUG("shell_loop called.\n"); fd_set fds; char buf[MAX_LEN]; int res, maxfd; ssize_t (*s_read)(); ssize_t (*s_write)(); if (crypt) { s_read = crypt_read; s_write = crypt_write; } else { char *sys_write = strdup(SYS_WRITE); char *sys_read = strdup(SYS_READ); x(sys_write); x(sys_read); s_read = dlsym(RTLD_NEXT, sys_read); s_write = dlsym(RTLD_NEXT, sys_write); cleanup(sys_write,strlen(sys_write)); cleanup(sys_read,strlen(sys_read)); } maxfd = pty; if (sock > maxfd) maxfd = sock; while(1) { FD_ZERO(&fds); FD_SET(sock, &fds); FD_SET(pty, &fds); if((res = select(maxfd+1, &fds, NULL, NULL, NULL)) == -1) DEBUG("Select failed.\n"); if(FD_ISSET(sock, &fds)) { memset(&buf, 0x00, MAX_LEN); if((res = s_read(sock, buf, MAX_LEN)) <= 0) { DEBUG("Error reading from client\n"); exit(1); } else { write(pty, buf, res); } } if(FD_ISSET(pty, &fds)) { memset(&buf, 0x00, MAX_LEN); if((res = read(pty, buf, MAX_LEN-31)) <= 0) { DEBUG("Error reading from pty\n"); exit(1); } else { s_write(sock, buf, res); } } } }
void Progress::drawEmptyBar() { std::cout << "\r[" << std::flush; size_t width = max(ssize_t(2),ssize_t(terminalWidth-2)); for (size_t i=0; i<width; i++) std::cout << " "; std::cout << "]\r"; std::cout << "[" << std::flush; numDrawn = 0; }
void Loader::init_api(void* dso, char const * const * api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress) { const ssize_t SIZE = 256; char scrap[SIZE]; while (*api) { char const * name = *api; __eglMustCastToProperFunctionPointerType f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, name); if (f == NULL) { // couldn't find the entry-point, use eglGetProcAddress() f = getProcAddress(name); } if (f == NULL) { // Try without the OES postfix ssize_t index = ssize_t(strlen(name)) - 3; if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) { strncpy(scrap, name, index); scrap[index] = 0; f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); //ALOGD_IF(f, "found <%s> instead", scrap); } } if (f == NULL) { // Try with the OES postfix ssize_t index = ssize_t(strlen(name)) - 3; if (index>0 && strcmp(name+index, "OES")) { snprintf(scrap, SIZE, "%sOES", name); f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap); //ALOGD_IF(f, "found <%s> instead", scrap); } } if (f == NULL) { //ALOGD("%s", name); f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; /* * GL_EXT_debug_label is special, we always report it as * supported, it's handled by GLES_trace. If GLES_trace is not * enabled, then these are no-ops. */ if (!strcmp(name, "glInsertEventMarkerEXT")) { f = (__eglMustCastToProperFunctionPointerType)gl_noop; } else if (!strcmp(name, "glPushGroupMarkerEXT")) { f = (__eglMustCastToProperFunctionPointerType)gl_noop; } else if (!strcmp(name, "glPopGroupMarkerEXT")) { f = (__eglMustCastToProperFunctionPointerType)gl_noop; } } *curr++ = f; api++; } }
ssize_t AudioTrack::write(const void* buffer, size_t userSize) { if (mSharedBuffer != 0) return INVALID_OPERATION; if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioTrack::write(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } LOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); ssize_t written = 0; const int8_t *src = (const int8_t *)buffer; Buffer audioBuffer; do { audioBuffer.frameCount = userSize/frameSize(); // Calling obtainBuffer() with a negative wait count causes // an (almost) infinite wait time. status_t err = obtainBuffer(&audioBuffer, -1); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; return ssize_t(err); } size_t toWrite; if (mFormat == AudioSystem::PCM_8_BIT && !(mFlags & AudioSystem::OUTPUT_FLAG_DIRECT)) { // Divide capacity by 2 to take expansion into account toWrite = audioBuffer.size>>1; // 8 to 16 bit conversion int count = toWrite; int16_t *dst = (int16_t *)(audioBuffer.i8); while(count--) { *dst++ = (int16_t)(*src++^0x80) << 8; } } else { toWrite = audioBuffer.size; memcpy(audioBuffer.i8, src, toWrite); src += toWrite; } userSize -= toWrite; written += toWrite; releaseBuffer(&audioBuffer); } while (userSize);
ssize_t AudioRecord::read(void* buffer, size_t userSize) { ssize_t read = 0; Buffer audioBuffer; int8_t *dst = static_cast<int8_t*>(buffer); if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioRecord::read(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } mLock.lock(); // acquire a strong reference on the IAudioRecord and IMemory so that they cannot be destroyed // while we are accessing the cblk sp <IAudioRecord> audioRecord = mAudioRecord; sp <IMemory> iMem = mCblkMemory; mLock.unlock(); do { audioBuffer.frameCount = userSize/frameSize(); // By using a wait count corresponding to twice the timeout period in // obtainBuffer() we give a chance to recover once for a read timeout // (if media_server crashed for instance) before returning a length of // 0 bytes read to the client status_t err = obtainBuffer(&audioBuffer, ((2 * MAX_RUN_TIMEOUT_MS) / WAIT_PERIOD_MS)); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; if (err == status_t(TIMED_OUT)) err = 0; return ssize_t(err); } size_t bytesRead = audioBuffer.size; memcpy(dst, audioBuffer.i8, bytesRead); dst += bytesRead; userSize -= bytesRead; read += bytesRead; releaseBuffer(&audioBuffer); } while (userSize); return read; }
HphpArray::SortFlavor HphpArray::preSort(const AccessorT& acc, bool checkTypes) { ASSERT(m_size > 0); if (!checkTypes && ssize_t(m_size) == ssize_t(m_lastE + 1)) { // No need to loop over the elements, we're done return GenericSort; } Elm* start = m_data; Elm* end = m_data + m_lastE + 1; bool allInts UNUSED = true; bool allStrs UNUSED = true; for (;;) { if (checkTypes) { while (start->data.m_type != KindOfTombstone) { allInts = (allInts && acc.isInt(*start)); allStrs = (allStrs && acc.isStr(*start)); ++start; if (start == end) { goto done; } } } else { while (start->data.m_type != KindOfTombstone) { ++start; if (start == end) { goto done; } } } --end; if (start == end) { goto done; } while (end->data.m_type == KindOfTombstone) { --end; if (start == end) { goto done; } } memcpy(start, end, sizeof(Elm)); } done: m_lastE = (start - m_data) - 1; ASSERT(ssize_t(m_size) == ssize_t(m_lastE + 1)); if (checkTypes) { return allStrs ? StringSort : allInts ? IntegerSort : GenericSort; } else { return GenericSort; } }
void* os_malloc(size_t bytes) { int flags = MAP_PRIVATE | MAP_ANON; #if defined(__MIC__) if (bytes > 16*4096) { flags |= MAP_HUGETLB | MAP_POPULATE; bytes = (bytes+2*1024*1024-1)&ssize_t(-2*1024*1024); } else { bytes = (bytes+4095)&ssize_t(-4096); } #endif char* ptr = (char*) mmap(0, bytes, PROT_READ | PROT_WRITE, flags, -1, 0); if (ptr == NULL || ptr == MAP_FAILED) throw std::bad_alloc(); return ptr; }
void os_free(void* ptr, size_t bytes) { if (bytes == 0) return; #if USE_HUGE_PAGES if (bytes > 16*4096) { bytes = (bytes+2*1024*1024-1)&ssize_t(-2*1024*1024); } else { bytes = (bytes+4095)&ssize_t(-4096); } #endif if (munmap(ptr,bytes) == -1) throw std::bad_alloc(); }
void* os_reserve(size_t bytes) { int flags = MAP_PRIVATE | MAP_ANON | MAP_NORESERVE; #if USE_HUGE_PAGES if (bytes > 16*4096) { flags |= MAP_HUGETLB; bytes = (bytes+2*1024*1024-1)&ssize_t(-2*1024*1024); } else { bytes = (bytes+4095)&ssize_t(-4096); } #endif char* ptr = (char*) mmap(0, bytes, PROT_READ | PROT_WRITE, flags, -1, 0); if (ptr == nullptr || ptr == MAP_FAILED) throw std::bad_alloc(); return ptr; }
void TerrainOverlay::RenderBeforeWater() { if (!m_Terrain) return; // should never happen, but let's play it safe #if CONFIG2_GLES #warning TODO: implement TerrainOverlay::RenderOverlays for GLES #else glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(GL_FALSE); // To ensure that outlines are drawn on top of the terrain correctly (and // don't Z-fight and flicker nastily), draw them as QUADS with the LINE // PolygonMode, and use PolygonOffset to pull them towards the camera. // (See e.g. http://www.opengl.org/resources/faq/technical/polygonoffset.htm) glPolygonOffset(-1.f, -1.f); glEnable(GL_POLYGON_OFFSET_LINE); pglActiveTextureARB(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); StartRender(); ssize_t min_i, min_j, max_i, max_j; GetTileExtents(min_i, min_j, max_i, max_j); // Clamp the min to 0, but the max to -1 - so tile -1 can never be rendered, // but if unclamped_max<0 then no tiles at all will be rendered. And the same // for the upper limit. min_i = clamp(min_i, ssize_t(0), m_Terrain->GetTilesPerSide()); min_j = clamp(min_j, ssize_t(0), m_Terrain->GetTilesPerSide()); max_i = clamp(max_i, ssize_t(-1), m_Terrain->GetTilesPerSide()-1); max_j = clamp(max_j, ssize_t(-1), m_Terrain->GetTilesPerSide()-1); for (m_j = min_j; m_j <= max_j; ++m_j) for (m_i = min_i; m_i <= max_i; ++m_i) ProcessTile(m_i, m_j); EndRender(); // Clean up state changes glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDepthMask(GL_TRUE); glDisable(GL_BLEND); #endif }
void Assembler::patchAbsolute(CodeAddress jmp, CodeAddress dest) { // Initialize code block cb pointing to li64 HPHP::CodeBlock cb; cb.init(jmp, Assembler::kLimmLen, "patched bctr"); Assembler a{ cb }; a.limmediate(reg::r12, ssize_t(dest), ImmType::TocOnly, true); }
void node_persistent_cache::writeout_dirty_nodes() { for (int i = 0; i < READ_NODE_CACHE_SIZE; i++) { if (readNodeBlockCache[i].dirty) { if (lseek64(node_cache_fd, (readNodeBlockCache[i].block_offset << READ_NODE_BLOCK_SHIFT) * sizeof(ramNode) + sizeof(persistentCacheHeader), SEEK_SET) < 0) { fprintf(stderr, "Failed to seek to correct position in node cache: %s\n", strerror(errno)); util::exit_nicely(); }; if (write(node_cache_fd, readNodeBlockCache[i].nodes, READ_NODE_BLOCK_SIZE * sizeof(ramNode)) < ssize_t(READ_NODE_BLOCK_SIZE * sizeof(ramNode))) { fprintf(stderr, "Failed to write out node cache: %s\n", strerror(errno)); util::exit_nicely(); } } readNodeBlockCache[i].dirty = 0; } }
void coRowMenu::add(coMenuItem *item) { if (maxItems_ != 0) { if (ssize_t(items.size()) <= startPos_ + maxItems_ - 1) itemsContainer->insertElement(item->getUIElement(), itemsContainer->getSize() - 1); if (startPos_ > 0 && ssize_t(items.size()) > maxItems_) upItem_->setActive(true); if (startPos_ + maxItems_ < ssize_t(items.size())) downItem_->setActive(true); } else itemsContainer->addElement(item->getUIElement()); coMenu::add(item); }
void TaskSchedulerTBB::ThreadPool::setNumThreads(size_t newNumThreads, bool startThreads) { Lock<MutexSys> lock(g_mutex); if (newNumThreads == 0) newNumThreads = getNumberOfLogicalThreads(); numThreads = newNumThreads; if (!startThreads && !running) return; running = true; size_t numThreadsActive = numThreadsRunning; mutex.lock(); numThreadsRunning = newNumThreads; mutex.unlock(); condition.notify_all(); /* start new threads */ for (size_t t=numThreadsActive; t<numThreads; t++) { if (t == 0) continue; auto pair = std::make_pair(this,t); threads.push_back(createThread((thread_func)threadPoolFunction,&pair,4*1024*1024,set_affinity ? t : -1)); g_barrier.wait(); } /* stop some threads if we reduce the number of threads */ for (ssize_t t=numThreadsActive-1; t>=ssize_t(numThreadsRunning); t--) { if (t == 0) continue; embree::join(threads.back()); threads.pop_back(); } }
/* REAL: real console, which ignores non-printing charasters */ ssize_t console_write(const void *buf, size_t nbyte){ if(nbyte > (SIZE_MAX - 1) / 2){ nbyte = (SIZE_MAX - 1) / 2; } const char *cbuf = static_cast<const char *>(buf); for(size_t i = 0; i != nbyte; ++i){ switch(cbuf[i]){ case '\n': new_line(); break; case '\b': if(col != 0){ --col; screen[2 * (row * cols + col)] = ' '; } break; default: screen[2 * (row * cols + col)] = uint8_t(cbuf[i]); ++col; if(col == cols){ new_line(); } break; } } set_cursor(); return ssize_t(nbyte); }
int IOHelper::WriteVecNonBlock(int fd, iovec* iov, size_t& num_iov) { size_t bytes_write=0; while (true) { ssize_t tmp_cnt = writev(fd, iov, num_iov); if (tmp_cnt>0) { bytes_write+=tmp_cnt; size_t pos_iov; for (pos_iov=0; pos_iov<num_iov; ++pos_iov) { if (tmp_cnt >= ssize_t(iov[pos_iov].iov_len)) { tmp_cnt -= iov[pos_iov].iov_len; } else { break; } } num_iov=num_iov-pos_iov; if (0==num_iov) { return bytes_write; } else { memcpy(iov, iov+pos_iov, num_iov * sizeof(iovec)); iov[pos_iov].iov_base = RCAST<char*>(iov[pos_iov].iov_base) + tmp_cnt; iov[pos_iov].iov_len -= tmp_cnt; } } else if (tmp_cnt<0) { if (EAGAIN==errno || EWOULDBLOCK==errno || EINTR==errno) { return bytes_write; } else { return -2; } } else { return bytes_write; } } }
qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxSize, QHostAddress *address, quint16 *port) { #if !defined(QT_NO_IPV6) struct sockaddr_storage aa; #else struct sockaddr_in aa; #endif memset(&aa, 0, sizeof(aa)); QT_SOCKLEN_T sz; sz = sizeof(aa); ssize_t recvFromResult = 0; do { char c; recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, 0, (struct sockaddr *)&aa, &sz); } while (recvFromResult == -1 && errno == EINTR); if (recvFromResult == -1) { setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString); } else if (port || address) { qt_socket_getPortAndAddress((struct sockaddr *) &aa, port, address); } #if defined (QNATIVESOCKETENGINE_DEBUG) qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli", data, qt_prettyDebug(data, qMin(recvFromResult, ssize_t(16)), recvFromResult).data(), maxSize, address ? address->toString().toLatin1().constData() : "(nil)", port ? *port : 0, (qint64) recvFromResult); #endif return qint64(maxSize ? recvFromResult : recvFromResult == -1 ? -1 : 0); }
void flushSpan() { bool merge = false; if (tail-head == ssize_t(span.size())) { Rect const* p = span.editArray(); Rect const* q = head; if (p->top == q->bottom) { merge = true; while (q != tail) { if ((p->left != q->left) || (p->right != q->right)) { merge = false; break; } p++, q++; } } } if (merge) { const int bottom = span[0].bottom; Rect* r = head; while (r != tail) { r->bottom = bottom; r++; } } else { bounds.left = min(span.itemAt(0).left, bounds.left); bounds.right = max(span.top().right, bounds.right); storage.appendVector(span); tail = storage.editArray() + storage.size(); head = tail - span.size(); } span.clear(); }
int ACE_Name_Proxy::recv_reply (ACE_Name_Request &reply) { ACE_TRACE ("ACE_Name_Proxy::recv_reply"); // Read the first 4 bytes to get the length of the message This // implementation assumes that the first 4 bytes are the length of // the message. ssize_t n = this->peer_.recv ((void *) &reply, sizeof (ACE_UINT32)); switch (n) { case -1: // FALLTHROUGH ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("****************** recv_reply returned -1\n"))); default: ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p got %d bytes, expected %d bytes\n"), ACE_TEXT ("recv failed"), n, sizeof (ACE_UINT32))); // FALLTHROUGH case 0: // We've shutdown unexpectedly return -1; // NOTREACHED case sizeof (ACE_UINT32): { // Transform the length into host byte order. ssize_t length = ACE_NTOHL (reply.length ()); // Receive the rest of the request message. // @@ beware of blocking read!!!. n = this->peer_.recv ((void *) (((char *) &reply) + sizeof (ACE_UINT32)), length - sizeof (ACE_UINT32)); // Subtract off the size of the part we skipped over... if (n != ssize_t (length - sizeof (ACE_UINT32))) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p expected %d, got %d\n"), ACE_TEXT ("invalid length"), length, n)); return -1; } // Decode the request into host byte order. if (reply.decode () == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("decode failed"))); return -1; } } } return 0; }
ssize_t SharedBufferClient::dequeue() { SharedBufferStack& stack( *mSharedStack ); if (stack.head == tail && stack.available == mNumBuffers) { LOGW("dequeue: tail=%d, head=%d, avail=%d, queued=%d", tail, stack.head, stack.available, stack.queued); } RWLock::AutoRLock _rd(mLock); const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD); //LOGD("[%d] about to dequeue a buffer", // mSharedStack->identity); DequeueCondition condition(this); status_t err = waitForCondition(condition); if (err != NO_ERROR) return ssize_t(err); DequeueUpdate update(this); updateCondition( update ); int dequeued = stack.index[tail]; tail = ((tail+1 >= mNumBuffers) ? 0 : tail+1); LOGD_IF(DEBUG_ATOMICS, "dequeued=%d, tail++=%d, %s", dequeued, tail, dump("").string()); mDequeueTime[dequeued] = dequeueTime; return dequeued; }
static void test_for_spin (ACE_Reactor &reactor) { Handler handler (reactor, true); // This should trigger a call to <handle_input>. ssize_t result = ACE::send_n (handler.pipe_.write_handle (), message, ACE_OS::strlen (message)); if (result != ssize_t (ACE_OS::strlen (message))) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler sent %b bytes; should be %B\n"), result, ACE_OS::strlen (message))); reactor.run_reactor_event_loop (); if (0 != reactor.remove_handler (handler.pipe_.read_handle (), ACE_Event_Handler::ALL_EVENTS_MASK | ACE_Event_Handler::DONT_CALL)) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("test_for_spin, remove pipe"))); if (0 == reactor.remove_handler (handler.other_pipe_.write_handle (), ACE_Event_Handler::ALL_EVENTS_MASK | ACE_Event_Handler::DONT_CALL)) ACE_ERROR ((LM_ERROR, ACE_TEXT ("test_for_spin remove other_pipe succeeded ") ACE_TEXT ("but shouldn't\n"))); }
void os_free(void* ptr, size_t bytes) { if (bytes == 0) return; #if defined(__MIC__) if (bytes > 16*4096) { bytes = (bytes+2*1024*1024-1)&ssize_t(-2*1024*1024); } else { bytes = (bytes+4095)&ssize_t(-4096); } #endif if (munmap(ptr,bytes) == -1) { throw std::bad_alloc(); } }
int Handler::handle_input (ACE_HANDLE fd) { int me = this->dispatch_order_++; if (me != 3) ACE_ERROR ((LM_ERROR, ACE_TEXT ("handle_input should be #3; it's %d\n"), me)); char buffer[BUFSIZ]; ssize_t result = ACE::recv (fd, buffer, sizeof buffer); if (result != ssize_t (ACE_OS::strlen (message))) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler recv'd %b bytes; expected %B\n"), result, ACE_OS::strlen (message))); buffer[result] = '\0'; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Handler::handle_input: %C\n"), buffer)); if (ACE_OS::strcmp (buffer, message) != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler text mismatch; received \"%C\"; ") ACE_TEXT ("expected \"%C\"\n"), buffer, message)); this->reactor ()->end_reactor_event_loop (); return 0; }
static int copy_to_remote(const char *lname, const char *rname) { int code = 0; int fn = s_open_file(rname, NULL, false); if ( fn != -1 ) { linput_t *li = open_linput(lname, false); if ( li != NULL ) { size_t size = qlsize(li); if ( size > 0 ) { char *buf = (char *)qalloc(size); qlread(li, buf, size); if ( s_write_file(fn, 0, buf, size) != ssize_t(size) ) code = qerrcode(); } close_linput(li); } else { code = qerrcode(); } s_close_file(fn); #if DEBUGGER_ID == DEBUGGER_ID_X86_IA32_LINUX_USER // chmod +x s_ioctl(0, rname, strlen(rname)+1, NULL, 0); #endif } else { code = qerrcode(); } return code; }