| 324 | } |
| 325 | |
| 326 | int zmq::msg_t::copy (msg_t &src_) |
| 327 | { |
| 328 | // Check the validity of the source. |
| 329 | if (unlikely (!src_.check ())) { |
| 330 | errno = EFAULT; |
| 331 | return -1; |
| 332 | } |
| 333 | |
| 334 | const int rc = close (); |
| 335 | if (unlikely (rc < 0)) |
| 336 | return rc; |
| 337 | |
| 338 | // The initial reference count, when a non-shared message is initially |
| 339 | // shared (between the original and the copy we create here). |
| 340 | const atomic_counter_t::integer_t initial_shared_refcnt = 2; |
| 341 | |
| 342 | if (src_.is_lmsg () || src_.is_zcmsg ()) { |
| 343 | // One reference is added to shared messages. Non-shared messages |
| 344 | // are turned into shared messages. |
| 345 | if (src_.flags () & msg_t::shared) |
| 346 | src_.refcnt ()->add (1); |
| 347 | else { |
| 348 | src_.set_flags (msg_t::shared); |
| 349 | src_.refcnt ()->set (initial_shared_refcnt); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (src_._u.base.metadata != NULL) |
| 354 | src_._u.base.metadata->add_ref (); |
| 355 | |
| 356 | if (src_._u.base.group.type == group_type_long) |
| 357 | src_._u.base.group.lgroup.content->refcnt.add (1); |
| 358 | |
| 359 | *this = src_; |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | void *zmq::msg_t::data () |
| 365 | { |
no test coverage detected