MCPcopy Create free account
hub / github.com/COVESA/vsomeip / receive

Method receive

implementation/endpoints/src/tcp_server_endpoint_impl.cpp:517–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517void tcp_server_endpoint_impl::connection::receive() {
518 std::unique_lock its_lock(socket_mutex_);
519 if (socket_->is_open()) {
520 const std::size_t its_capacity(recv_buffer_.capacity());
521 if (recv_buffer_size_ > its_capacity) {
522 VSOMEIP_ERROR_P << "Received buffer size is greater than the buffer capacity! recv_buffer_size_: " << recv_buffer_size_
523 << " its_capacity: " << its_capacity;
524 return;
525 }
526 size_t left_buffer_size = its_capacity - recv_buffer_size_;
527 try {
528 if (missing_capacity_) {
529 if (missing_capacity_ > max_message_size_) {
530 VSOMEIP_ERROR_P << instance_name_ << "Missing receive buffer capacity exceeds allowed maximum: " << missing_capacity_
531 << " local: " << get_address_port_local() << " remote: " << get_address_port_remote();
532 its_lock.unlock();
533 wait_until_sent(boost::asio::error::operation_aborted);
534 return;
535 }
536 const std::size_t its_required_capacity(recv_buffer_size_ + missing_capacity_);
537 if (its_capacity < its_required_capacity) {
538 // Make the resize to its_required_capacity
539 recv_buffer_.reserve(its_required_capacity);
540 recv_buffer_.resize(its_required_capacity, 0x0);
541 if (recv_buffer_.size() > 1048576) {
542 VSOMEIP_INFO_P << instance_name_ << "recv_buffer size is: " << recv_buffer_.size()
543 << " local: " << get_address_port_local() << " remote: " << get_address_port_remote();
544 }
545 }
546 left_buffer_size = missing_capacity_;
547 missing_capacity_ = 0;
548 } else if (buffer_shrink_threshold_ && shrink_count_ > buffer_shrink_threshold_ && recv_buffer_size_ == 0) {
549 // In this case, make the resize to recv_buffer_size_initial_
550 recv_buffer_.resize(recv_buffer_size_initial_, 0x0);
551 recv_buffer_.shrink_to_fit();
552 // And set buffer_size to recv_buffer_size_initial_, the same of our resize
553 left_buffer_size = recv_buffer_size_initial_;
554 shrink_count_ = 0;
555 }
556 } catch (const std::exception& e) {
557 handle_recv_buffer_exception(e);
558 its_lock.unlock();
559 wait_until_sent(boost::asio::error::operation_aborted);
560 return;
561 }
562
563 socket_->async_receive(boost::asio::buffer(&recv_buffer_[recv_buffer_size_], left_buffer_size),
564 std::bind(&tcp_server_endpoint_impl::connection::receive_cbk, shared_from_this(), std::placeholders::_1,
565 std::placeholders::_2));
566 }
567}
568
569void tcp_server_endpoint_impl::connection::stop() {
570 std::scoped_lock its_lock(socket_mutex_);

Callers

nothing calls this directly

Calls 7

bufferClass · 0.85
capacityMethod · 0.80
unlockMethod · 0.80
resizeMethod · 0.80
is_openMethod · 0.45
sizeMethod · 0.45
async_receiveMethod · 0.45

Tested by

no test coverage detected