// File: /workspace/github_c_makefile_star2_O3/pencode-lab[P]Shoit/shoit_sender.c
// Function: echo_to_receiver_on_tcp
static bool echo_to_receiver_on_tcp(shoit_core_t *sender, int type)
{
    char buffer[MTU]={0};
    int dataSize =0;
    shoit_control_t *tcpCrl=(shoit_control_t *)buffer;
    memset(buffer,0,sizeof(buffer));
    tcpCrl->status =type;
    tcpCrl->iStream = sender->iStream;

    if(sender->verbose>1) SHOIT_LOG("call %s:%d\n",__func__,type);

    switch(type){
        case ROUND:
        {
            tcpCrl->payloadSize = htonl(sender->payloadSize);
            tcpCrl->bucketSize = shoit_misc_htonll(sender->bucketSize);                                                                      
            tcpCrl->fileSize = shoit_misc_htonll(sender->fileSize);

            if(tcpCrl->iStream)
                tcpCrl->dataSize = htonl(0);                                                                                                  
            else if(sender->fileName!=NULL){
                char *notIncludePathFileName = shoit_misc_from_path_get_filename(sender->fileName);                                        
                if(notIncludePathFileName==NULL) {
                    SHOIT_LOG("echo_to_receiver_on_tcp error(0x010)\n");
                    return false;
                }
                dataSize = strlen(notIncludePathFileName);                                                                                  
                tcpCrl->dataSize = htonl(dataSize);                                                                                                    
                memcpy(tcpCrl->data,notIncludePathFileName,dataSize);
            } 

        }break;
        case UDPEND:
        case HEART:
        case CLOSE:
            tcpCrl->payloadSize = htonl(sender->payloadSize);
            tcpCrl->bucketSize = shoit_misc_htonll(sender->bucketSize);
            tcpCrl->dataSize = htonl(0); 
            break;
        default:
            return false;
    }

    if(shoit_network_writen(sender->tcpSockfd, buffer, sizeof(shoit_control_t)+dataSize) != (sizeof(shoit_control_t)+dataSize))              
    {                                                                                                                                
        SHOIT_LOG("tcp send failed(%s).\n",__func__);                                                                     
        return false;
    }              

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x550, %rsp            # imm = 0x550
movl %esi, %r14d
movq %rdi, %rbx
movq %rsp, %r15
xorl %ebp, %ebp
movl $0x550, %edx            # imm = 0x550
movq %r15, %rdi
xorl %esi, %esi
callq 0x2190
movl %r14d, (%r15)
movzwl 0x1a4(%rbx), %r12d
movw %r12w, 0x4(%r15)
cmpl $0x2, 0x5c(%rbx)
jl 0x4d14
movq 0xe8(%rbx), %rdi
leaq 0x1bd9(%rip), %rsi      # 0x68dc
leaq 0x1bde(%rip), %rdx      # 0x68e8
movl %r14d, %ecx
xorl %eax, %eax
callq 0x374a
leal -0x6(%r14), %eax
cmpl $0x2, %eax
jb 0x4d9b
cmpl $0x4, %r14d
je 0x4d9b
cmpl $0x2, %r14d
jne 0x4df6
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x3802
movq %rax, 0xa(%rsp)
movq 0x10(%rbx), %rdi
callq 0x3802
movq %rax, 0x12(%rsp)
testw %r12w, %r12w
jne 0x4db2
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x4dba
callq 0x3711
testq %rax, %rax
je 0x4e08
movq %rax, %r15
movq %rax, %rdi
callq 0x20d0
movslq %eax, %r14
bswapl %eax
leaq 0x1e(%rsp), %rdi
movl %eax, -0x4(%rdi)
movq %r15, %rsi
movq %r14, %rdx
callq 0x2280
addq $0x1e, %r14
jmp 0x4dc0
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x3802
movq %rax, 0xa(%rsp)
movl $0x0, 0x1a(%rsp)
movl $0x1e, %r14d
movl 0x6c(%rbx), %edi
movq %rsp, %rsi
movq %r14, %rdx
callq 0x34bd
movl $0x1, %ebp
cmpq %r14, %rax
je 0x4df6
movq 0xe8(%rbx), %rdi
leaq 0x1b40(%rip), %rsi      # 0x6926
leaq 0x1afb(%rip), %rdx      # 0x68e8
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x374a
movl %ebp, %eax
addq $0x550, %rsp            # imm = 0x550
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xe8(%rbx), %rdi
leaq 0x1aea(%rip), %rsi      # 0x6900
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x374a
jmp 0x4df6