当前位置: 首页>>代码示例>>C++>>正文


C++ remaining函数代码示例

本文整理汇总了C++中remaining函数的典型用法代码示例。如果您正苦于以下问题:C++ remaining函数的具体用法?C++ remaining怎么用?C++ remaining使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了remaining函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

	/// Writes the contents of \p buffer of \p size into the stream.
	ostringstream& ostringstream::write (const void* buffer, size_type sz)
	{
		const char* buf = (const char*) buffer;
		for (size_type bw = 0; (bw = minV(sz, remaining() ? remaining() : overflow(sz))); buf += bw, sz -= bw)
		ostream::write (buf, bw);
		return (*this);
	}
开发者ID:vijaykumarm108,项目名称:lolibc,代码行数:8,代码来源:ostringstream.cpp

示例2: CPPA_REQUIRE

void buffer::append_from(network::input_stream* istream) {
    CPPA_REQUIRE(remaining() > 0);
    auto num_bytes = istream->read_some(wr_ptr(), remaining());
    if (num_bytes > 0) {
        inc_size(num_bytes);
    }
}
开发者ID:alepharchives,项目名称:libcppa,代码行数:7,代码来源:buffer.cpp

示例3: remaining

/* find_http_req DATA LEN FOUND FOUNDLEN
 * Look for an HTTP request and response in buffer DATA of length LEN. The
 * return value is a pointer into DATA suitable for a subsequent call to this
 * function; *FOUND is either NULL, or a pointer to the start of an HTTP
 * request; in the latter case, *FOUNDLEN is the length of the match
 * containing enough information to obtain the URL. */
unsigned char *find_http_req(const unsigned char *data, const size_t len, unsigned char **http, size_t *httplen) {
    unsigned char *req, *le, *blankline, *hosthdr;
    
#define remaining(x)    (len - (data - (x)))
#define MAX_REQ         16384
    
    /* HTTP requests look like:
     *
     *      GET {path} HTTP/1.(0|1)\r\n
     *      header: value\r\n
     *          ...
     *      \r\n
     *
     * We may care about the Host: header in the request. */
    if (len < 40)
        return (unsigned char*)data;
    
    if (!(req = memstr(data, len, (unsigned char*) "GET ", 4)))
        return (unsigned char*)(data + len - 4);

    /* Find the end of the request line. */
    if (!(le = memstr(req + 4, remaining(req + 4), (unsigned char*) "\r\n", 2))) {
        if (remaining(req + 4) > MAX_REQ)
            return (unsigned char*)(req + 4);
        else
            return (unsigned char*)req;
    }

    /* Not enough space for a path. */
    if (le < req + 5)
        return le + 2;

    /* Not an HTTP request, just a line starting GET.... */
    if (memcmp(le - 9, " HTTP/1.", 8) || !strchr("01", (int)*(le - 1)))
        return le + 2;

    /* Find the end of the request headers. */
    if (!(blankline = memstr(le + 2, remaining(le + 2), (unsigned char*) "\r\n\r\n", 4))) {
        if (remaining(le + 2) > MAX_REQ)
            return (unsigned char*)(data + len - 4);
        else
            return req;
    }

    if (memcmp(req + 4, "http://", 7) == 0)
        /* Probably a cache request; in any case, don't need to look for a Host:. */
        goto found;

    /* Is there a Host: header? */
    if (!(hosthdr = memstr(le, blankline - le + 2, (unsigned char*) "\r\nHost: ", 8))) {
        return blankline + 4;
    }

found:
    
    *http = req;
    *httplen = blankline - req;

    return blankline + 4;
}
开发者ID:achudars,项目名称:driftnet,代码行数:66,代码来源:http.c

