10 #ifndef MSGPACK_V1_VREFBUFFER_HPP 11 #define MSGPACK_V1_VREFBUFFER_HPP 23 #endif // defined(_MSC_VER) 25 #if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) 59 m_chunk_size(chunk_size)
61 size_t nfirst = (
sizeof(
iovec) < 72/2) ?
62 72 /
sizeof(
iovec) : 8;
65 sizeof(
iovec) * nfirst));
67 throw std::bad_alloc();
71 m_end = array + nfirst;
74 chunk* c =
static_cast<chunk*
>(::malloc(
sizeof(chunk) + chunk_size));
77 throw std::bad_alloc();
79 inner_buffer*
const ib = &m_inner_buffer;
81 ib->free = chunk_size;
82 ib->ptr =
reinterpret_cast<char*
>(c) +
sizeof(chunk);
90 chunk* c = m_inner_buffer.head;
104 void write(
const char* buf,
size_t len)
106 if(len < m_ref_size) {
107 append_copy(buf, len);
109 append_ref(buf, len);
115 if(m_tail == m_end) {
116 const size_t nused = m_tail - m_array;
117 const size_t nnext = nused * 2;
120 m_array,
sizeof(
iovec)*nnext));
122 throw std::bad_alloc();
126 m_end = nvec + nnext;
127 m_tail = nvec + nused;
130 m_tail->
iov_base =
const_cast<char*
>(buf);
131 m_tail->iov_len = len;
137 inner_buffer*
const ib = &m_inner_buffer;
140 size_t sz = m_chunk_size;
145 chunk* c =
static_cast<chunk*
>(::malloc(
sizeof(chunk) + sz));
147 throw std::bad_alloc();
153 ib->ptr =
reinterpret_cast<char*
>(c) +
sizeof(chunk);
157 std::memcpy(m, buf, len);
161 if(m_tail != m_array && m ==
162 static_cast<const char*>(
163 const_cast<const void *>((m_tail - 1)->
iov_base)
179 return m_tail - m_array;
184 size_t sz = m_chunk_size;
186 chunk* empty =
static_cast<chunk*
>(::malloc(
sizeof(chunk) + sz));
188 throw std::bad_alloc();
193 const size_t nused = m_tail - m_array;
194 if(to->m_tail + nused < m_end) {
195 const size_t tosize = to->m_tail - to->m_array;
196 const size_t reqsize = nused + tosize;
197 size_t nnext = (to->m_end - to->m_array) * 2;
198 while(nnext < reqsize) {
199 size_t tmp_nnext = nnext * 2;
200 if (tmp_nnext <= nnext) {
208 to->m_array,
sizeof(
iovec)*nnext));
211 throw std::bad_alloc();
215 to->m_end = nvec + nnext;
216 to->m_tail = nvec + tosize;
219 std::memcpy(to->m_tail, m_array,
sizeof(
iovec)*nused);
225 inner_buffer*
const ib = &m_inner_buffer;
226 inner_buffer*
const toib = &to->m_inner_buffer;
228 chunk* last = ib->head;
232 last->next = toib->head;
233 toib->head = ib->head;
235 if(toib->free < ib->free) {
236 toib->free = ib->free;
242 ib->ptr =
reinterpret_cast<char*
>(empty) +
sizeof(chunk);
248 chunk* c = m_inner_buffer.head->next;
256 inner_buffer*
const ib = &m_inner_buffer;
259 ib->free = m_chunk_size;
260 ib->ptr =
reinterpret_cast<char*
>(c) +
sizeof(chunk);
265 #if defined(MSGPACK_USE_CPP03) 269 #else // defined(MSGPACK_USE_CPP03) 272 #endif // defined(MSGPACK_USE_CPP03) 282 inner_buffer m_inner_buffer;
292 #endif // MSGPACK_V1_VREFBUFFER_HPP size_t iov_len
Definition: vrefbuffer.hpp:30
void * iov_base
Definition: vrefbuffer.hpp:29
size_t vector_size() const
Definition: vrefbuffer.hpp:177
void append_ref(const char *buf, size_t len)
Definition: vrefbuffer.hpp:113
#define MSGPACK_VREFBUFFER_REF_SIZE
Definition: vrefbuffer_decl.hpp:18
~vrefbuffer()
Definition: vrefbuffer.hpp:88
const struct iovec * vector() const
Definition: vrefbuffer.hpp:172
Definition: adaptor_base.hpp:15
std::size_t const packer_max_buffer_size
Definition: vrefbuffer.hpp:42
#define MSGPACK_VREFBUFFER_CHUNK_SIZE
Definition: vrefbuffer_decl.hpp:22
void append_copy(const char *buf, size_t len)
Definition: vrefbuffer.hpp:135
Definition: vrefbuffer.hpp:28
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
void write(const char *buf, size_t len)
Definition: vrefbuffer.hpp:104
void migrate(vrefbuffer *to)
Definition: vrefbuffer.hpp:182
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:35
vrefbuffer(size_t ref_size=MSGPACK_VREFBUFFER_REF_SIZE, size_t chunk_size=MSGPACK_VREFBUFFER_CHUNK_SIZE)
Definition: vrefbuffer.hpp:56
Definition: vrefbuffer.hpp:45
void clear()
Definition: vrefbuffer.hpp:246