// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/httpudp.c
// Function: outputToClient
static int outputToClient(info_t * client)
{
    char *dataPtr;
    int write_len;

    if (client->responseClientFd < 0 && createRspFd(client) < 0)
        return 1;

    client->timer = 0;
    dataPtr = client->rsp_data;
    //至少要有一个完整的udp包才返回客户端
    while ((int)(*(uint16_t *) dataPtr + sizeof(uint16_t)) <= client->rsp_data_len) {
        write_len = sendto(client->responseClientFd, dataPtr + sizeof(uint16_t) + client->rsp_data_sent_len, *(uint16_t *) dataPtr - client->rsp_data_sent_len, 0, (struct sockaddr *)&client->inaddr, sizeof(struct sockaddr_in));
        //printf("rsp: [write_len:%d, dataLen:%u, sent:%u, total:%d]\n", write_len, *(uint16_t *)dataPtr, client->rsp_data_sent_len, client->rsp_data_len);
        if (write_len < 0 && errno == EAGAIN)
            return 0;
        client->rsp_data_sent_len += write_len;
        if (write_len == 0 || write_len < 0) {
            //perror("toClient write()");
            return 1;
        }
        if (write_len < *(uint16_t *) dataPtr) {
            udp_ev.data.ptr = client;
            udp_ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
            epoll_ctl(udp_efd, EPOLL_CTL_ADD, client->responseClientFd, &udp_ev);
            return 0;
        }
        dataPtr += write_len + sizeof(uint16_t);
        client->rsp_data_len -= write_len + sizeof(uint16_t);
        client->rsp_data_sent_len = 0;
    }
    //发送完已读取到的所有数据  释放内存
    if (client->rsp_data_len == 0) {
        free(client->rsp_data);
        client->rsp_data = NULL;
        udp_ev.data.ptr = client;
        udp_ev.events = EPOLLIN | EPOLLET;
        epoll_ctl(udp_efd, EPOLL_CTL_MOD, client->responseClientFd, &udp_ev);
    }
    //还有数据未返回给客户端，将未返回的数据复制到内存头
    else if (dataPtr > client->rsp_data) {
        memmove(client->rsp_data, dataPtr, client->rsp_data_len);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10060(%rax)
jge 0x9c03
movq -0x10(%rbp), %rdi
callq 0x9e10
cmpl $0x0, %eax
jge 0x9c03
movl $0x1, -0x4(%rbp)
jmp 0x9dfd
movq -0x10(%rbp), %rax
movl $0x0, 0x10064(%rax)
movq -0x10(%rbp), %rax
movq 0x10040(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
addq $0x2, %rax
movq -0x10(%rbp), %rcx
cmpl 0x10054(%rcx), %eax
jg 0x9d60
movq -0x10(%rbp), %rax
movl 0x10060(%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
movq -0x10(%rbp), %rax
movslq 0x10058(%rax), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10058(%rcx), %eax
movslq %eax, %rdx
movq -0x10(%rbp), %r8
addq $0x10014, %r8           # imm = 0x10014
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x21e0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x9ca6
callq 0x2050
cmpl $0xb, (%rax)
jne 0x9ca6
movl $0x0, -0x4(%rbp)
jmp 0x9dfd
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x10058(%rax), %ecx
movl %ecx, 0x10058(%rax)
cmpl $0x0, -0x1c(%rbp)
je 0x9cc5
cmpl $0x0, -0x1c(%rbp)
jge 0x9cd1
movl $0x1, -0x4(%rbp)
jmp 0x9dfd
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x9d21
movq -0x10(%rbp), %rax
movq %rax, 0x2069cae(%rip)   # 0x2073998
movl $0x80000005, 0x2069ca0(%rip) # imm = 0x80000005
movl 0x2069c96(%rip), %edi   # 0x2073990
movq -0x10(%rbp), %rax
movl 0x10060(%rax), %edx
movl $0x1, %esi
leaq 0x2069c84(%rip), %rcx   # 0x2073994
callq 0x2240
movl $0x0, -0x4(%rbp)
jmp 0x9dfd
movslq -0x1c(%rbp), %rax
addq $0x2, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movslq -0x1c(%rbp), %rdx
addq $0x2, %rdx
movq -0x10(%rbp), %rax
movslq 0x10054(%rax), %rcx
subq %rdx, %rcx
movl %ecx, 0x10054(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10058(%rax)
jmp 0x9c20
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10054(%rax)
jne 0x9dc4
movq -0x10(%rbp), %rax
movq 0x10040(%rax), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
movq $0x0, 0x10040(%rax)
movq -0x10(%rbp), %rax
movq %rax, 0x2069c01(%rip)   # 0x2073998
movl $0x80000001, 0x2069bf3(%rip) # imm = 0x80000001
movl 0x2069be9(%rip), %edi   # 0x2073990
movq -0x10(%rbp), %rax
movl 0x10060(%rax), %edx
movl $0x3, %esi
leaq 0x2069bd7(%rip), %rcx   # 0x2073994
callq 0x2240
jmp 0x9df6
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10040(%rcx), %rax
jbe 0x9df4
movq -0x10(%rbp), %rax
movq 0x10040(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x10054(%rax), %rdx
callq 0x2450
jmp 0x9df6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)