// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x558, %rsp            # imm = 0x558
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), %eax
movw %ax, 0x4(%r15)
cmpl $0x2, 0x5c(%rbx)
jl 0x4cdc
movq 0xe8(%rbx), %rdi
leaq 0x1bf1(%rip), %rsi      # 0x68bc
leaq 0x1bf6(%rip), %rdx      # 0x68c8
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3741
leal -0x6(%r14), %eax
cmpl $0x2, %eax
jb 0x4d64
cmpl $0x4, %r14d
je 0x4d64
cmpl $0x2, %r14d
jne 0x4dc3
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x37f9
movq %rax, 0xa(%rsp)
movq 0x10(%rbx), %rdi
callq 0x37f9
movq %rax, 0x12(%rsp)
cmpw $0x0, 0x4(%rsp)
jne 0x4d7b
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x4d83
callq 0x3708
movq %rax, %r14
testq %rax, %rax
je 0x4dd3
movq %r14, %rdi
callq 0x20d0
movq %rax, %r15
movslq %r15d, %rdx
bswapl %eax
leaq 0x1e(%rsp), %rdi
movl %eax, -0x4(%rdi)
movq %r14, %rsi
callq 0x2280
jmp 0x4deb
movl 0x2c(%rbx), %eax
bswapl %eax
movl %eax, 0x6(%rsp)
movq 0x8(%rbx), %rdi
callq 0x37f9
movq %rax, 0xa(%rsp)
movl $0x0, 0x1a(%rsp)
xorl %r15d, %r15d
movl 0x6c(%rbx), %edi
movslq %r15d, %r14
addq $0x1e, %r14
movq %rsp, %rsi
movq %r14, %rdx
callq 0x34ad
movl $0x1, %ebp
cmpq %r14, %rax
je 0x4dc3
movq 0xe8(%rbx), %rdi
leaq 0x1b53(%rip), %rsi      # 0x6906
leaq 0x1b0e(%rip), %rdx      # 0x68c8
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x3741
movl %ebp, %eax
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xe8(%rbx), %rdi
leaq 0x1aff(%rip), %rsi      # 0x68e0
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x3741
testq %r14, %r14
jne 0x4d86
xorl %ebp, %ebp
jmp 0x4dc3