// File: /workspace/github_c_makefile_star2_O3/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 0x37d0
leaq 0xbafe(%rip), %rax      # 0xf2b0
movq (%rax), %rdi
callq 0x36d3
testq %rax, %rax
jne 0x3a1a
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 0x6f11(%rip), %rdi      # 0xa702
xorl %eax, %eax
callq 0x6c74
cmpq $0x0, 0x40(%rbx)
je 0x38de
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 0x6efa(%rip), %rdi      # 0xa736
xorl %eax, %eax
callq 0x6c74
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 0x39bd
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)
movq $0x0, 0xe(%rax)
movq 0x50(%rbx), %rdi
movq 0x60(%rbx), %rsi
callq 0x3ba8
movl %eax, 0x68(%rbx)
testl %eax, %eax
je 0x38d2
movq 0x60(%rbx), %rsi
leaq 0x6e11(%rip), %rdi      # 0xa6da
movl %eax, %edx
xorl %eax, %eax
callq 0x6c74
movq %rbx, %rdi
callq *0x48(%r15)
jmp 0x3a1a
leaq 0x6e41(%rip), %rdi      # 0xa726
xorl %eax, %eax
callq 0x6c74
movq 0x50(%r15), %rdi
callq 0x7ca0
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x39d9
movl $0x10, 0x58(%rbx)
movl $0x10, %esi
movq %rax, %rdi
callq 0x7cd0
movq %rax, 0x50(%rbx)
movq 0x40(%rbx), %rdi
testq %rax, %rax
je 0x3a0d
movl $0x16, %esi
callq 0x7cd0
movq %rax, 0x60(%rbx)
movq 0x40(%rbx), %rdi
testq %rax, %rax
je 0x3a0d
movl $0x38, %esi
callq 0x7d16
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x3a09
movq 0x50(%r15), %rcx
movq 0x40(%rbx), %rdi
subq %rax, %rcx
leaq (%rcx,%rdi), %r14
addq $-0x38, %r14
movq %r14, %rsi
callq 0x7cf7
movq 0x20(%rbx), %rcx
movq %rax, 0x20(%rcx)
testq %rax, %rax
je 0x3a09
movq %rax, (%rcx)
movq %rax, 0x8(%rcx)
addq %rax, %r14
movq %r14, 0x28(%rcx)
orb $0x1, 0x30(%rcx)
orb $0x40, 0x98(%rbx)
leaq 0x522b(%rip), %rax      # 0x8bd0
movq %rax, 0x30(%rbx)
leaq 0x4(%r15), %rax
movq %rax, 0x70(%rbx)
movl 0x14(%r15), %eax
movl %eax, 0x78(%rbx)
jmp 0x3803
callq 0x2030
movl (%rax), %edi
cmpl $0xb, %edi
jne 0x39f9
leaq 0x6d78(%rip), %rdi      # 0xa748
xorl %eax, %eax
callq 0x6c74
jmp 0x3a1a
movq 0x50(%r15), %rdx
leaq 0x687d(%rip), %rsi      # 0xa261
xorl %edi, %edi
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6b27
leaq 0x6d5c(%rip), %rsi      # 0xa75c
xorl %eax, %eax
callq 0x6b27
jmp 0x3a1a
movq 0x40(%rbx), %rdi
callq 0x2338
movq $0x0, 0x40(%rbx)
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop