CT_INT_TYPE CConn_Streambuf::underflow(void) { _ASSERT(gptr() >= egptr()); if (!m_Conn) return CT_EOF; // flush output buffer, if tied up to it if (m_Tie && x_sync() != 0) return CT_EOF; #ifdef NCBI_COMPILER_MIPSPRO if (m_MIPSPRO_ReadsomeGptrSetLevel && m_MIPSPRO_ReadsomeGptr != gptr()) return CT_EOF; m_MIPSPRO_ReadsomeGptr = (CT_CHAR_TYPE*)(-1L); #endif /*NCBI_COMPILER_MIPSPRO*/ // read from connection size_t n_read; m_Status = CONN_Read(m_Conn, m_ReadBuf, m_BufSize, &n_read, eIO_ReadPlain); _ASSERT(n_read <= m_BufSize); if (!n_read) { _ASSERT(m_Status != eIO_Success); if (m_Status != eIO_Closed) ERR_POST_X(8, x_Message("underflow(): CONN_Read() failed")); return CT_EOF; } // update input buffer with the data just read x_GPos += (CT_OFF_TYPE) n_read; setg(m_ReadBuf, m_ReadBuf, m_ReadBuf + n_read); return CT_TO_INT_TYPE(*m_ReadBuf); }
CStreamLineReader::EEOLStyle CStreamLineReader::x_AdvanceEOLUnknown(void) { _ASSERT(m_AutoEOL); NcbiGetline(*m_Stream, m_Line, "\r\n", &m_LastReadSize); m_Stream->unget(); CT_INT_TYPE eol = m_Stream->get(); if (CT_EQ_INT_TYPE(eol, CT_TO_INT_TYPE('\r'))) { m_EOLStyle = eEOL_cr; } else if (CT_EQ_INT_TYPE(eol, CT_TO_INT_TYPE('\n'))) { // NcbiGetline doesn't yield enough information to determine // whether eEOL_lf or eEOL_crlf is more appropriate, and not // all streams allow tellg() (which could otherwise resolve // matters), so defer further analysis to x_AdvanceEOLCRLF, // which will be responsible for reading the next line and // supports switching to eEOL_lf as appropriate. // // An alternative approach would have been to pass \n\r rather // than \r\n, and then check for an immediately following \n // if eol turned out to be \r, but that would miscount an // actual(!) \n\r sequence as a single line break. m_EOLStyle = eEOL_crlf; } return m_EOLStyle; }
CT_INT_TYPE CCompressionStreambuf::underflow(void) { // Check processor's state if ( !IsStreamProcessorOkay(CCompressionStream::eRead) ) { return CT_EOF; } // Reset pointer to the processed data setg(m_Reader->m_OutBuf, m_Reader->m_OutBuf, m_Reader->m_OutBuf); // Try to process next data if ( !ProcessStreamRead() || gptr() == egptr() ) { return CT_EOF; } return CT_TO_INT_TYPE(*gptr()); }
ERW_Result CCgiEntryReader::PendingCount(size_t* count) { _ASSERT(count); if ( !m_Buffer.empty() ) { *count = m_Buffer.size(); return eRW_Success; } else if ((m_State & fHitBoundary) != 0) { *count = 0; return eRW_Eof; } else if (m_Context.m_In.rdbuf()->in_avail() <= 0) { return eRW_NotImplemented; } else if ((m_State & fHitCRLF) == fHitCRLF && CT_EQ_INT_TYPE(m_Context.m_In.peek(), CT_TO_INT_TYPE('-'))) { return eRW_NotImplemented; // possible boundary } else { *count = 1; return eRW_Success; } }
CStreamLineReader::EEOLStyle CStreamLineReader::x_AdvanceEOLSimple(char eol, char alt_eol) { SIZE_TYPE pos; NcbiGetline(*m_Stream, m_Line, eol, &m_LastReadSize); if (m_AutoEOL && (pos = m_Line.find(alt_eol)) != NPOS) { ++pos; if (eol != '\n' || pos != m_Line.size()) { // an *immediately* preceding CR is quite all right CStreamUtils::Pushback(*m_Stream, m_Line.data() + pos, m_Line.size() - pos); m_EOLStyle = eEOL_mixed; } m_Line.resize(pos - 1); m_LastReadSize = pos; return (m_EOLStyle == eEOL_mixed) ? m_EOLStyle : eEOL_crlf; } else if (m_AutoEOL && eol == '\r' && CT_EQ_INT_TYPE(m_Stream->peek(), CT_TO_INT_TYPE(alt_eol))) { m_Stream->get(); ++m_LastReadSize; return eEOL_crlf; } return (eol == '\r') ? eEOL_cr : eEOL_lf; }