// File: /workspace/github_cpp_makefile_star2_O3/JianjiaoSQ[P]MyPoorWebServer/http/http_conn.cpp
// Function: http_conn::write()
bool http_conn::write()
{
    int temp = 0;

    if (bytes_to_send == 0)
    {
        modfd(m_epollfd, m_sockfd, EPOLLIN, m_TRIGMode);
        init();
        return true;
    }

    while (1)
    {
        temp = writev(m_sockfd, m_iv, m_iv_count);

        if (temp < 0)
        {
            if (errno == EAGAIN)
            {
                modfd(m_epollfd, m_sockfd, EPOLLOUT, m_TRIGMode);
                return true;
            }
            unmap();
            return false;
        }

        bytes_have_send += temp;
        bytes_to_send -= temp;
        if (bytes_have_send >= m_iv[0].iov_len)
        {
            m_iv[0].iov_len = 0;
            m_iv[1].iov_base = m_file_address + (bytes_have_send - m_write_idx);
            m_iv[1].iov_len = bytes_to_send;
        }
        else
        {
            m_iv[0].iov_base = m_write_buf + bytes_have_send;
            m_iv[0].iov_len = m_iv[0].iov_len - bytes_have_send;
        }

        if (bytes_to_send <= 0)
        {
            unmap();
            modfd(m_epollfd, m_sockfd, EPOLLIN, m_TRIGMode);

            if (m_linger) // 写完之后是否保持连接
            {
                init();
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x0, 0xdf0(%rdi)
je 0x533c
leaq 0xdc0(%rbx), %r14
leaq 0x834(%rbx), %r15
movl 0x14(%rbx), %edi
movl 0xde0(%rbx), %edx
movq %r14, %rsi
callq 0x3200
testl %eax, %eax
js 0x539f
movslq 0xdf4(%rbx), %rcx
movslq %eax, %rdx
addq %rdx, %rcx
movl %ecx, 0xdf4(%rbx)
movslq 0xdf0(%rbx), %rax
subq %rdx, %rax
movl %eax, 0xdf0(%rbx)
movq 0xdc8(%rbx), %rdx
subq %rcx, %rdx
jbe 0x5299
addq %r15, %rcx
movq %rcx, (%r14)
jmp 0x52bd
movslq 0xc34(%rbx), %rdx
movslq %ecx, %rcx
subq %rdx, %rcx
addq 0xd28(%rbx), %rcx
movq %rcx, 0xdd0(%rbx)
movq %rax, 0xdd8(%rbx)
xorl %edx, %edx
movq %rdx, 0xdc8(%rbx)
testl %eax, %eax
jg 0x5249
movq 0xd28(%rbx), %rdi
testq %rdi, %rdi
je 0x52eb
movq 0xd60(%rbx), %rsi
callq 0x3230
movq $0x0, 0xd28(%rbx)
movl 0x80cf(%rip), %edi      # 0xd3c0
movl 0x14(%rbx), %edx
movl 0xe30(%rbx), %eax
leaq 0x4(%rsp), %rcx
movl %edx, 0x4(%rcx)
xorl %esi, %esi
cmpl $0x1, %eax
setne %sil
shll $0x1f, %esi
addl $0xc0002001, %esi       # imm = 0xC0002001
movl %esi, (%rcx)
movl $0x3, %esi
callq 0x34e0
xorl %eax, %eax
cmpb $0x1, 0xd24(%rbx)
jne 0x53e0
movq $0x0, 0xdf0(%rbx)
jmp 0x537e
movl 0x807e(%rip), %edi      # 0xd3c0
movl 0x14(%rbx), %edx
movl 0xe30(%rbx), %eax
leaq 0x4(%rsp), %rcx
movl %edx, 0x4(%rcx)
xorl %esi, %esi
cmpl $0x1, %eax
setne %sil
shll $0x1f, %esi
addl $0xc0002001, %esi       # imm = 0xC0002001
movl %esi, (%rcx)
movl $0x3, %esi
callq 0x34e0
movq $0x0, 0xdf0(%rbx)
xorl %eax, %eax
movl %eax, 0xde4(%rbx)
leaq 0x28(%rbx), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl %eax, 0x10(%rbx)
movl $0xcfd, %edx            # imm = 0xCFD
xorl %esi, %esi
callq 0x3220
jmp 0x53de
callq 0x3050
cmpl $0xb, (%rax)
jne 0x53ea
movl 0x8011(%rip), %edi      # 0xd3c0
movl 0x14(%rbx), %edx
movl 0xe30(%rbx), %eax
leaq 0x4(%rsp), %rcx
movl %edx, 0x4(%rcx)
xorl %esi, %esi
cmpl $0x1, %eax
setne %sil
shll $0x1f, %esi
addl $0xc0002004, %esi       # imm = 0xC0002004
movl %esi, (%rcx)
movl $0x3, %esi
callq 0x34e0
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0xd28(%rbx), %rdi
testq %rdi, %rdi
je 0x540d
movq 0xd60(%rbx), %rsi
callq 0x3230
movq $0x0, 0xd28(%rbx)
xorl %eax, %eax
jmp 0x53e0
nop