// File: /workspace/github_c_makefile_star2_O2/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 0x49bb
movq 0xe8(%rbx), %rdi
leaq 0x1f02(%rip), %rsi      # 0x68ac
leaq 0x1f07(%rip), %rdx      # 0x68b8
movl %r14d, %ecx
xorl %eax, %eax
callq 0x34b1
leal -0x6(%r14), %eax
cmpl $0x2, %eax
jb 0x4a42
cmpl $0x4, %r14d
je 0x4a42
cmpl $0x2, %r14d
jne 0x4a98
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x3567
movq %rax, 0xa(%rsp)
movq 0x10(%rbx), %rdi
callq 0x3567
movq %rax, 0x12(%rsp)
testw %r12w, %r12w
jne 0x4a59
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x4a5e
callq 0x347a
testq %rax, %rax
je 0x4aaa
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 0x4a62
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x3567
movq %rax, 0xa(%rsp)
andl $0x0, 0x1a(%rsp)
pushq $0x1e
popq %r14
movl 0x6c(%rbx), %edi
movq %rsp, %rsi
movq %r14, %rdx
callq 0x325e
cmpq %r14, %rax
jne 0x4a7a
pushq $0x1
popq %rbp
jmp 0x4a98
movq 0xe8(%rbx), %rdi
leaq 0x1e6e(%rip), %rsi      # 0x68f6
leaq 0x1e29(%rip), %rdx      # 0x68b8
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x34b1
movl %ebp, %eax
addq $0x550, %rsp            # imm = 0x550
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xe8(%rbx), %rdi
leaq 0x1e18(%rip), %rsi      # 0x68d0
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x34b1
jmp 0x4a98