// File: /workspace/github_c_makefile_star2_O0/pencode-lab[P]Shoit/shoit_sender.c
// Function: tcpserver_run
static void tcpserver_run(shoit_core_t *sender)
{
    struct timeval timeout;
    fd_set rset,orgSet;
    int maxfdpl;
    int done=0;
    int retval;

    shoit_control_t crlhdr; /*tcp header*/

    maxfdpl = sender->tcpSockfd +1;                                                                                          
    FD_ZERO(&orgSet);                                                                                                                
    FD_SET(sender->tcpSockfd, &orgSet);

    while(!done && sender->runing){
        timeout.tv_sec = 5;                                                                                                          
        timeout.tv_usec = 0;                                                                                                         
        memcpy(&rset,&orgSet,sizeof(orgSet));                                                                                        
        retval = select(maxfdpl, &rset, NULL, NULL, &timeout);                                                                       
        if(retval<0){/*error*/                                                                                                       
            SHOIT_LOG("select return -1 (%s) at 0xe01\n",strerror(errno));                                                         
            done =1;                                                                                                                 
        } if(retval>0 && FD_ISSET(sender->tcpSockfd, &rset)){          
            memset(&crlhdr,0,sizeof(shoit_control_t));

            if(shoit_network_readn(sender->tcpSockfd,
                                  (char*)&crlhdr,sizeof(shoit_control_t))==sizeof(shoit_control_t)) {                                   
                switch(crlhdr.status){                                                                                              
                    case CONNECT:/*receiver request*/                                                                                
                        if(sender->verbose>1) SHOIT_LOG("CONNECT signal\n");                                               
                        char password[16];bzero(password,sizeof(password));
                        int dataSize = ntohl(crlhdr.dataSize);
                        if(dataSize>0){
                            if(shoit_network_readn(sender->tcpSockfd,password,dataSize)!=dataSize){
                                SHOIT_LOG("read line for password error");
                                done =1;
                                break;
                            }
                        }
                        /*check password*/
                        if(strncmp(password,sender->password,dataSize-sizeof(int))){
                            SHOIT_LOG("remote password[%s]:[%s] is wrong.\n",password,sender->password);
                            done =1;
                            break;
                        }
                         /*notice pthread start transfer data to remote*/
                        sem_post(&sender->dataSem);/*let us udp send data in man pthread*/
                        sem_post(&sender->progSem);
                        if(sender->verbose>1) SHOIT_LOG("recv CONNECT signal and sem_post() start pthread\n");
                        break;                                                                                                       
                    case READY:
                        if(sender->verbose>1) SHOIT_LOG("get READY sig.and post sem.\n");
                        sem_post(&sender->dataSem);
                        break;
                    case BITMAP: /*receiver send me the errorBitMap*/                                                                
                        if(sender->verbose>1) SHOIT_LOG("BITMAP signal\n");
                        int needReadLen = ntohl(crlhdr.dataSize);
                        if(needReadLen ==0) {/*no error*/
                            char *errorBitmap = (char*)(sender->errorBitmap+sizeof(shoit_control_t));
                            errorBitmap[0]=1;
                        }else {
                             shoit_network_readn(sender->tcpSockfd,
                                                    (char*)(sender->errorBitmap+sizeof(shoit_control_t)),
                                                    needReadLen);
                        }
                        /*notic pthread process errorBitMap*/
                        if(sender->verbose>1) SHOIT_LOG("get BITMAP sig.and post sem.\n");
                        sem_post(&sender->dataSem);/*let us udp send data in man pthread*/
                        break;                                                                                                       
                    default:                                                                                                         
                        SHOIT_LOG("read error tcpcrl,ignore the recv data,error status[%d]. 0xe03\n",crlhdr.status);                                  
                        break;                                                                                                       
                }      
            }else{
                if(sender->verbose>1) SHOIT_LOG("remote socket close.\n");
                done =1;
            }
        }//retval >0
    }//while(!done)

    sender->runing = false;
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl $0x0, -0x120(%rbp)
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
leaq -0x118(%rbp), %rax
movq %rax, -0x150(%rbp)
movl $0x0, -0x148(%rbp)
movl -0x148(%rbp), %eax
cmpq $0x10, %rax
jae 0x5533
movq -0x150(%rbp), %rax
movl -0x148(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x5501
jmp 0x5535
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x118(%rbp,%rax,8), %rcx
movq %rcx, -0x118(%rbp,%rax,8)
xorl %eax, %eax
cmpl $0x0, -0x120(%rbp)
movb %al, -0x171(%rbp)
jne 0x5599
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
setne %al
movb %al, -0x171(%rbp)
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x55a8
jmp 0x59ae
movq $0x5, -0x18(%rbp)
movq $0x0, -0x10(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x118(%rbp), %rsi
movl $0x80, %edx
callq 0x2280
movl -0x11c(%rbp), %edi
leaq -0x98(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x18(%rbp), %r8
movq %rcx, %rdx
callq 0x22a0
movl %eax, -0x124(%rbp)
cmpl $0x0, -0x124(%rbp)
jge 0x563e
jmp 0x55fe
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x180(%rbp)
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq -0x180(%rbp), %rdi
movq %rax, %rdx
leaq 0x44d3(%rip), %rsi      # 0x9b00
movb $0x0, %al
callq 0x3df0
movl $0x1, -0x120(%rbp)
cmpl $0x0, -0x124(%rbp)
jle 0x59a9
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x98(%rbp,%rax,8), %rax
movq %rax, -0x188(%rbp)
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x188(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x59a9
leaq -0x142(%rbp), %rdi
xorl %esi, %esi
movl $0x1e, %edx
callq 0x21a0
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %edi
leaq -0x142(%rbp), %rsi
movl $0x1e, %edx
callq 0x3940
cmpq $0x1e, %rax
jne 0x5976
movl -0x142(%rbp), %eax
movl %eax, -0x18c(%rbp)
subl $0x1, %eax
je 0x5708
jmp 0x56e3
movl -0x18c(%rbp), %eax
subl $0x3, %eax
je 0x5857
jmp 0x56f4
movl -0x18c(%rbp), %eax
subl $0x5, %eax
je 0x5893
jmp 0x5951
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x572f
jmp 0x5714
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x43fa(%rip), %rsi      # 0x9b20
movb $0x0, %al
callq 0x3df0
jmp 0x572f
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x21a0
movl -0x128(%rbp), %edi
callq 0x2430
movl %eax, -0x164(%rbp)
cmpl $0x0, -0x164(%rbp)
jle 0x57ae
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %edi
leaq -0x160(%rbp), %rsi
movslq -0x164(%rbp), %rdx
callq 0x3940
movslq -0x164(%rbp), %rcx
cmpq %rcx, %rax
je 0x57ac
jmp 0x5784
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x439a(%rip), %rsi      # 0x9b30
movb $0x0, %al
callq 0x3df0
movl $0x1, -0x120(%rbp)
jmp 0x5974
jmp 0x57ae
leaq -0x160(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rsi
movslq -0x164(%rbp), %rdx
subq $0x4, %rdx
callq 0x2070
cmpl $0x0, %eax
je 0x580b
jmp 0x57d4
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq -0x160(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rcx
leaq 0x4358(%rip), %rsi      # 0x9b4d
movb $0x0, %al
callq 0x3df0
movl $0x1, -0x120(%rbp)
jmp 0x5974
movq -0x8(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x21f0
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
callq 0x21f0
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x5852
jmp 0x5837
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x4328(%rip), %rsi      # 0x9b71
movb $0x0, %al
callq 0x3df0
jmp 0x5852
jmp 0x5974
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x587e
jmp 0x5863
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x432e(%rip), %rsi      # 0x9ba3
movb $0x0, %al
callq 0x3df0
jmp 0x587e
movq -0x8(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x21f0
jmp 0x5974
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x58ba
jmp 0x589f
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x430f(%rip), %rsi      # 0x9bc0
movb $0x0, %al
callq 0x3df0
jmp 0x58ba
movl -0x128(%rbp), %edi
callq 0x2430
movl %eax, -0x168(%rbp)
cmpl $0x0, -0x168(%rbp)
jne 0x58f6
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
addq $0x1e, %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rax
movb $0x1, (%rax)
jmp 0x5918
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %edi
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rsi
addq $0x1e, %rsi
movslq -0x168(%rbp), %rdx
callq 0x3940
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x593f
jmp 0x5924
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x4299(%rip), %rsi      # 0x9bcf
movb $0x0, %al
callq 0x3df0
jmp 0x593f
movq -0x8(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x21f0
jmp 0x5974
jmp 0x5953
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
movl -0x142(%rbp), %edx
leaq 0x4282(%rip), %rsi      # 0x9bed
movb $0x0, %al
callq 0x3df0
jmp 0x5974
jmp 0x59a7
movq -0x8(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x599d
jmp 0x5982
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x4299(%rip), %rsi      # 0x9c2d
movb $0x0, %al
callq 0x3df0
jmp 0x599d
movl $0x1, -0x120(%rbp)
jmp 0x59a9
jmp 0x5574
movq -0x8(%rbp), %rax
movl $0x0, 0x1a8(%rax)
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)