Пример #1
0
	/**
		Put bit at put pointer.

		\param[out] b Current bit.
		\return Whether okay (eof has not been encountered).
	*/
	bool sputb(bitfield b)
	{
		// Note: This is an optimization of "return sputn(bitfield, 1) == 1;"

		bool put_succeeded = true;

		if (pptr() == std::streampos(-1) || pptr() == epptr())
		{
			put_succeeded = overflow(b);
		}
		else
		{
			const size_t intra_byte_bit_offset = pptr() % CHAR_BIT;
			const size_t shift_amount = (CHAR_BIT - ((1 + intra_byte_bit_offset) % CHAR_BIT)) % CHAR_BIT;
			const unsigned char mask = ~(1 << shift_amount);
			unsigned char * const byte_pointer = current_put_byte();
			*byte_pointer = *byte_pointer & mask | (b & 1) << shift_amount;

			pbump(1);
		}

		return put_succeeded;
	}
Пример #2
0
   int
   mlpipebuf::buffer_out()
   {
#ifdef DEBUG
      char *fname = "mlpipebuf::buffer_out()";
      Tracebuf T(fname);
#endif

      int cnt = pptr() - pbase();
      int retval = buffer_to_device(m_outbuf, cnt);
      pbump(-cnt);

      return retval;
   }
Пример #3
0
int callbackBuffer::overflow(int ch)
{
	streamsize n = pptr() - pbase();
	if (n && sync())
		return EOF;
	if (ch != EOF) {
		char cbuf[1];
		cbuf[0] = (char) ch;
		if (write_to_callback(cbuf, 1) != 1)
			return EOF;
	}
	pbump(-n);					// Reset pptr().
	return 0;
}
Пример #4
0
int scgi_outbuffer::overflow(int c)
{
	int len=pptr()-pbase();
	if(len) {
		int n=safe_write(fd,pbase(),len);
		pbump(-n);
	}
	if(c!=EOF) {
		char b=c;
		if(safe_write(fd,&b,1)<1)
			return EOF;
	}
	return 0;
}
Пример #5
0
bool ocryptostreambuf::update()
{
  int inl = pptr() - pbase(); // number of bytes to input
  pbump(-inl);
  int outl = 0;
  if (1 != EVP_CipherUpdate(ctx, (uint8_t*)out.data(), &outl, (uint8_t*)pbase(), inl))
    {
      EVP_CIPHER_CTX_free(ctx);
      ctx = NULL;
      return false;
    }
  // output to underlying stream
  return ( output.sputn(out.data(), outl) == outl );
}
Пример #6
0
    int flushBuffer () { // do the actual write
        int num = (int)(pptr()-pbase());
        if (write(2, buffer, num) != num) { // out to stderr
            return EOF;
        }
		// and log it
		buffer[num] = 0;
		if (!logs_.size()) { // did we recently hose this out?
			logs_.push_back(mprocess::mnote(time(NULL),std::string("")));
		}
		logs_[0].second += buffer;
        pbump (-num);    // reset put pointer accordingly
        return num;
    }
