// File: JianjiaoSQ[P]MyPoorWebServer/webserver.cpp
// Function: WebServer::dealwithwrite(int)
void WebServer::dealwithwrite(int sockfd)
{
    tw_timer *timer = users_timer[sockfd].timer;
    //reactor
    if (1 == m_actormodel)
    {
        if (timer)
        {
            adjust_timer(timer);
        }

        m_pool->append(users + sockfd, 1);

        while (true)
        {
            if (1 == users[sockfd].improv)
            {
                if (1 == users[sockfd].timer_flag)
                {
                    deal_timer(timer, sockfd);
                    users[sockfd].timer_flag = 0;
                }
                users[sockfd].improv = 0;
                break;
            }
        }
    }
    else
    {
        //proactor
        if (users[sockfd].write())
        {
            LOG_INFO("send data to the client(%s)", inet_ntoa(users[sockfd].get_address()->sin_addr));

            if (timer)
            {
                adjust_timer(timer);
            }
        }
        else
        {
            deal_timer(timer, sockfd);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq 0x1d580(%rcx), %rax
movslq -0xc(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x1, %eax
cmpl 0x18(%rcx), %eax
jne 0xc41e
cmpq $0x0, -0x18(%rbp)
je 0xc363
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbcf0
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rdi
movq 0x28(%rax), %rsi
movslq -0xc(%rbp), %rax
imulq $0xf68, %rax, %rax      # imm = 0xF68
addq %rax, %rsi
movl $0x1, %edx
callq 0xcb50
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0xc(%rbp), %rax
imulq $0xf68, %rax, %rax      # imm = 0xF68
addq %rax, %rcx
movl $0x1, %eax
cmpl 0x4(%rcx), %eax
jne 0xc414
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0xc(%rbp), %rax
imulq $0xf68, %rax, %rax      # imm = 0xF68
addq %rax, %rcx
movl $0x1, %eax
cmpl (%rcx), %eax
jne 0xc3f5
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0xbd60
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0xf68, %rcx, %rcx      # imm = 0xF68
addq %rcx, %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0xf68, %rcx, %rcx      # imm = 0xF68
addq %rcx, %rax
movl $0x0, 0x4(%rax)
jmp 0xc419
jmp 0xc38a
jmp 0xc4ce
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0xc(%rbp), %rax
imulq $0xf68, %rax, %rax      # imm = 0xF68
addq %rax, %rdi
callq 0x6560
testb $0x1, %al
jne 0xc43f
jmp 0xc4bc
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpl 0x14(%rcx), %eax
jne 0xc4a6
callq 0x6df0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq 0x28(%rax), %rdi
movslq -0xc(%rbp), %rax
imulq $0xf68, %rax, %rax      # imm = 0xF68
addq %rax, %rdi
callq 0xcbf0
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edi
callq 0x31d0
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movl $0x1, %esi
leaq 0x20b4(%rip), %rdx      # 0xe546
movb $0x0, %al
callq 0x9300
callq 0x6df0
movq %rax, %rdi
callq 0x9870
cmpq $0x0, -0x18(%rbp)
je 0xc4ba
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbcf0
jmp 0xc4cc
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0xbd60
jmp 0xc4ce
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)