aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/salticidae/conn.h7
-rw-r--r--src/conn.cpp10
2 files changed, 9 insertions, 8 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h
index d93f787..53d51a3 100644
--- a/include/salticidae/conn.h
+++ b/include/salticidae/conn.h
@@ -104,7 +104,12 @@ class SegBuffer {
}
return *this;
}
-
+
+ void rewind(bytearray_t &&data) {
+ _size += data.size();
+ buffer.push_front(buffer_entry_t(std::move(data)));
+ }
+
void push(bytearray_t &&data) {
_size += data.size();
buffer.push_back(buffer_entry_t(std::move(data)));
diff --git a/src/conn.cpp b/src/conn.cpp
index 2a7735b..d650b76 100644
--- a/src/conn.cpp
+++ b/src/conn.cpp
@@ -60,7 +60,7 @@ void ConnPool::Conn::send_data(evutil_socket_t fd, short events) {
if (ret < 1) /* nothing is sent */
{
/* rewind the whole buff_seg */
- send_buffer.push(std::move(buff_seg));
+ send_buffer.rewind(std::move(buff_seg));
if (ret < 0 && errno != EWOULDBLOCK)
{
SALTICIDAE_LOG_INFO("reason: %s", strerror(errno));
@@ -69,13 +69,9 @@ void ConnPool::Conn::send_data(evutil_socket_t fd, short events) {
}
}
else
- {
/* rewind the leftover */
- bytearray_t left_over;
- left_over.resize(size);
- memmove(left_over.data(), buff_seg.data() + ret, size);
- send_buffer.push(std::move(left_over));
- }
+ send_buffer.rewind(
+ bytearray_t(buff_seg.begin() + ret, buff_seg.end()));
/* wait for the next write callback */
ready_send = false;
ev_write.add();