Пример #7
0
MessageBuffer::int_type MessageBuffer::overflow(int_type ch)
{
    typedef MessageBuffer::traits_type traits_type;

    if( ! _buffer)
    {
        _bufferSize = BufferSize;
        _buffer = new char[_bufferSize];
        this->setp(_buffer, _buffer + _bufferSize);
        this->setg(_buffer, _buffer, _buffer);
    }
    else
    {
        std::size_t bufsize = _bufferSize + BufferSize;
        char* buf = new char[ bufsize ];
        traits_type::copy(buf, _buffer, _bufferSize);
        std::swap(_buffer, buf);

        this->setp(_buffer, _buffer + bufsize);
        this->pbump(_bufferSize);

        std::size_t gsize = gptr() - eback();
        this->setg(_buffer, _buffer + gsize, pptr());
        
        _bufferSize = bufsize;
        delete [] buf;
    }

    // if the overflow char is not EOF put it in buffer
    if(traits_type::eq_int_type(ch, traits_type::eof()) == false)
    {
        *pptr() = traits_type::to_char_type(ch);
        this->pbump(1);
    }

    return traits_type::not_eof(ch);
}
Пример #8
0
int LogBuf::overflow(Int32 c)
{
    if(!pptr())
        return EOF;

    if(c != EOF)
    {
        // Put character into write buffer
        *pptr() = c;

        pbump(1);

        // Flush write buffer
        std::streamsize size = pptr() - pbase();

        if(size > 0)
        {
            write(pbase(), size);
            pbump(-size);
        }
    }

    return 0;
}
Пример #9
0
  int bz2streambuf::overflow(int c)
  {
    Assert(write);

    int w = pptr() - pbase();
    if (c != EOF)
    {
      *pptr() = c;
      ++w;
    }

    BZ2_bzWrite(&bzerror, bzfile, pbase(), w * sizeof(char));
    if (bzerror == BZ_OK)
    {
      setp(buf, buf + bufsize - 1);
      return 0;
    }
    else
    {
      error = true;
      setp(0, 0);
      return EOF;
    }
  }
Пример #10
0
  /**
   * Behaves according to the specification of @c std::streambuf::overflow(),
   * with the specialisation that @c std::length_error is thrown if appending
   * the character to the input sequence would require the condition
   * <tt>size() > max_size()</tt> to be true.
   */
  int_type overflow(int_type c)
  {
    if (!traits_type::eq_int_type(c, traits_type::eof()))
    {
      if (pptr() == epptr())
      {
        std::size_t buffer_size = pptr() - gptr();
        if (buffer_size < max_size_ && max_size_ - buffer_size < buffer_delta)
        {
          reserve(max_size_ - buffer_size);
        }
        else
        {
          reserve(buffer_delta);
        }
      }

      *pptr() = traits_type::to_char_type(c);
      pbump(1);
      return c;
    }

    return traits_type::not_eof(c);
  }
Пример #11
0
std::streampos SimpleStreamBuf::seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which)
{
    if (dir == std::ios_base::beg)
    {
        return seekpos(off, which);
    }
    else if (dir == std::ios_base::end)
    {
        return seekpos((pptr() - m_buffer) - off, which);
    }
    else if (dir == std::ios_base::cur)
    {
        if(which == std::ios_base::in)
        { 
            return seekpos((gptr() - m_buffer) + off, which);
        }
        else
        {
            return seekpos((pptr() - m_buffer) + off, which);
        }
    }

    return off_type(-1);
}
Пример #12
0
  int gzstreambuf::overflow(int c)
  {
    Assert(write);

    int w = pptr() - pbase();
    if (c != EOF)
    {
      *pptr() = c;
      ++w;
    }

    int byteswritten = gzwrite(gz, (void *)pbase(), w * sizeof(char));
    if (byteswritten == (w * sizeof(char)))
    {
      setp(buf, buf + bufsize - 1);
      return 0;
    }
    else
    {
      error = true;
      setp(0, 0);
      return EOF;
    }
  }
Пример #13
0
std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type ch)
{
    /* This function should be called when pptr() == epptr(). We use it also in sync()
       so we also have to write data if buffer is not full. */

    if (pbase() == pptr()) // no data to write, sync() called with empty buffer
        return 0;

    // save buffer
    PHYSFS_sint64 bytes_written = PHYSFS_write(m_file, pbase(), 1, pptr() - pbase());
    if (bytes_written <= 0)
        return traits_type::eof();

    pbump(-bytes_written);
    // write final char
    if (ch != traits_type::eof())
    {
        bytes_written = PHYSFS_write(m_file, &ch, 1, 1);
        if (bytes_written <= 0)
            return traits_type::eof();
    }

    return ch;
}
Пример #14
0
std::streampos iconvstreambuf::seekoff(std::streamoff off,
  std::ios_base::seekdir way, std::ios_base::openmode which)
{
  // modify off to by relative position from current position
  switch (way) {
    case std::ios_base::beg:
      off -= pos;
    case std::ios_base::cur:
      break;
    default:
      return std::streampos(-1);
  }

  if (which == std::ios_base::in) {
    char *buf_p = gptr() + off;
    // alow seek only on valid data
    if (buf_p < eback() || buf_p > pptr())
        return std::streampos(-1);

    gbump(off);
    pos += off;
    return pos;
  }

  if (which == std::ios_base::out) {
    char *buf_p = pptr() + off;
    // alow seek only on valid data
    if (buf_p < pbase() || buf_p > pptr())
        return std::streampos(-1);

    pbump(off);
    return pos + off;
  }

  return std::streampos(-1);
}
Пример #15
0
 int ostreambuf::overflow (int c) {
     LOG("bz::ostreambuf::overflow(" << c << ")\t available=" << (available ()) << "\tEOF=" << eof);
     if (eof == c) {
         LOG("\tEOF");
         flush(no_sync);
         return eof;
     } else {
         if (0 == available()) {
             LOG("\t have to flush :[]");
             flush(no_sync);
         }
         *pptr() = static_cast < char >(c);
         pbump(1);
     }
     return c;
 }
Пример #16
0
 // output functions
 int_type overflow (
     int_type c
 )
 {
     if (c != EOF)
     {
         *pptr() = c;
         pbump(1);
     }
     if (flush_out_buffer() == EOF)
     {
         // an error occurred
         return EOF;
     }
     return c;
 }
Пример #17
0
std::streambuf::int_type ocryptostreambuf::overflow(int_type ch)
{
  // overflow is only ever called when buffer is full
  // i think eof never happens in normal course of operation?
  if (!ctx || ch == traits_type::eof() )
    {
      return traits_type::eof();
    }

  update();

  // append remaining char to newly empty buffer
  *pptr() = ch;  pbump(1);

  return ch;
}
Пример #18
0
 virtual std::streambuf::int_type overflow(std::streambuf::int_type c = traits_type::eof())
 {
     zstrm_p->next_in = reinterpret_cast< decltype(zstrm_p->next_in) >(pbase());
     zstrm_p->avail_in = pptr() - pbase();
     while (zstrm_p->avail_in > 0)
     {
         int r = deflate_loop(Z_NO_FLUSH);
         if (r != 0)
         {
             setp(nullptr, nullptr);
             return traits_type::eof();
         }
     }
     setp(in_buff, in_buff + buff_size);
     return traits_type::eq_int_type(c, traits_type::eof()) ? traits_type::eof() : sputc(c);
 }
Пример #19
0
int filebuf::sync()
{
//    char* ptr = cur_ptr();
    if (pptr() > pbase())
	if (do_flush()) return EOF;
    if (gptr() != egptr()) {
	streampos delta = gptr() - egptr();
	if (in_backup())
	    delta -= eGptr() - Gbase();
	if (sys_seek(delta, ios::cur) == EOF)
	    return EOF;
    }
    // FIXME: Cleanup - can this be shared?
//    setg(base(), ptr, ptr);
    return 0;
}
Пример #20
0
    inline pos_type seekp(off_type off
                          , ::std::ios_base::seekdir way)
    {
        if (way == ::std::ios_base::cur)
            off += pptr() - begin();
        else if (way == ::std::ios_base::end)
            off += capacity();

        if (off >= 0 && off <= (off_type) capacity() && off >= gptr() - begin())
        {
            setpg(offset(off), gptr());
            return (::std::streampos)(off);
        }

        return (::std::streampos)(::std::_BADOFF);
    }
Пример #21
0
int gzfilebuf::flushbuf() {

  int n;
  char *q;

  q = pbase();
  n = pptr() - q;

  if ( gzwrite( file, q, n) < n )
    return EOF;

  setp(0,0);

  return 0;

}
int strstreambuf::doallocate()
{
    char * bptr;
    int size;
    size = __max(x_bufmin,blen() + __max(x_bufmin,1));
    long offset = 0;

    if (x_alloc)
        {
        bptr = (char*)(*x_alloc)(size);
        }
    else
        {
        bptr = _new_crt char[size];
        }
    if (!bptr)
        return EOF;

    if (blen())
        {
        memcpy(bptr, base(), blen());
        offset = bptr - base(); // amount to adjust pointers by
        }
    if (x_free)
        {
        (*x_free)(base());
        }
    else
        {
        delete base();
        }
    setb(bptr,bptr+size,0);     // we handle deallocation

    // adjust get/put pointers too, if necessary
    if (offset)
        if (egptr())
            {
            setg(eback()+offset,gptr()+offset,egptr()+offset);
            }
        if (epptr())
            {
            size = pptr() - pbase();
            setp(pbase()+offset,epptr()+offset);
            pbump(size);
        }
    return(1);
}
 sockstreambuf_kernel_2::int_type sockstreambuf_kernel_2::
 overflow (
     int_type c
 )
 {
     if (c != EOF)
     {
         *pptr() = c;
         pbump(1);
     }
     if (flush_out_buffer() == EOF)
     {
         // an error occurred
         return EOF;
     }
     return c;
 }
Пример #24
0
CT_POS_TYPE CConn_Streambuf::seekoff(CT_OFF_TYPE        off,
                                     IOS_BASE::seekdir  whence,
                                     IOS_BASE::openmode which)
{
    if (m_Conn  &&  off == 0  &&  whence == IOS_BASE::cur) {
        // tellp()/tellg() support only
        switch (which) {
        case IOS_BASE::out:
            return x_PPos + (CT_OFF_TYPE)(pptr() - pbase());
        case IOS_BASE::in:
            return x_GPos - (CT_OFF_TYPE)(egptr() - gptr());
        default:
            break;
        }
    }
    return (CT_POS_TYPE)((CT_OFF_TYPE)(-1L));
}
Пример #25
0
/*!

*/
int
gzfilterstreambuf::sync()
{
    if ( pptr() != NULL )
    {
        // just flush the put area
        if ( ! writeData( SYNC_FLUSH ) ) // == Z_SYNC_FLUSH
        {
            return -1;
        }

        // reset putting buffer pointer
        this->setp( M_output_buf, M_output_buf + M_buf_size );
    }

    return 0;
}
Пример #26
0
    /**
     * Flushes the output buffer to disk.
     *
     * Synchronizes the systembuf buffers with the contents of the file
     * associated to this object through the native file handle. The
     * output buffer is flushed to disk and cleared to leave new room
     * for more data.
     *
     * \returns 0 on success, -1 if an error occurred.
     */
    virtual int sync()
    {
        ptrdiff_t cnt = pptr() - pbase();

        bool ok;
#if defined(BOOST_POSIX_API)
        ok = ::write(handle_, pbase(), cnt > 0? (size_t)cnt:0 ) == cnt;
#elif defined(BOOST_WINDOWS_API)
        DWORD rcnt;
        BOOL res = ::WriteFile(handle_, pbase(), cnt, &rcnt, NULL);
        ok = (res && static_cast<long>(rcnt) == cnt);
#endif

        if (ok)
            pbump((int)-cnt);
        return ok ? 0 : -1;
    }
