// File: mh0fm4[P]SCDC/src/components/transport/transport_uds.cc
// Function: scdc_transport_uds::connect(char const*)
scdc_transport_connection_t *scdc_transport_uds::connect(const char *socketfile)
{
  SCDC_TRACE("connect: socketfile: '" << socketfile << "'");

  scdc_transport_uds_connection_t *uds_conn = new scdc_transport_uds_connection_t(this);

  uds_conn->socket = ::socket(PF_LOCAL, SOCK_STREAM, 0);
  if (uds_conn->socket == -1)
  {
    SCDC_ERROR("start: creating client socket failed: '" << strerror(errno) << "'");
    return 0;
  }

  struct sockaddr_un saddr;
  memset(&saddr, 0, sizeof(saddr));

  saddr.sun_family = AF_LOCAL;
  strcpy(saddr.sun_path, socketfile);

  int r;
  bool except = false;

#if SCDC_TRANSPORT_UDS_USE_SHUTDOWN_EXCEPTION
  try
  {
#endif
    r = ::connect(uds_conn->socket, (struct sockaddr *) &saddr, sizeof(saddr));

#if SCDC_TRANSPORT_UDS_USE_SHUTDOWN_EXCEPTION
  } catch (const scdc_transport_uds_shutdown_ex &ex)
  {
    SCDC_INFO("connect: catch shutdown exception");
    r = -1;
    except = true;
  }
#endif

  if (r == -1)
  {
    if (!except) SCDC_FAIL("connect: connecting to server failed: '" << strerror(errno) << "'");
    ::close(uds_conn->socket);
    delete uds_conn;
    return 0;
  }

  return scdc_transport::connect(uds_conn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x9cbb0
movl $0x2d8, %edi            # imm = 0x2D8
callq 0xc690
movq -0xb0(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
callq 0x9d260
jmp 0x9cbd5
movq -0xb8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0xc130
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2d4(%rax)
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x2d4(%rax)
jne 0x9ccf3
jmp 0x9cc0d
leaq 0x37a94(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9cce4
leaq 0x37a7b(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x37a6c(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0x985a(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xd11f(%rip), %rsi      # 0xa9d7c
callq 0xc670
movq %rax, %rdi
leaq 0xd120(%rip), %rsi      # 0xa9d8c
callq 0xc670
movq %rax, -0xc0(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xb736(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x37314(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x379f0(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9cce4
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x2d8, %esi            # imm = 0x2D8
callq 0xc6a0
jmp 0x9ce86
jmp 0x9cce6
movq $0x0, -0x8(%rbp)
jmp 0x9ce79
leaq -0x9a(%rbp), %rdi
xorl %esi, %esi
movl $0x6e, %edx
callq 0xc350
movw $0x1, -0x9a(%rbp)
leaq -0x9a(%rbp), %rdi
addq $0x2, %rdi
movq -0x18(%rbp), %rsi
callq 0xc610
movb $0x0, -0xa1(%rbp)
movq -0x20(%rbp), %rax
movl 0x2d4(%rax), %edi
leaq -0x9a(%rbp), %rsi
movl $0x6e, %edx
callq 0xc540
movl %eax, -0xa0(%rbp)
cmpl $-0x1, -0xa0(%rbp)
jne 0x9ce65
testb $0x1, -0xa1(%rbp)
jne 0x9ce1e
jmp 0x9cd67
leaq 0x3793a(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0x9ce1a
leaq 0x37921(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x37912(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x9408(%rip), %rsi      # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0xcfc5(%rip), %rsi      # 0xa9d7c
callq 0xc670
movq %rax, %rdi
leaq 0xcf45(%rip), %rsi      # 0xa9d0b
callq 0xc670
movq %rax, -0xc8(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xb5dc(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x371ba(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x37896(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0x9ce1c
jmp 0x9ce1e
movq -0x20(%rbp), %rax
movl 0x2d4(%rax), %edi
callq 0xccd0
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x9ce5b
movq -0xd0(%rbp), %rdi
callq 0x9d2a0
movq -0xd0(%rbp), %rdi
movl $0x2d8, %esi            # imm = 0x2D8
callq 0xc6a0
movq $0x0, -0x8(%rbp)
jmp 0x9ce79
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x98d80
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0xcba0
nop