// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x0, 0x10060(%rdi)
jns 0x762d
movl $0x1, 0x4(%rsp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x2540
movl %eax, 0x10060(%rbx)
testl %eax, %eax
js 0x762d
movl %eax, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x20d0
movl 0x10060(%rbx), %edi
leaq 0x4(%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 0x2550
cmpl $-0x1, %eax
je 0x7791
xorl %edi, %edi
callq 0x2510
cmpl $-0x1, %eax
je 0x77a2
movl 0x10060(%rbx), %edi
leaq 0x10024(%rbx), %rsi
movl $0x10, %edx
callq 0x2400
leaq 0x11d67(%rip), %r14     # 0x19370
movl 0xc(%r14), %edi
callq 0x2510
cmpl $-0x1, %eax
je 0x77b3
movl 0xc(%r14), %edi
callq 0x2550
cmpl $-0x1, %eax
je 0x77c4
movl $0x0, 0x10064(%rbx)
movq 0x10040(%rbx), %r14
movzwl (%r14), %ecx
leal 0x2(%rcx), %edx
movl 0x10054(%rbx), %eax
cmpl %eax, %edx
jg 0x76f2
leaq 0x10014(%rbx), %r15
movl 0x10060(%rbx), %edi
movslq 0x10058(%rbx), %rax
leaq (%r14,%rax), %rsi
addq $0x2, %rsi
movslq %ecx, %rdx
subq %rax, %rdx
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x21c0
movq %rax, %r12
testl %r12d, %r12d
jns 0x769b
callq 0x2050
cmpl $0xb, (%rax)
je 0x7781
addl %r12d, 0x10058(%rbx)
testl %r12d, %r12d
jle 0x774c
movzwl (%r14), %eax
cmpl %eax, %r12d
jl 0x7753
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), %edx
cmpl %eax, %edx
jle 0x765a
movq 0x10040(%rbx), %rdi
testl %eax, %eax
je 0x7711
xorl %ebx, %ebx
cmpq %rdi, %r14
jbe 0x7783
movslq %eax, %rdx
movq %r14, %rsi
callq 0x2420
jmp 0x7783
callq 0x2030
movq $0x0, 0x10040(%rbx)
movq %rbx, 0x2069210(%rip)   # 0x2070938
leaq 0x2069205(%rip), %rcx   # 0x2070934
movl $0x80000001, 0x20691fb(%rip) # imm = 0x80000001
movl 0x20691f1(%rip), %edi   # 0x2070930
movl 0x10060(%rbx), %edx
movl $0x3, %esi
jmp 0x777c
movl $0x1, %ebx
jmp 0x7783
movq %rbx, 0x20691de(%rip)   # 0x2070938
leaq 0x20691d3(%rip), %rcx   # 0x2070934
movl $0x80000005, 0x20691c9(%rip) # imm = 0x80000005
movl 0x20691bf(%rip), %edi   # 0x2070930
movl 0x10060(%rbx), %edx
movl $0x1, %esi
callq 0x2220
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x1cae(%rip), %rdi      # 0x9446
callq 0x2450
jmp 0x75db
leaq 0x1ca5(%rip), %rdi      # 0x944e
callq 0x2450
jmp 0x75eb
leaq 0x1c94(%rip), %rdi      # 0x944e
callq 0x2450
jmp 0x761b
leaq 0x1c7b(%rip), %rdi      # 0x9446
callq 0x2450
jmp 0x762d
nopl (%rax)