Ticket #3017: patch-netbuf.h.diff

File patch-netbuf.h.diff, 4.6 KB (added by andre@…, 19 years ago)

This is patchfile 1 of 2

  • netxx-0.4.2/include/netxx/netbuf.h

    old new  
    6161 * This streambuf is buffered so you should call std::flush to make sure it
    6262 * sends the data that you inserted.
    6363**/
    64 template <typename std::streamsize bufsize, class charT=char, class traits=std::char_traits<char> >
     64template <std::streamsize bufsize, class charT=char, class traits=std::char_traits<char> >
    6565class Netbuf : public std::basic_streambuf<charT, traits> {
    6666public:
    6767    /// int type
     
    9292    ~Netbuf (void);
    9393protected:
    9494    // TODO streamsize xsputn (const char_type *s, streamsize n);
    95     int_type overflow (int_type c=traits_type::eof());
     95
     96    int_type overflow (int_type c=traits::eof());
    9697    int sync (void);
    9798
    9899    int_type underflow (void);
     
    116117    : stream_(stream)
    117118{
    118119    setp(putbuf_, putbuf_ + bufsize);
    119     setg(getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE);
     120    Netbuf::setg(getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE);
    120121}
    121122//#############################################################################
    122123template<std::streamsize bufsize, class charT, class traits>
     
    127128template<std::streamsize bufsize, class charT, class traits>
    128129typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::overflow (int_type c) {
    129130    if (buffer_out() < 0) {
    130         return traits_type::eof();
    131     } else if (!traits_type::eq_int_type(c, traits_type::eof())) {
     131        return traits::eof();
     132    } else if (!traits::eq_int_type(c, traits::eof())) {
    132133        return sputc(c);
    133134    } else {
    134         return traits_type::not_eof(c);
     135        return traits::not_eof(c);
    135136    }
    136137}
    137138//#############################################################################
     
    142143//#############################################################################
    143144template<std::streamsize bufsize, class charT, class traits>
    144145int Netbuf<bufsize, charT, traits>::buffer_out (void) {
    145     int length = pptr() - pbase();
     146    int length = Netbuf::pptr() - Netbuf::pbase();
    146147    int rc = stream_.write(putbuf_, length);
    147     pbump(-length);
     148    Netbuf::pbump(-length);
    148149    return rc;
    149150}
    150151//#############################################################################
    151152template<std::streamsize bufsize, class charT, class traits>
    152153typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::underflow (void) {
    153     if (gptr() < egptr()) return traits_type::to_int_type(*gptr());
    154     if (buffer_in() < 0) return traits_type::eof();
    155     else return traits_type::to_int_type(*gptr());
     154    if (Netbuf::gptr() < Netbuf::egptr()) return traits::to_int_type(*Netbuf::gptr());
     155    if (buffer_in() < 0) return traits::eof();
     156    else return traits::to_int_type(*Netbuf::gptr());
    156157}
    157158//#############################################################################
    158159template<std::streamsize bufsize, class charT, class traits>
    159160typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::pbackfail(int_type c) {
    160     if (gptr() != eback()) {
    161         gbump(-1);
     161    if (Netbuf::gptr() != Netbuf::eback()) {
     162        Netbuf::gbump(-1);
    162163
    163         if (!traits_type::eq_int_type(c, traits_type::eof())) {
    164             *(gptr()) = traits_type::to_char_type(c);
     164        if (!traits::eq_int_type(c, traits::eof())) {
     165            *(Netbuf::gptr()) = traits::to_char_type(c);
    165166        }
    166167
    167         return traits_type::not_eof(c);
     168        return traits::not_eof(c);
    168169    } else {
    169         return traits_type::eof();
     170        return traits::eof();
    170171    }
    171172}
    172173//#############################################################################
    173174template<std::streamsize bufsize, class charT, class traits>
    174175int Netbuf<bufsize, charT, traits>::buffer_in (void) {
    175     std::streamsize number_putbacks = std::min(gptr() - eback(), PUTBACK_SIZE);
     176    std::streamsize number_putbacks = std::min(Netbuf::gptr() - Netbuf::eback(), PUTBACK_SIZE);
    176177    std::memcpy(getbuf_ + (PUTBACK_SIZE - number_putbacks) * sizeof(char_type),
    177             gptr() - number_putbacks * sizeof(char_type), number_putbacks * sizeof(char_type));
     178            Netbuf::gptr() - number_putbacks * sizeof(char_type), number_putbacks * sizeof(char_type));
    178179
    179180    int rc = stream_.read(getbuf_ + PUTBACK_SIZE * sizeof(char_type), bufsize - PUTBACK_SIZE);
    180181   
    181182    if (rc <= 0) {
    182         setg(0, 0, 0);
     183        Netbuf::setg(0, 0, 0);
    183184        return -1;
    184185    } else {
    185         setg(getbuf_ + PUTBACK_SIZE - number_putbacks, getbuf_ + PUTBACK_SIZE, getbuf_ + PUTBACK_SIZE + rc);
     186        Netbuf::setg(getbuf_ + PUTBACK_SIZE - number_putbacks, getbuf_ + PUTBACK_SIZE, getbuf_ + PUTBACK_SIZE + rc);
    186187        return rc;
    187188    }
    188189}