filebuf::filebuf(int f) { xfd = f; // assumed to be valid opened = 1; // unless we can find out otherwise mode = 0; // unless we can find out otherwise last_seek = 0; char* p = new char[B_size]; if( p ) { setb(p, p+B_size, 1); // ~streambuf() will delete buffer setp(p+4, p+4); setg(p, p+4, p+4); } }
filebuf::filebuf() { xfd = EOF; mode = 0; opened = 0; last_seek = 0; char* p = new char[B_size]; if( p ) { setb(p, p+B_size, 1); // ~streambuf() will delete buffer setp(p+4, p+4); setg(p, p+4, p+4); } }
void IOBuffer::init(std::size_t bufferSize, bool extend) { _ibufferSize = bufferSize + 4; _ibuffer = 0; _obufferSize = bufferSize; _obuffer = 0; _oextend = extend; if( gptr() ) setg(_ibuffer, _ibuffer + _ibufferSize, _ibuffer + _ibufferSize); if( pptr() ) setp(_obuffer, _obuffer + _obufferSize); }
int Md5streambuf::sync() { if (pptr() != pbase()) { // konsumiere Zeichen aus dem Puffer log_debug("process " << (pptr() - pbase()) << " bytes of data"); cxxtools_MD5Update(context, (const unsigned char*)pbase(), pptr() - pbase()); // leere Ausgabepuffer setp(buffer, buffer + bufsize); } return 0; }
int main (void) { int (*p) (void); int i; for (i = 0; i < 10; i ++) { setp (&p, i); p (); } return 0; }
int lowpanstream::overflow(int c) { char *ibegin = out_buf_; char *iend = pptr(); IBRCOMMON_LOGGER_DEBUG(10) << "lowpanstream::overflow"<< IBRCOMMON_LOGGER_ENDL; // mark the buffer as free setp(out_buf_ + 1, out_buf_ + BUFF_SIZE - 1); if (!std::char_traits<char>::eq_int_type(c, std::char_traits<char>::eof())) { *iend++ = std::char_traits<char>::to_char_type(c); } // bytes to send size_t bytes = (iend - ibegin); // if there is nothing to send, just return if (bytes == 0) { IBRCOMMON_LOGGER_DEBUG(10) << "lowpanstream::overflow() nothing to sent" << IBRCOMMON_LOGGER_ENDL; return std::char_traits<char>::not_eof(c); } //FIXME: Should we write in the segment position here? out_buf_[0] = 0x07 & out_seq_num_; out_buf_[0] |= _out_stat; out_seq_num_global++; out_seq_num_ = (out_seq_num_ + 1) % 8; IBRCOMMON_LOGGER_DEBUG(10) << "lowpanstream send segment " << (int)out_seq_num_ << " / " << out_seq_num_global << IBRCOMMON_LOGGER_ENDL; // Send segment to CL, use callback interface callback.send_cb(out_buf_, bytes, _address); if (_out_stat & SEGMENT_LAST) { // reset outgoing status byte and sequence number _out_stat = SEGMENT_FIRST; out_seq_num_ = 0; } else { _out_stat = SEGMENT_MIDDLE; } return std::char_traits<char>::not_eof(c); }
std::ios::pos_type Charbuf::seekoff(std::ios::off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) { std::ios::pos_type pos; char *cpos = nullptr; if (which & std::ios_base::in) { switch (dir) { case std::ios::beg: cpos = eback() + off - m_bufOffset; break; case std::ios::cur: cpos = gptr() + off; break; case std::ios::end: cpos = egptr() - off; break; default: break; // Should never happen. } if (cpos < eback() || cpos > egptr()) return -1; setg(eback(), cpos, egptr()); pos = cpos - eback(); } if (which & std::ios_base::out) { switch (dir) { case std::ios::beg: cpos = m_buf + off - m_bufOffset; break; case std::ios::cur: cpos = pptr() + off; break; case std::ios::end: cpos = egptr() - off; break; default: break; // Should never happen. } if (cpos < m_buf || cpos > epptr()) return -1; setp(cpos, epptr()); pos = cpos - m_buf; } return pos; }
int Socket::sync() { if(getOutputBufferSize() <= 0) //No output buffer return EOF; if(pptr() == pbase()) //Allready in sync return 0; try { setp(pbase(), pptr()+send(pbase(), pptr()-pbase())); return 0; } catch(Exception err) { return EOF; } }
/// Move-construct a basic_socket_streambuf from another. basic_socket_streambuf(basic_socket_streambuf&& other) : detail::socket_streambuf_io_context(other), basic_socket<Protocol ASIO_SVC_TARG>(std::move(other.socket())), ec_(other.ec_), expiry_time_(other.expiry_time_) { get_buffer_.swap(other.get_buffer_); put_buffer_.swap(other.put_buffer_); setg(other.eback(), other.gptr(), other.egptr()); setp(other.pptr(), other.epptr()); other.ec_ = asio::error_code(); other.expiry_time_ = max_expiry_time(); other.init_buffers(); }
int PAsteriskLog::Buffer::overflow(int c) { if (pptr() >= epptr()) { int ppos = pptr() - pbase(); char *newptr = string.GetPointer(string.GetSize() + 2000); setp(newptr, newptr + string.GetSize() - 1); pbump(ppos); } if (c != EOF) { *pptr() = (char)c; pbump(1); } return 0; }
int streambuf::sync () { // Ouput all contents of put buffer. const std::streamsize count = myChannel.put( reinterpret_cast<const uint8*>(pbase()), std::streamsize(pptr()-pbase()) ); // Adjust put buffer pointers. setp(pptr(),epptr()); // Indicate status (failure/success). return ((count == 0)? 0 : 1); }
streampos strstreambuf::seekoff( streamoff offset, ios::seekdir direction, int mode ) { streampos newpos; char *endget; char *pos; mode &= (ios::in | ios::out); if( (mode == 0) || ( (direction==ios::cur) && (mode == (ios::in | ios::out)) ) ) { return( EOF ); } __lock_it( __b_lock ); // Move the get pointer: if( mode & ios::in ) { endget = pptr(); if( endget == NULL || endget < egptr() ) { endget = egptr(); } newpos = __get_position( offset, direction, eback(), gptr(), egptr(), endget ); if( newpos != EOF ) { // If the seek went beyond the end of the get area, extend the // get area to include the characters in the put area. pos = eback() + newpos; if( pos > egptr() ) { setg( eback(), pos, epptr() ); } else { setg( eback(), pos, egptr() ); } } } if( mode & ios::out ) { // Move the put pointer: newpos = __get_position( offset, direction, pbase(), pptr(), epptr(), epptr() ); if( newpos != EOF ) { setp( pbase(), epptr() ); pbump( newpos ); if( newpos > __minbuf_size ) { __minbuf_size = (int)newpos; } } } return( newpos ); }
virtual int sync() { if (pbase() != pptr()) { // Replace '\n' at the end of the message with '\0' *(pptr() - 1) = '\0'; // Call the function in sf.pyx that handles new messages set_error_message(pbase()); setp(pbase(), epptr()); } return 0; }
ocryptostreambuf::ocryptostreambuf(std::streambuf* out, const crypto_key& key, const crypto_iv& iv, int enc) :ctx(EVP_CIPHER_CTX_new()), output(*out) { if (!ctx) return; if (1 != EVP_CipherInit_ex(ctx, EVP_aes_256_cbc(), NULL, key.data(), iv.data(), enc)) { EVP_CIPHER_CTX_free(ctx); ctx = NULL; } setp(in.data(),in.data()+in.size()); }
/** * Constructs a new systembuf for the given file handle. * * This constructor creates a new systembuf object that reads or * writes data from/to the \a h native file handle. This handle * is \b not owned by the created systembuf object; the code * should take care of it externally. * * This class buffers input and output; the buffer size may be * tuned through the \a bufsize parameter, which defaults to 8192 * bytes. * * \see pistream and postream */ explicit systembuf(handle_type h, std::size_t bufsize = 8192) : handle_(h), bufsize_(bufsize), read_buf_(new char[bufsize]), write_buf_(new char[bufsize]) { #if defined(BOOST_POSIX_API) BOOST_ASSERT(handle_ >= 0); #elif defined(BOOST_WINDOWS_API) BOOST_ASSERT(handle_ != INVALID_HANDLE_VALUE); #endif BOOST_ASSERT(bufsize_ > 0); setp(write_buf_.get(), write_buf_.get() + bufsize_); }
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; } }
bool exec_stream_buffer_t::send_buffer() { if( pbase()!=pptr() ) { std::size_t write_size=pptr()-pbase(); std::size_t n=write_size; bool no_more; m_thread_buffer.put( pbase(), n, no_more ); if( no_more || n!=write_size ) { return false; }else { setp( m_stream_buffer, m_stream_buffer+STREAM_BUFFER_SIZE ); } } return true; }
DatagramConnection::Stream::Stream(DatagramConnection &conn, const dtn::data::Length &maxmsglen) : std::iostream(this), _buf_size(maxmsglen), _first_segment(true), _last_segment(false), _queue_buf(_buf_size), _queue_buf_len(0), _queue_buf_head(false), _out_buf(_buf_size), _in_buf(_buf_size), _abort(false), _skip(false), _reject(false), _callback(conn) { // Initialize get pointer. This should be zero so that underflow // is called upon first read. setg(0, 0, 0); // mark the buffer for outgoing data as free // the +1 sparse the first byte in the buffer and leave room // for the processing flags of the segment setp(&_out_buf[0], &_out_buf[0] + _buf_size - 1); }
void strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg) { if (__n == 0) __n = static_cast<streamsize>(strlen(__gnext)); else if (__n < 0) __n = INT_MAX; if (__pbeg == nullptr) setg(__gnext, __gnext, __gnext + __n); else { setg(__gnext, __gnext, __pbeg); setp(__pbeg, __pbeg + __n); } }
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; } }
unicode_streambuf::unicode_streambuf(std::wstreambuf* wide_buffer, size_t size) : wide_size_(size), narrow_size_(wide_size_ * utf8_max_character_size), narrow_(new char[narrow_size_]), wide_(new wchar_t[narrow_size_]), wide_buffer_(wide_buffer) { if (wide_size_ > (bc::max_uint64 / utf8_max_character_size)) throw std::ios_base::failure( "Wide buffer must be no more than one fourth of max uint64."); // Input buffer is not yet populated, reflect zero length buffer here. setg(narrow_, narrow_, narrow_); // Output buffer is underexposed by 1 byte to accomodate the overflow byte. setp(narrow_, &narrow_[narrow_size_ - 1]); }
_STLP_EXP_DECLSPEC strstreambuf::int_type strstreambuf::overflow(int_type c) { if (c == traits_type::eof()) return traits_type::not_eof(c); #ifdef __SYMBIAN32__ if (pptr() != 0 && pptr() < epptr()) { *pptr() = c; pbump(1); return c; } if (!_M_dynamic || _M_constant || _M_frozen) return (EOF); // can't extend #endif // Try to expand the buffer. if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) { ptrdiff_t old_size = epptr() - pbase(); ptrdiff_t new_size = (max)(2 * old_size, ptrdiff_t(1)); char* buf = _M_alloc(new_size); if (buf) { memcpy(buf, pbase(), old_size); char* old_buffer = pbase(); bool reposition_get = false; ptrdiff_t old_get_offset; if (gptr() != 0) { reposition_get = true; old_get_offset = gptr() - eback(); } setp(buf, buf + new_size); pbump((int)old_size); if (reposition_get) setg(buf, buf + old_get_offset, buf + (max)(old_get_offset, old_size)); _M_free(old_buffer); } } if (pptr() != epptr()) { *pptr() = c; pbump(1); return c; } else return traits_type::eof(); }
_STLP_BEGIN_NAMESPACE // strstreambuf constructor, destructor. strstreambuf::strstreambuf(streamsize initial_capacity) : _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(true), _M_frozen(false), _M_constant(false) { size_t n = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()), (max)(initial_capacity, streamsize(16)))) : __STATIC_CAST(size_t, (max)(initial_capacity, streamsize(16))); char* buf = _M_alloc(n); if (buf) { setp(buf, buf + n); setg(buf, buf, buf); } }
void ostreambuf::init() { LOG("bz::ostreambuf::init"); int cret =::BZ2_bzCompressInit( z_strm, level, 0, //verbosity 30 //workFactor (default value) controls when to switch to the fallback algorithm ); if (BZ_OK != cret) { LOG("bz::ostreambuf::init: error creating zstream " << cret); raise_error(cret); } //initialize streambuf interface functions setp(in.buf, in.buf + in.size); }
boolean rpcbuf::expand_p() { int newsize = (epptr() - pbase()) * 2; char* put = new char[newsize]; if (!put) { return false; } int nwaiting = out_waiting(); Memory::copy(pbase(), put, nwaiting); delete pbase(); setp(put, put + newsize); pbump(nwaiting); setr(put); return true; }
void strstreambuf::_CS_init(char* gn, streamsize n, char* pb) { if (n == 0) n = gn == 0? 0: strlen(gn); else if (n < 0) n = INT_MAX; if (pb == 0) setg(gn, gn, gn + n); else { setg(gn, gn, pb); setp(pb, pb + n); } }
inline systembuf::systembuf(handle_type h, std::size_t bufsize) : m_handle(h), m_bufsize(bufsize), m_read_buf(new char[bufsize]), m_write_buf(new char[bufsize]) { #if defined(BOOST_PROCESS_WIN32_API) BOOST_ASSERT(m_handle != INVALID_HANDLE_VALUE); #else BOOST_ASSERT(m_handle >= 0); #endif BOOST_ASSERT(m_bufsize > 0); setp(m_write_buf.get(), m_write_buf.get() + m_bufsize); }
void syslogLogger::put_buffer() { if (pbase() != pptr()) { t_int len = (pptr() - pbase()); char *buffer = new char[len + 1]; strncpy(buffer, pbase(), len); buffer[len] = '\0'; syslog(LOG_NOTICE, "%s", buffer); setp(pbase(), epptr()); delete [] buffer; } }
// // int netstream::overflow(int ch) // // Used to dump the buffer when it is full and a new character needs to be added. // int netstream::overflow( int ch ) { // Send the characters that are buffered. (Errors? What are those?) channel.write( start, static_cast<int>( pptr( ) - pbase( ) ) ); // Reset the put pointers. setp( pbase( ), epptr( ) ); // Put the given character into the buffer. if ( ch != EOF ) { *pptr( ) = Ch; pbump( 1 ); } return 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; }