29 : std::iostream(this), errmsg(
ERROR_NONE), _bufsize(buffer_size), in_buf_(_bufsize), out_buf_(_bufsize)
32 timerclear(&_timeout);
35 setp(&out_buf_[0], &out_buf_[0] + _bufsize - 1);
55 ::memcpy(&_timeout, &val,
sizeof _timeout);
60 int ret = std::char_traits<char>::eq_int_type(this->
overflow(
61 std::char_traits<char>::eof()), std::char_traits<char>::eof()) ? -1
69 char *ibegin = &out_buf_[0];
73 setp(&out_buf_[0], &out_buf_[0] + _bufsize - 1);
75 if (!std::char_traits<char>::eq_int_type(c, std::char_traits<char>::eof()))
77 *iend++ = std::char_traits<char>::to_char_type(c);
81 if ((iend - ibegin) == 0)
84 return std::char_traits<char>::not_eof(c);
89 _socket.
select(NULL, &writeset, NULL, NULL);
92 if (writeset.size() == 0) {
97 ssize_t bytes = (iend - ibegin);
102 ssize_t ret = sock.
send(&out_buf_[0], (iend - ibegin), 0);
108 char *resched_begin = ibegin + ret;
109 char *resched_end = iend;
112 size_t bytes_left = resched_end - resched_begin;
115 ::memcpy(ibegin, resched_begin, bytes_left);
118 char *buffer_begin = ibegin + bytes_left;
121 setp(buffer_begin, &out_buf_[0] + _bufsize - 1);
140 std::stringstream ss; ss <<
"send() failed: " << err.
code();
153 return std::char_traits<char>::not_eof(c);
161 if (timerisset(&_timeout)) {
163 ::memcpy(&to_copy, &_timeout,
sizeof to_copy);
164 _socket.
select(&readset, NULL, NULL, &to_copy);
166 _socket.
select(&readset, NULL, NULL, NULL);
170 if (readset.size() == 0) {
178 ssize_t bytes = sock.
recv(&in_buf_[0], _bufsize, 0);
186 return std::char_traits<char>::eof();
191 setg(&in_buf_[0], &in_buf_[0], &in_buf_[0] + bytes);
193 return std::char_traits<char>::not_eof(in_buf_[0]);
198 return std::char_traits<char>::eof();
211 return std::char_traits<char>::eof();