Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 79945
Collapse All | Expand All

(-)netxx-0.4.2/include/netxx/netbuf.h (-11 / +14 lines)
Lines 61-67 Link Here
61
 * This streambuf is buffered so you should call std::flush to make sure it
61
 * This streambuf is buffered so you should call std::flush to make sure it
62
 * sends the data that you inserted.
62
 * sends the data that you inserted.
63
**/
63
**/
64
template <typename std::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
class Netbuf : public std::basic_streambuf<charT, traits> {
65
class Netbuf : public std::basic_streambuf<charT, traits> {
66
public:
66
public:
67
    /// int type
67
    /// int type
Lines 70-75 Link Here
70
    /// char type
70
    /// char type
71
    typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
71
    typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
72
72
73
    /// traits type
74
    typedef typename std::basic_streambuf<charT, traits>::traits_type traits_type;
75
73
    //####################################################################
76
    //####################################################################
74
    /** 
77
    /** 
75
     * Construct a Netxx::Netbuf object and link it to the given StreamBase
78
     * Construct a Netxx::Netbuf object and link it to the given StreamBase
Lines 142-167 Link Here
142
//#############################################################################
145
//#############################################################################
143
template<std::streamsize bufsize, class charT, class traits>
146
template<std::streamsize bufsize, class charT, class traits>
144
int Netbuf<bufsize, charT, traits>::buffer_out (void) {
147
int Netbuf<bufsize, charT, traits>::buffer_out (void) {
145
    int length = pptr() - pbase();
148
    int length = this->pptr() - this->pbase();
146
    int rc = stream_.write(putbuf_, length);
149
    int rc = stream_.write(putbuf_, length);
147
    pbump(-length);
150
    this->pbump(-length);
148
    return rc;
151
    return rc;
149
}
152
}
150
//#############################################################################
153
//#############################################################################
151
template<std::streamsize bufsize, class charT, class traits>
154
template<std::streamsize bufsize, class charT, class traits>
152
typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::underflow (void) {
155
typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::underflow (void) {
153
    if (gptr() < egptr()) return traits_type::to_int_type(*gptr());
156
    if (this->gptr() < this->egptr()) return traits_type::to_int_type(*(this->gptr()));
154
    if (buffer_in() < 0) return traits_type::eof();
157
    if (buffer_in() < 0) return traits_type::eof();
155
    else return traits_type::to_int_type(*gptr());
158
    else return traits_type::to_int_type(*(this->gptr()));
156
}
159
}
157
//#############################################################################
160
//#############################################################################
158
template<std::streamsize bufsize, class charT, class traits>
161
template<std::streamsize bufsize, class charT, class traits>
159
typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::pbackfail(int_type c) {
162
typename Netbuf<bufsize, charT, traits>::int_type Netbuf<bufsize, charT, traits>::pbackfail(int_type c) {
160
    if (gptr() != eback()) {
163
    if (this->gptr() != this->eback()) {
161
	gbump(-1);
164
	this->gbump(-1);
162
165
163
	if (!traits_type::eq_int_type(c, traits_type::eof())) {
166
	if (!traits_type::eq_int_type(c, traits_type::eof())) {
164
	    *(gptr()) = traits_type::to_char_type(c);
167
	    *(this->gptr()) = traits_type::to_char_type(c);
165
	}
168
	}
166
169
167
	return traits_type::not_eof(c);
170
	return traits_type::not_eof(c);
Lines 172-185 Link Here
172
//#############################################################################
175
//#############################################################################
173
template<std::streamsize bufsize, class charT, class traits>
176
template<std::streamsize bufsize, class charT, class traits>
174
int Netbuf<bufsize, charT, traits>::buffer_in (void) {
177
int Netbuf<bufsize, charT, traits>::buffer_in (void) {
175
    std::streamsize number_putbacks = std::min(gptr() - eback(), PUTBACK_SIZE);
178
    std::streamsize number_putbacks = std::min(this->gptr() - this->eback(), PUTBACK_SIZE);
176
    std::memcpy(getbuf_ + (PUTBACK_SIZE - number_putbacks) * sizeof(char_type),
179
    std::memcpy(getbuf_ + (PUTBACK_SIZE - number_putbacks) * sizeof(char_type),
177
	    gptr() - number_putbacks * sizeof(char_type), number_putbacks * sizeof(char_type));
180
	    this->gptr() - number_putbacks * sizeof(char_type), number_putbacks * sizeof(char_type));
178
181
179
    int rc = stream_.read(getbuf_ + PUTBACK_SIZE * sizeof(char_type), bufsize - PUTBACK_SIZE);
182
    int rc = stream_.read(getbuf_ + PUTBACK_SIZE * sizeof(char_type), bufsize - PUTBACK_SIZE);
180
    
183
    
181
    if (rc <= 0) {
184
    if (rc <= 0) {
182
	setg(0, 0, 0);
185
	this->setg(0, 0, 0);
183
	return -1;
186
	return -1;
184
    } else {
187
    } else {
185
	setg(getbuf_ + PUTBACK_SIZE - number_putbacks, getbuf_ + PUTBACK_SIZE, getbuf_ + PUTBACK_SIZE + rc);
188
	setg(getbuf_ + PUTBACK_SIZE - number_putbacks, getbuf_ + PUTBACK_SIZE, getbuf_ + PUTBACK_SIZE + rc);

Return to bug 79945