| 65 | } |
| 66 | |
| 67 | int zmq::v2_decoder_t::size_ready (uint64_t msg_size_, |
| 68 | unsigned char const *read_pos_) |
| 69 | { |
| 70 | // Message size must not exceed the maximum allowed size. |
| 71 | if (_max_msg_size >= 0) |
| 72 | if (unlikely (msg_size_ > static_cast<uint64_t> (_max_msg_size))) { |
| 73 | errno = EMSGSIZE; |
| 74 | return -1; |
| 75 | } |
| 76 | |
| 77 | // Message size must fit into size_t data type. |
| 78 | if (unlikely (msg_size_ != static_cast<size_t> (msg_size_))) { |
| 79 | errno = EMSGSIZE; |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | int rc = _in_progress.close (); |
| 84 | assert (rc == 0); |
| 85 | |
| 86 | // the current message can exceed the current buffer. We have to copy the buffer |
| 87 | // data into a new message and complete it in the next receive. |
| 88 | |
| 89 | shared_message_memory_allocator &allocator = get_allocator (); |
| 90 | if (unlikely (!_zero_copy |
| 91 | || msg_size_ > static_cast<size_t> ( |
| 92 | allocator.data () + allocator.size () - read_pos_))) { |
| 93 | // a new message has started, but the size would exceed the pre-allocated arena |
| 94 | // this happens every time when a message does not fit completely into the buffer |
| 95 | rc = _in_progress.init_size (static_cast<size_t> (msg_size_)); |
| 96 | } else { |
| 97 | // construct message using n bytes from the buffer as storage |
| 98 | // increase buffer ref count |
| 99 | // if the message will be a large message, pass a valid refcnt memory location as well |
| 100 | rc = |
| 101 | _in_progress.init (const_cast<unsigned char *> (read_pos_), |
| 102 | static_cast<size_t> (msg_size_), |
| 103 | shared_message_memory_allocator::call_dec_ref, |
| 104 | allocator.buffer (), allocator.provide_content ()); |
| 105 | |
| 106 | // For small messages, data has been copied and refcount does not have to be increased |
| 107 | if (_in_progress.is_zcmsg ()) { |
| 108 | allocator.advance_content (); |
| 109 | allocator.inc_ref (); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (unlikely (rc)) { |
| 114 | errno_assert (errno == ENOMEM); |
| 115 | rc = _in_progress.init (); |
| 116 | errno_assert (rc == 0); |
| 117 | errno = ENOMEM; |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | _in_progress.set_flags (_msg_flags); |
| 122 | // this sets read_pos to |
| 123 | // the message data address if the data needs to be copied |
| 124 | // for small message / messages exceeding the current buffer |
nothing calls this directly
no test coverage detected