// File: mh0fm4[P]SCDC/src/components/transport/transport_uds.cc
// Function: scdc_transport_uds::receive(scdc_transport_connection_t*, void*, long long)
scdcint_t scdc_transport_uds::receive(scdc_transport_connection_t *conn, void *buf, scdcint_t max_buf_size)
{
  SCDC_TRACE("receive: conn: '" << conn << "', buf: '" << buf << "', max_buf_size: " << max_buf_size);

  scdc_transport_uds_connection_t *uds_conn = static_cast<scdc_transport_uds_connection_t *>(conn);

  if (max_buf_size <= 0)
  {
    SCDC_TRACE("connection: " << uds_conn << ": receive: nothing to receive");
    return 0;
  }

  scdcint_t n = 0;

  bool except = false;

#if SCDC_TRANSPORT_UDS_USE_SHUTDOWN_EXCEPTION
  try
  {
#endif

do_recv:
    n = ::recv(uds_conn->socket, buf, max_buf_size, 0);

    if (n < 0 && errno == EINTR)
    {
      SCDC_TRACE("receive: continuing after EINTR");
      goto do_recv;
    }

#if SCDC_TRANSPORT_UDS_USE_SHUTDOWN_EXCEPTION
  } catch (const scdc_transport_uds_shutdown_ex &ex)
  {
    SCDC_INFO("connection " << uds_conn << ": receive: catch shutdown receive");
    n = -1;
    except = false;
  }
#endif

  if (n < 0)
  {
    if (!except) SCDC_ERROR("connection: " << uds_conn << ": receive: receive failed: '" << strerror(errno) << "'");
    return -1;
  }

  SCDC_TRACE("connection " << uds_conn << ": receive: received " << n << " byte(s)");

  /* receiving 0 bytes signals that the socket was closed */
  if (n == 0) n = -1;

  return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
jmp 0x9d09a
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jg 0x9d0ba
jmp 0x9d0ab
jmp 0x9d0ad
movq $0x0, -0x8(%rbp)
jmp 0x9d202
movq $0x0, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x30(%rbp), %rax
movl 0x2d4(%rax), %edi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc1c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x9d0fa
callq 0xc080
cmpl $0x4, (%rax)
jne 0x9d0fa
jmp 0x9d0f6
jmp 0x9d0f8
jmp 0x9d0c6
cmpq $0x0, -0x38(%rbp)
jge 0x9d1e7
testb $0x1, -0x39(%rbp)
jne 0x9d1dd
jmp 0x9d111
leaq 0x37590(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9d1d9
leaq 0x37577(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x37568(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0x9356(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xcc1b(%rip), %rsi      # 0xa9d7c
callq 0xc670
movq %rax, %rdi
leaq 0xca1b(%rip), %rsi      # 0xa9b8b
callq 0xc670
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0xc4f0
movq %rax, %rdi
leaq 0xcbbf(%rip), %rsi      # 0xa9d4a
callq 0xc670
movq %rax, -0x48(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xb21d(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x36dfb(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x374d7(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9d1db
jmp 0x9d1dd
movq $-0x1, -0x8(%rbp)
jmp 0x9d202
jmp 0x9d1e9
jmp 0x9d1eb
cmpq $0x0, -0x38(%rbp)
jne 0x9d1fa
movq $-0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)