示例4: read

    void read(void * data, const std::size_t & len)
    {
        if (file_)
        {
            if (file_->read(reinterpret_cast<char *>(data), len))
            {
                file_offset_ += len;

                file_->seek_set(file_offset_);
            }
            else
            {
                assert(0);
            }
        }
        else
        {
            if (remaining() < len)
            {
                throw std::runtime_error(
                    "buffer underrun, len = " + std::to_string(len) +
                    ", remaining = " + std::to_string(remaining())
                );
            }

            if (m_read_ptr == 0)
            {
                m_read_ptr = &m_data[0];
            }

            std::memcpy(data, m_read_ptr, len);

            m_read_ptr += len;
        }
    }
开发者ID:VNLtools,项目名称:coinpp,代码行数:35,代码来源:data_buffer.hpp

示例5: remaining

size_t UpdaterClass::write(uint8_t *data, size_t len) {
  size_t left = len;
  if(hasError() || !isRunning())
    return 0;

  if(len > remaining())
    len = remaining();

  while((_bufferLen + left) > FLASH_SECTOR_SIZE) {
    size_t toBuff = FLASH_SECTOR_SIZE - _bufferLen;
    memcpy(_buffer + _bufferLen, data + (len - left), toBuff);
    _bufferLen += toBuff;
    if(!_writeBuffer()){
      return len - left;
    }
    left -= toBuff;
    yield();
  }
  //lets see whats left
  memcpy(_buffer + _bufferLen, data + (len - left), left);
  _bufferLen += left;
  if(_bufferLen == remaining()){
    //we are at the end of the update, so should write what's left to flash
    if(!_writeBuffer()){
      return len - left;
    }
  }
  return len;
}
开发者ID:Nimajamin,项目名称:Arduino,代码行数:29,代码来源:Updater.cpp

示例6: while

size_t UpdaterClass::writeStream(Stream &data) {
  size_t written = 0;
  size_t toRead = 0;
  if(hasError() || !isRunning())
    return 0;

  while(remaining()) {
    toRead = FLASH_SECTOR_SIZE - _bufferLen;
    toRead = data.readBytes(_buffer + _bufferLen, toRead);
    if(toRead == 0){ //Timeout
      _error = UPDATE_ERROR_STREAM;
      _currentAddress = (_startAddress + _size);
#ifdef DEBUG_UPDATER
      printError(DEBUG_UPDATER);
#endif
      return written;
    }
    _bufferLen += toRead;
    if((_bufferLen == remaining() || _bufferLen == FLASH_SECTOR_SIZE) && !_writeBuffer())
      return written;
    written += toRead;
    yield();
  }
  return written;
}
开发者ID:Nimajamin,项目名称:Arduino,代码行数:25,代码来源:Updater.cpp

示例7: getn

 virtual unsigned getn(void *dst, unsigned n)
 {
     if (!compressed)
         return getBytes(dst, size*n)/size;
     byte *d = (byte *)dst;
     byte *e = d+(size*n);
     byte *p = (byte *)prev;
     unsigned ret = 0;
     while (d!=e) {
         if (first) {
             if (getBytes(d, size)!=size)
                 break;
             first = false;
         }
         else {
             if (remaining()<maxcompsize) 
                 refill();
             if (remaining()==0)
                 break;
             ptr += DiffExpand(ptr,d,p,size);
         }
         p = d;
         d += size;
         ret++;
     }
     if (ret)    // we got at least 1 so copy to prev
         memcpy(prev,e-size,size);
     return ret;
 }
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:29,代码来源:jio.cpp

示例8: GetUsage

int DumpPacketCommand::Execute() {
  if (remaining().empty()) {
    cout << GetUsage() << GetHelp() << endl;
    return 2;
  }
  const string filename(remaining().front());
  return dump_file(filename);
}
开发者ID:TRI0N,项目名称:wwiv,代码行数:8,代码来源:dump_packet.cpp

示例9: return

