diff options
author | Determinant <ted.sybil@gmail.com> | 2018-07-12 18:04:52 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-07-12 18:04:52 -0400 |
commit | 53f4c5137da249e5e955809ffe32afa3cf5c3522 (patch) | |
tree | 0b187dc8e2d2d86a223ab79c42bdc471c40bc569 /include/salticidae/conn.h | |
parent | 33faa8e355dc47a126790f1ea3e52d1813aedc69 (diff) |
...
Diffstat (limited to 'include/salticidae/conn.h')
-rw-r--r-- | include/salticidae/conn.h | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h index 40facc9..589bf16 100644 --- a/include/salticidae/conn.h +++ b/include/salticidae/conn.h @@ -75,21 +75,45 @@ class RingBuffer { size_t length() const { return data.end() - offset; } }; + std::list<buffer_entry_t> ring; size_t _size; public: RingBuffer(): _size(0) {} ~RingBuffer() { clear(); } - RingBuffer &operator=(const RingBuffer &other) = delete; - RingBuffer(const RingBuffer &other) = delete; - RingBuffer &operator=(RingBuffer &&other) { - ring = std::move(other.ring); - _size = other._size; + + void swap(RingBuffer &other) { + std::swap(ring, other.ring); + std::swap(_size, other._size); + } + + RingBuffer(const RingBuffer &other): + ring(other.ring), _size(other._size) {} + + RingBuffer(RingBuffer &&other): + ring(std::move(other.ring)), _size(other._size) { other._size = 0; + } + + RingBuffer &operator=(RingBuffer &&other) { + if (this != &other) + { + RingBuffer tmp(std::move(other)); + tmp.swap(*this); + } return *this; } - + + RingBuffer &operator=(const RingBuffer &other) { + if (this != &other) + { + RingBuffer tmp(other); + tmp.swap(*this); + } + return *this; + } + void push(bytearray_t &&data) { _size += data.size(); ring.push_back(buffer_entry_t(std::move(data))); @@ -188,9 +212,9 @@ class ConnPool { protected: /** close the connection and free all on-going or planned events. */ virtual void close() { - ev_read.clear(); - ev_write.clear(); - ev_connect.clear(); + ev_read.del(); + ev_write.del(); + ev_connect.del(); ::close(fd); fd = -1; } |