Ticket #3017: patch-netbuf.h.diff
File patch-netbuf.h.diff, 4.6 KB (added by andre@…, 20 years ago) |
---|
-
netxx-0.4.2/include/netxx/netbuf.h
old new 61 61 * This streambuf is buffered so you should call std::flush to make sure it 62 62 * sends the data that you inserted. 63 63 **/ 64 template < typenamestd::streamsize bufsize, class charT=char, class traits=std::char_traits<char> >64 template <std::streamsize bufsize, class charT=char, class traits=std::char_traits<char> > 65 65 class Netbuf : public std::basic_streambuf<charT, traits> { 66 66 public: 67 67 /// int type … … 92 92 ~Netbuf (void); 93 93 protected: 94 94 // 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()); 96 97 int sync (void); 97 98 98 99 int_type underflow (void); … … 116 117 : stream_(stream) 117 118 { 118 119 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); 120 121 } 121 122 //############################################################################# 122 123 template<std::streamsize bufsize, class charT, class traits> … … 127 128 template<std::streamsize bufsize, class charT, class traits> 128 129 typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::overflow (int_type c) { 129 130 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())) { 132 133 return sputc(c); 133 134 } else { 134 return traits _type::not_eof(c);135 return traits::not_eof(c); 135 136 } 136 137 } 137 138 //############################################################################# … … 142 143 //############################################################################# 143 144 template<std::streamsize bufsize, class charT, class traits> 144 145 int Netbuf<bufsize, charT, traits>::buffer_out (void) { 145 int length = pptr() -pbase();146 int length = Netbuf::pptr() - Netbuf::pbase(); 146 147 int rc = stream_.write(putbuf_, length); 147 pbump(-length);148 Netbuf::pbump(-length); 148 149 return rc; 149 150 } 150 151 //############################################################################# 151 152 template<std::streamsize bufsize, class charT, class traits> 152 153 typename 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()); 156 157 } 157 158 //############################################################################# 158 159 template<std::streamsize bufsize, class charT, class traits> 159 160 typename 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); 162 163 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); 165 166 } 166 167 167 return traits _type::not_eof(c);168 return traits::not_eof(c); 168 169 } else { 169 return traits _type::eof();170 return traits::eof(); 170 171 } 171 172 } 172 173 //############################################################################# 173 174 template<std::streamsize bufsize, class charT, class traits> 174 175 int 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); 176 177 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)); 178 179 179 180 int rc = stream_.read(getbuf_ + PUTBACK_SIZE * sizeof(char_type), bufsize - PUTBACK_SIZE); 180 181 181 182 if (rc <= 0) { 182 setg(0, 0, 0);183 Netbuf::setg(0, 0, 0); 183 184 return -1; 184 185 } 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); 186 187 return rc; 187 188 } 188 189 }