/// Called when more buffer space (\p n bytes) is needed.
ofstream::size_type ofstream::overflow (size_type n)
{
    if (eof() || (n > remaining() && n < capacity() - pos()))
	return (ostringstream::overflow (n));
    size_type bw = m_File.write (cdata(), pos());
    clear (m_File.rdstate());
    erase (begin(), bw);
    if (remaining() < n)
	ostringstream::overflow (n);
    return (remaining());
}
开发者ID:Andproject,项目名称:platform_frameworks_base,代码行数:12,代码来源:ofstream.cpp

示例10: oldPos

/// Attempts to create more output space. Returns remaining().
ostringstream::size_type ostringstream::overflow (size_type n)
{
    if (n > remaining()) {
	const uoff_t oldPos (pos());
	m_Buffer.reserve (oldPos + n, false);
	m_Buffer.resize (oldPos + n);
	ostream::link (m_Buffer);
	SetPos (oldPos);
    }
    verify_remaining ("write", "text", n);
    return (remaining());
}
开发者ID:embarkmobile,项目名称:ustl-symbian,代码行数:13,代码来源:sostream.cpp

示例11: remaining

void StringBuffer::append(const TCHAR *pStr, int len)
{
	if(!pStr || !len)return;
	int rem = remaining();
	while(len >= rem)
	{
		expandBuffer(len + 16 - rem);
		rem = remaining();
	}
	TCHAR *pTail = m_pStr + m_strLen;
	CopyMemory(pTail, pStr, len * sizeof(TCHAR));
	m_strLen += len;
}
开发者ID:jaylauffer,项目名称:loadngo,代码行数:13,代码来源:StringBuffer.cpp

示例12: memcpy

long CharStringBuffer::append(const char* s, unsigned long n) {

	if ( n <= remaining() ) {
		memcpy(&contents[fill_point_marker], s, n);
		fill_point_marker += n;
		return n;
	} else {
		unsigned int num_to_copy = remaining();
		memcpy(&contents[fill_point_marker], s, num_to_copy);
		fill_point_marker += num_to_copy;
		return num_to_copy;
	}
}
开发者ID:JdeRobot,项目名称:ThirdParty,代码行数:13,代码来源:character_buffer.cpp

示例13: remaining

    bool buffer_writer::write(const char * ptr, uint32 n)
    {
        bool allWritten = true;
        if (n > remaining())
        {
            allWritten = false;
            n = remaining();
        }

        std::memcpy(_ptr+_iter, ptr, n*sizeof(char));
        _iter += n;

        return allWritten;
    }
开发者ID:karhu,项目名称:arc-project,代码行数:14,代码来源:buffer_writer.cpp

示例14: remaining

	cc7::ByteRange TestFile::readMemory(size_t size)
	{
		size = std::min(size, remaining());
		ByteRange range = _resource->range().subRange(_offset, size);
		_offset += size;
		return range;
	}
开发者ID:hvge,项目名称:cc7,代码行数:7,代码来源:TestFile.cpp

示例15: getSockets

void ThriftServer::stopListening() {
  auto sockets = getSockets();
  std::atomic<size_t> remaining(1 + sockets.size());
  folly::Baton<> done;

  auto defer_wait = folly::makeGuard([&] { done.wait(); });
  auto maybe_post = [&] { --remaining ? void() : done.post(); };
  maybe_post();
  for (auto& socket : sockets) {
    // Stop accepting new connections
    auto eb = socket->getEventBase();
    eb->runInEventBaseThread(
        [socket = std::move(socket), g = folly::makeGuard(maybe_post)] {
          socket->pauseAccepting();

          // Close the listening socket
          // This will also cause the workers to stop
          socket->stopAccepting();
        });
  }

  if (stopWorkersOnStopListening_) {
    // Wait for any tasks currently running on the task queue workers to
    // finish, then stop the task queue workers. Have to do this now, so
    // there aren't tasks completing and trying to write to i/o thread
    // workers after we've stopped the i/o workers.
    threadManager_->join();
  }
}
开发者ID:facebook,项目名称:fbthrift,代码行数:29,代码来源:ThriftServer.cpp


注:本文中的remaining函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。