// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x0, 0x10060(%rdi)
jns 0x7204
movl $0x1, 0x4(%rsp)
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x2550
movl %eax, 0x10060(%rbx)
testl %eax, %eax
js 0x7204
pushq $0x4
popq %rbp
movl %eax, %edi
movl %ebp, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x20d0
movl 0x10060(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
leaq 0x4(%rsp), %r14
movq %r14, %rcx
movl %ebp, %r8d
callq 0x20b0
movl 0x10060(%rbx), %edi
pushq $0x13
popq %rdx
xorl %esi, %esi
movq %r14, %rcx
movl %ebp, %r8d
callq 0x20b0
xorl %edi, %edi
callq 0x2560
cmpl $-0x1, %eax
je 0x7349
xorl %edi, %edi
callq 0x2520
cmpl $-0x1, %eax
je 0x735a
movl 0x10060(%rbx), %edi
leaq 0x10024(%rbx), %rsi
pushq $0x10
popq %rdx
callq 0x2410
leaq 0x121a0(%rip), %r14     # 0x19380
movl 0xc(%r14), %edi
callq 0x2520
cmpl $-0x1, %eax
je 0x736b
movl 0xc(%r14), %edi
callq 0x2560
cmpl $-0x1, %eax
je 0x737c
andl $0x0, 0x10064(%rbx)
movq 0x10040(%rbx), %r14
leaq 0x10014(%rbx), %r15
movl 0x10054(%rbx), %eax
pushq $0x10
popq %r12
pushq $0x1
popq %rbp
movzwl (%r14), %edx
leal 0x2(%rdx), %ecx
cmpl %eax, %ecx
jg 0x72b6
movl 0x10060(%rbx), %edi
movslq 0x10058(%rbx), %rax
leaq (%r14,%rax), %rsi
addq $0x2, %rsi
subq %rax, %rdx
xorl %ecx, %ecx
movq %r15, %r8
movl %r12d, %r9d
callq 0x21c0
movq %rax, %r13
testl %r13d, %r13d
jns 0x7270
callq 0x2050
cmpl $0xb, (%rax)
je 0x7336
addl %r13d, 0x10058(%rbx)
testl %r13d, %r13d
jle 0x7338
movzwl (%r14), %eax
cmpl %eax, %r13d
jb 0x72d5
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
addq %r13, %r14
addq $0x2, %r14
addq $0x2, %r13
movl 0x10054(%rbx), %eax
subl %r13d, %eax
movl %eax, 0x10054(%rbx)
andl $0x0, 0x10058(%rbx)
jmp 0x7226
movq 0x10040(%rbx), %rdi
testl %eax, %eax
je 0x72fd
xorl %ebp, %ebp
cmpq %rdi, %r14
jbe 0x7338
movslq %eax, %rdx
movq %r14, %rsi
callq 0x2430
jmp 0x7338
movq %rbx, 0x206966c(%rip)   # 0x2070948
leaq 0x2069661(%rip), %rcx   # 0x2070944
movl $0x80000005, 0x2069657(%rip) # imm = 0x80000005
movl 0x206964d(%rip), %edi   # 0x2070940
movl 0x10060(%rbx), %edx
pushq $0x1
jmp 0x7330
callq 0x2030
andq $0x0, 0x10040(%rbx)
movq %rbx, 0x2069637(%rip)   # 0x2070948
leaq 0x206962c(%rip), %rcx   # 0x2070944
movl $0x80000001, 0x2069622(%rip) # imm = 0x80000001
movl 0x2069618(%rip), %edi   # 0x2070940
movl 0x10060(%rbx), %edx
pushq $0x3
popq %rsi
callq 0x2220
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20f2(%rip), %rdi      # 0x9442
callq 0x2460
jmp 0x71b4
leaq 0x20e9(%rip), %rdi      # 0x944a
callq 0x2460
jmp 0x71c4
leaq 0x20d8(%rip), %rdi      # 0x944a
callq 0x2460
jmp 0x71f2
leaq 0x20bf(%rip), %rdi      # 0x9442
callq 0x2460
jmp 0x7204
nopl (%rax)