// File: /workspace/github_c_makefile_star2_O2/qq-smart[P]qq_sh_server/event/qq_event_accept.c
// Function: qq_event_recvmsg
void
qq_event_recvmsg(qq_event_t *ev)
{
    ssize_t            n;
    size_t             size;
    qq_err_t           err;
    struct iovec       iov[1];
    struct msghdr      msg;
    struct sockaddr    sa;
    qq_listening_t    *ls;
    qq_connection_t   *c;

    if (ev->timedout) {
        if (qq_enable_accept_events((qq_cycle_t *) qq_cycle) != QQ_OK) {
            return;
        }
        ev->timedout = 0;
    }

    c = ev->data;
    ls = c->listening;
    ev->ready = 0;

    qq_log_debug("qq_event_recvmsg() on %s, ready: %d", ls->addr_text, ev->available);

    if (c->pool == NULL) {
        qq_log_debug("c->pool == NULL");

        c->pool = qq_create_pool(ls->pool_size);
        if (c->pool == NULL) {
            qq_log_error(0, "qq_create_pool(%d) failed", ls->pool_size);
            return;
        }

        c->socklen = sizeof(struct sockaddr);
        c->sockaddr = qq_palloc(c->pool, c->socklen);
        if (c->sockaddr == NULL) {
            qq_destroy_pool(c->pool);
            c->pool = NULL;
            return;
        }

        c->addr_text = qq_palloc(c->pool, QQ_SOCKADDR_STRLEN);
        if (c->addr_text == NULL) {
            qq_destroy_pool(c->pool);
            c->pool = NULL;
            return;
        }

        c->buffer = qq_pcalloc(c->pool, sizeof(qq_buf_t));
        if (c->buffer == NULL) {
            qq_destroy_pool(c->pool);
            c->pool = NULL;
            return;
        }
        size = ls->pool_size -
            ((size_t)((uintptr_t)c->buffer - (uintptr_t)c->pool) + sizeof(qq_buf_t));
        c->buffer->start = qq_pnalloc(c->pool, size);
        if (c->buffer->start == NULL) {
            qq_destroy_pool(c->pool);
            c->pool = NULL;
            return;
        }
        c->buffer->pos = c->buffer->start;
        c->buffer->last = c->buffer->start;
        c->buffer->end = c->buffer->last + size;
        c->buffer->temporary = 1;

        c->shared = 1;
        c->send = qq_udp_send;
        c->local_sockaddr = (struct sockaddr *) &ls->sockaddr;
        c->local_socklen = ls->socklen;
    }

    memset(&msg, 0, sizeof(struct msghdr));

    iov[0].iov_base = (void *) c->buffer->pos;
    iov[0].iov_len = c->buffer->end - c->buffer->start;
    qq_log_debug("recvmsg(size: %d)", c->buffer->end - c->buffer->start);

    msg.msg_name = &sa;
    msg.msg_namelen = sizeof(struct sockaddr);
    msg.msg_iov = iov;
    msg.msg_iovlen = 1;

    n = recvmsg(c->fd, &msg, 0);

    if (n == -1) {
        err = errno;
        if (err == QQ_EAGAIN) {
            qq_log_debug("recvmsg() not ready");
            return;
        }

        qq_log_error(err, "recvmsg() failed");
        return;
    }

    memcpy(c->sockaddr, msg.msg_name, c->socklen);

    c->buffer->last += n;

    c->write->ready = 1;

    memset(c->addr_text, 0, QQ_SOCKADDR_STRLEN);
    c->addr_text_len = qq_sock_ntop((struct sockaddr_in *)c->sockaddr, c->addr_text);
    if (c->addr_text_len != 0) {
        qq_log_debug("connection address: %s, address len: %d",
            c->addr_text, c->addr_text_len);
    }

    ls->handler(c);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rdi, %r14
movl 0x8(%rdi), %edx
btl $0xa, %edx
jae 0x3728
leaq 0xaba6(%rip), %rax      # 0xe2b0
movq (%rax), %rdi
callq 0x363c
testq %rax, %rax
jne 0x3966
movl $0xfffffbff, %edx       # imm = 0xFFFFFBFF
andl 0x8(%r14), %edx
movl %edx, 0x8(%r14)
movq (%r14), %rbx
movq 0x38(%rbx), %r15
movl %edx, %eax
andl $-0x21, %eax
movl %eax, 0x8(%r14)
leaq 0x18(%r15), %rsi
shrl $0x14, %edx
andl $0x1, %edx
leaq 0x5fb9(%rip), %rdi      # 0x9702
xorl %eax, %eax
callq 0x6706
cmpq $0x0, 0x40(%rbx)
je 0x3833
xorps %xmm0, %xmm0
leaq -0x78(%rbp), %r14
movups %xmm0, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movups %xmm0, 0x8(%r14)
movq 0x20(%rbx), %rax
movq (%rax), %rcx
leaq -0x30(%rbp), %r12
movq %rcx, (%r12)
movq 0x28(%rax), %rsi
subq 0x20(%rax), %rsi
movq %rsi, 0x8(%r12)
leaq 0x5fa2(%rip), %rdi      # 0x9736
xorl %eax, %eax
callq 0x6706
leaq -0x40(%rbp), %rax
movq %rax, (%r14)
movl $0x10, 0x8(%r14)
movq %r12, 0x10(%r14)
movq $0x1, 0x18(%r14)
movl 0x18(%rbx), %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2090
cmpq $-0x1, %rax
je 0x390c
movq %rax, %r14
movq 0x50(%rbx), %rdi
movq -0x78(%rbp), %rsi
movl 0x58(%rbx), %edx
callq 0x21c0
movq 0x20(%rbx), %rax
addq %r14, 0x8(%rax)
movq 0x10(%rbx), %rax
orl $0x20, 0x8(%rax)
movq 0x60(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0xe(%rax)
movq 0x50(%rbx), %rdi
movq 0x60(%rbx), %rsi
callq 0x3ae8
movl %eax, 0x68(%rbx)
testl %eax, %eax
je 0x3827
movq 0x60(%rbx), %rsi
leaq 0x5ebc(%rip), %rdi      # 0x96da
movl %eax, %edx
xorl %eax, %eax
callq 0x6706
movq %rbx, %rdi
callq *0x48(%r15)
jmp 0x3966
leaq 0x5eec(%rip), %rdi      # 0x9726
xorl %eax, %eax
callq 0x6706
movq 0x50(%r15), %rdi
callq 0x7620
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x3928
movl $0x10, 0x58(%rbx)
pushq $0x10
popq %rsi
movq %rax, %rdi
callq 0x764e
movq %rax, 0x50(%rbx)
movq 0x40(%rbx), %rdi
testq %rax, %rax
je 0x395c
pushq $0x16
popq %rsi
callq 0x764e
movq %rax, 0x60(%rbx)
movq 0x40(%rbx), %rdi
testq %rax, %rax
je 0x395c
pushq $0x38
popq %rsi
callq 0x7694
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x3958
movq 0x50(%r15), %rcx
movq 0x40(%rbx), %rdi
subq %rax, %rcx
leaq (%rcx,%rdi), %r14
addq $-0x38, %r14
movq %r14, %rsi
callq 0x7675
movq 0x20(%rbx), %rcx
movq %rax, 0x20(%rcx)
testq %rax, %rax
je 0x3958
movq %rax, (%rcx)
movq %rax, 0x8(%rcx)
addq %rax, %r14
movq %r14, 0x28(%rcx)
orb $0x1, 0x30(%rcx)
orb $0x40, 0x98(%rbx)
leaq 0x4a98(%rip), %rax      # 0x838c
movq %rax, 0x30(%rbx)
leaq 0x4(%r15), %rax
movq %rax, 0x70(%rbx)
movl 0x14(%r15), %eax
movl %eax, 0x78(%rbx)
jmp 0x375b
callq 0x2030
movl (%rax), %edi
cmpl $0xb, %edi
jne 0x3948
leaq 0x5e29(%rip), %rdi      # 0x9748
xorl %eax, %eax
callq 0x6706
jmp 0x3966
movq 0x50(%r15), %rdx
leaq 0x592e(%rip), %rsi      # 0x9261
xorl %edi, %edi
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x65bd
leaq 0x5e0d(%rip), %rsi      # 0x975c
xorl %eax, %eax
callq 0x65bd
jmp 0x3966
movq 0x40(%rbx), %rdi
callq 0x2348
andq $0x0, 0x40(%rbx)
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop