// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x10060(%rdi)
jns 0x75c4
movl $0x1, 0xc(%rsp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x2550
movl %eax, 0x10060(%rbx)
testl %eax, %eax
js 0x75c4
movl %eax, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x20d0
movl 0x10060(%rbx), %edi
leaq 0xc(%rsp), %r14
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x20b0
movl 0x10060(%rbx), %edi
xorl %esi, %esi
movl $0x13, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x20b0
xorl %edi, %edi
callq 0x2560
cmpl $-0x1, %eax
je 0x7741
xorl %edi, %edi
callq 0x2520
cmpl $-0x1, %eax
je 0x7752
movl 0x10060(%rbx), %edi
leaq 0x10024(%rbx), %rsi
movl $0x10, %edx
callq 0x2410
leaq 0x11de0(%rip), %r14     # 0x19380
movl 0xc(%r14), %edi
callq 0x2520
cmpl $-0x1, %eax
je 0x7763
movl 0xc(%r14), %edi
callq 0x2560
cmpl $-0x1, %eax
je 0x7774
movl $0x0, 0x10064(%rbx)
movq 0x10040(%rbx), %r14
movzwl (%r14), %ecx
leal 0x2(%rcx), %edx
movl 0x10054(%rbx), %eax
cmpl %eax, %edx
jle 0x7610
movq 0x10040(%rbx), %rdi
testl %eax, %eax
je 0x76ad
xorl %ebp, %ebp
cmpq %rdi, %r14
jbe 0x7732
movslq %eax, %rdx
movq %r14, %rsi
callq 0x2430
jmp 0x7732
leaq 0x10014(%rbx), %r15
movl 0x10058(%rbx), %edx
movl 0x10060(%rbx), %edi
movslq %edx, %rax
leaq (%r14,%rax), %rsi
addq $0x2, %rsi
subl %eax, %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x21c0
movq %rax, %r12
testl %r12d, %r12d
js 0x76e8
addl %r12d, 0x10058(%rbx)
testl %r12d, %r12d
je 0x76fb
movzwl (%r14), %eax
cmpl %eax, %r12d
jb 0x7702
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
addq %r12, %r14
addq $0x2, %r14
addq $0x2, %r12
movl 0x10054(%rbx), %eax
subl %r12d, %eax
movl %eax, 0x10054(%rbx)
movl $0x0, 0x10058(%rbx)
movzwl (%r14), %ecx
leal 0x2(%rcx), %esi
xorl %edx, %edx
cmpl %eax, %esi
jle 0x761d
jmp 0x75e6
callq 0x2030
movq $0x0, 0x10040(%rbx)
movq %rbx, 0x2069284(%rip)   # 0x2070948
leaq 0x2069279(%rip), %rcx   # 0x2070944
movl $0x80000001, 0x206926f(%rip) # imm = 0x80000001
movl 0x2069265(%rip), %edi   # 0x2070940
movl 0x10060(%rbx), %edx
movl $0x3, %esi
jmp 0x772b
callq 0x2050
xorl %ebp, %ebp
cmpl $0xb, (%rax)
je 0x7732
addl %r12d, 0x10058(%rbx)
movl $0x1, %ebp
jmp 0x7732
movq %rbx, 0x206923f(%rip)   # 0x2070948
leaq 0x2069234(%rip), %rcx   # 0x2070944
movl $0x80000005, 0x206922a(%rip) # imm = 0x80000005
movl 0x2069220(%rip), %edi   # 0x2070940
movl 0x10060(%rbx), %edx
movl $0x1, %esi
callq 0x2220
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cfa(%rip), %rdi      # 0x9442
callq 0x2460
jmp 0x7572
leaq 0x1cf1(%rip), %rdi      # 0x944a
callq 0x2460
jmp 0x7582
leaq 0x1ce0(%rip), %rdi      # 0x944a
callq 0x2460
jmp 0x75b2
leaq 0x1cc7(%rip), %rdi      # 0x9442
callq 0x2460
jmp 0x75c4
nopl (%rax)