Пример #27
0
LoggerMessage::LoggerMessage(LoggerMessage&& other)
  : std::ostream(nullptr)
  , std::streambuf()
  , category(other.category)
  , logLevel(other.logLevel)
  , logger(other.logger)
  , message(other.message)
  , timestamp(boost::posix_time::microsec_clock::local_time())
  , gotText(false) {
  if (this != &other) {
    _M_tie = nullptr;
    _M_streambuf = nullptr;

    //ios_base swap
    std::swap(_M_streambuf_state, other._M_streambuf_state);
    std::swap(_M_exception, other._M_exception);
    std::swap(_M_flags, other._M_flags);
    std::swap(_M_precision, other._M_precision);
    std::swap(_M_width, other._M_width);

    std::swap(_M_callbacks, other._M_callbacks);
    std::swap(_M_ios_locale, other._M_ios_locale);
    //ios_base swap

    //streambuf swap
    char *_Pfirst = pbase();
    char *_Pnext = pptr();
    char *_Pend = epptr();
    char *_Gfirst = eback();
    char *_Gnext = gptr();
    char *_Gend = egptr();

    setp(other.pbase(), other.epptr());
    other.setp(_Pfirst, _Pend);

    setg(other.eback(), other.gptr(), other.egptr());
    other.setg(_Gfirst, _Gnext, _Gend);

    std::swap(_M_buf_locale, other._M_buf_locale);
    //streambuf swap

    std::swap(_M_fill, other._M_fill);
    std::swap(_M_tie, other._M_tie);
  }
  _M_streambuf = this;
}
Пример #28
0
void BinaryStreamBuffer::reserve(size_t newSize)
{
	size_t getPos = 0;
	size_t putPos = 0;
	size_t readEndPos = 0;
	if(!m_dataBuf.empty()){
		getPos = gptr() - eback();
		readEndPos = egptr() - eback();
		putPos = pptr() - buffer();
	}

	if(newSize > m_dataBuf.size())
		m_dataBuf.resize(newSize);

	setg(buffer(), buffer() + getPos, buffer() + readEndPos);
	setp(buffer() + putPos, end());
}
Пример #29
0
EIO_Status CConn_Streambuf::x_Close(bool close)
{
    if (!m_Conn)
        return close ? eIO_Closed : eIO_Success;
 
    EIO_Status status;
    // flush only if some data pending
    if (pbase() < pptr()) {
        if ((status = CONN_Status(m_Conn, eIO_Write)) != eIO_Success) {
            m_Status = status;
            if (CONN_Status(m_Conn, eIO_Open) == eIO_Success) {
                _TRACE(x_Message("Close():  Cannot finalize implicitly"
                                 ", data loss may result"));
            }
        } else if (sync() != 0)
            status = m_Status != eIO_Success ? m_Status : eIO_Unknown;
    } else
        status = eIO_Success;

    setg(0, 0, 0);
    setp(0, 0);

    CONN c = m_Conn;
    m_Conn = 0;  // NB: no re-entry

    if (close) {
        // here: not called from the close callback x_OnClose
        if (m_CbValid) {
            SCONN_Callback cb;
            CONN_SetCallback(c, eCONN_OnClose, &m_Cb, &cb);
            if ((void*) cb.func != (void*) x_OnClose  ||  cb.data != this)
                CONN_SetCallback(c, eCONN_OnClose, &cb, 0);
        }
        if (m_Close  &&  (m_Status = CONN_Close(c)) != eIO_Success) {
            _TRACE(x_Message("Close():  CONN_Close() failed"));
            if (status == eIO_Success)
                status  = m_Status;
        }
    } else if (m_CbValid  &&  m_Cb.func) {
        EIO_Status cbstat = m_Cb.func(c, eCONN_OnClose, m_Cb.data);
        if (cbstat != eIO_Success)
            status  = cbstat;
    }
    return status;
}
Пример #30
0
streambuf::int_type streambuf::overflow ( int_type character )
{
    // Ouput all contents of put buffer.
    const std::streamsize count = myStream.write(
                                      pbase(), ::ULONG(pptr()-pbase())
                                  );
    if ( count == 0 ) {
        return (traits_type::eof());
    }
    // Output overflowing character.
    const char_type value = traits_type::to_int_type(character);
    if ( myStream.write(&value,1) == 0 ) {
        return (traits_type::eof());
    }
    // Adjust put buffer pointers.
    setp(myPutBuffer,myPutBuffer+PutBufferSize);
    return (traits_type::not_eof(character));
}