// File: QZzcoder[P]LiveChat/server.cpp
// Function: main
int main()
{
    int shutDownNum = -404;
    socket_fd = getSocket(8888,"127.0.0.1",true);
    cout << "bind ok 等待客户端的连接" << endl;
    cout << "新建用户: 用户名&密码" << endl;
    cout << "退出: end" << endl;

    len = sizeof(client);

    char recv_buff[255];

    serverSelectSet.insert(socket_fd);
    cinSelectSet.insert(STDIN_FILENO);
    thread t1(oneLoop);
    thread t2(oneLoop);
    thread t3(oneLoop);
    while(1){
        //处理登录
        if(mySelect(fds,serverSelectSet,0) == socket_fd){
            bq.put(socket_fd);
        }
        //一次收发
        int activeClient = mySelect(fds,clientSelectSet,0);
        if(clientSelectSet.count(activeClient) == 1){
            bq.put(activeClient);

        }
        //服务器控制
        if(mySelect(fds,cinSelectSet,500) == STDIN_FILENO){
            ssize_t recv_size = read(STDIN_FILENO,recv_buff,255);
            if(recv_buff[0] == 'e' &&recv_buff[1] == 'n' &&recv_buff[2] == 'd'){
                cout<<getTime()<<"server Shutdown"<<endl;
                for(auto it:name2sock){
                    cout<<it.first<<" shutdown"<<endl;
                    close(it.second);
                }
                for(int i = 0;i<3;i++){
                    bq.put(shutDownNum);
                }

                break;
            }
            vector<string> msg = splitString(recv_buff,'&');
            if(msg.size() == 2&&newUser(msg[0],msg[1])){
                cout<<getTime()<<"新用户添加成功:"<<msg[0]<<"--"<<msg[1];
            }else{
                cout<<"用户名和密码间隔 : &"<<endl;
            }
        }
    }
    //7.关闭sockfd
    t1.join();
    t2.join();
    t3.join();
    close(socket_fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movl $0x0, -0x4(%rbp)
movl $0xfffffe6c, -0x8(%rbp) # imm = 0xFFFFFE6C
leaq -0x29(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x34e0
movq -0x340(%rbp), %rdx
leaq 0x89c8(%rip), %rsi      # 0xe17f
leaq -0x28(%rbp), %rdi
callq 0x33f0
jmp 0x57c2
movl $0x22b8, %edi           # imm = 0x22B8
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0xcfd0
movl %eax, -0x344(%rbp)
jmp 0x57dd
movl -0x344(%rbp), %eax
movl %eax, 0xfb9f(%rip)      # 0x15388
leaq 0xfb98(%rip), %rax      # 0x15388
movq %rax, -0x358(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3200
leaq -0x29(%rbp), %rdi
callq 0x3380
movq 0xf7c8(%rip), %rdi      # 0x14fd8
movq %rdi, -0x368(%rbp)
leaq 0x896b(%rip), %rsi      # 0xe189
callq 0x3310
movq %rax, %rdi
movq 0xf793(%rip), %rsi      # 0x14fc0
movq %rsi, -0x360(%rbp)
callq 0x3370
movq -0x368(%rbp), %rdi
leaq 0x8963(%rip), %rsi      # 0xe1aa
callq 0x3310
movq -0x360(%rbp), %rsi
movq %rax, %rdi
callq 0x3370
movq -0x368(%rbp), %rdi
leaq 0x8960(%rip), %rsi      # 0xe1c9
callq 0x3310
movq -0x360(%rbp), %rsi
movq %rax, %rdi
callq 0x3370
movq -0x358(%rbp), %rsi
movl $0x10, 0xfc52(%rip)     # 0x154e0
leaq 0xfbbb(%rip), %rdi      # 0x15450
callq 0x69b0
movq %rax, -0x150(%rbp)
movb %dl, -0x148(%rbp)
movl $0x0, -0x154(%rbp)
leaq 0xfbf8(%rip), %rdi      # 0x154b0
leaq -0x154(%rbp), %rsi
callq 0x6ce0
movq %rax, -0x168(%rbp)
movb %dl, -0x160(%rbp)
leaq -0xdf8(%rip), %rsi      # 0x4ae0
movq %rsi, -0x350(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x6d30
movq -0x350(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x6d30
jmp 0x5900
leaq -0xe27(%rip), %rsi      # 0x4ae0
leaq -0x180(%rbp), %rdi
callq 0x6d30
jmp 0x5915
jmp 0x5917
jmp 0x5919
leaq 0xfb30(%rip), %rsi      # 0x15450
leaq -0x1b0(%rbp), %rdi
callq 0x6de0
jmp 0x592e
leaq 0xfa6b(%rip), %rdi      # 0x153a0
leaq -0x1b0(%rbp), %rsi
xorl %edx, %edx
callq 0xd0f0
movl %eax, -0x36c(%rbp)
jmp 0x594b
movl 0xfa37(%rip), %eax      # 0x15388
movl %eax, -0x370(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x62b0
movl -0x370(%rbp), %ecx
movl -0x36c(%rbp), %eax
cmpl %ecx, %eax
jne 0x5a12
leaq 0xf962(%rip), %rdi      # 0x152e0
leaq 0xfa03(%rip), %rsi      # 0x15388
callq 0x6e10
jmp 0x598c
jmp 0x5a12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x59b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3200
leaq -0x29(%rbp), %rdi
callq 0x3380
jmp 0x60e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x60d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x60ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x60be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x62b0
jmp 0x60be
leaq 0xfa67(%rip), %rsi      # 0x15480
leaq -0x1e8(%rbp), %rdi
callq 0x6de0
jmp 0x5a27
leaq 0xf972(%rip), %rdi      # 0x153a0
leaq -0x1e8(%rbp), %rsi
xorl %edx, %edx
callq 0xd0f0
movl %eax, -0x374(%rbp)
jmp 0x5a44
leaq -0x1e8(%rbp), %rdi
callq 0x62b0
movl -0x374(%rbp), %eax
movl %eax, -0x1b4(%rbp)
leaq 0xfa1d(%rip), %rdi      # 0x15480
leaq -0x1b4(%rbp), %rsi
callq 0x6ae0
movq %rax, -0x380(%rbp)
jmp 0x5a78
movq -0x380(%rbp), %rax
cmpq $0x1, %rax
jne 0x5ab9
leaq 0xf854(%rip), %rdi      # 0x152e0
leaq -0x1b4(%rbp), %rsi
callq 0x6e10
jmp 0x5a9a
jmp 0x5ab9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x62b0
jmp 0x60be
leaq 0xf9f0(%rip), %rsi      # 0x154b0
leaq -0x218(%rbp), %rdi
callq 0x6de0
jmp 0x5ace
leaq 0xf8cb(%rip), %rdi      # 0x153a0
leaq -0x218(%rbp), %rsi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0xd0f0
movl %eax, -0x384(%rbp)
jmp 0x5aee
leaq -0x218(%rbp), %rdi
callq 0x62b0
movl -0x384(%rbp), %eax
cmpl $0x0, %eax
jne 0x604b
xorl %edi, %edi
leaq -0x140(%rbp), %rsi
movl $0xff, %edx
callq 0x3420
movq %rax, -0x390(%rbp)
jmp 0x5b25
movq -0x390(%rbp), %rax
movq %rax, -0x220(%rbp)
movsbl -0x140(%rbp), %eax
cmpl $0x65, %eax
jne 0x5d42
movsbl -0x13f(%rbp), %eax
cmpl $0x6e, %eax
jne 0x5d42
movsbl -0x13e(%rbp), %eax
cmpl $0x64, %eax
jne 0x5d42
leaq -0x240(%rbp), %rdi
callq 0xcf10
jmp 0x5b71
movq 0xf460(%rip), %rdi      # 0x14fd8
leaq -0x240(%rbp), %rsi
callq 0x32c0
movq %rax, -0x398(%rbp)
jmp 0x5b8d
movq -0x398(%rbp), %rdi
leaq 0x863a(%rip), %rsi      # 0xe1d5
callq 0x3310
movq %rax, -0x3a0(%rbp)
jmp 0x5ba9
movq -0x3a0(%rbp), %rdi
movq 0xf409(%rip), %rsi      # 0x14fc0
callq 0x3370
jmp 0x5bbe
leaq -0x240(%rbp), %rdi
callq 0x3200
leaq 0xf84f(%rip), %rax      # 0x15420
movq %rax, -0x248(%rbp)
leaq 0xf841(%rip), %rdi      # 0x15420
callq 0x6b40
movq %rax, -0x250(%rbp)
leaq 0xf82e(%rip), %rdi      # 0x15420
callq 0x6b70
movq %rax, -0x258(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x6ba0
testb $0x1, %al
jne 0x5c1a
jmp 0x5d05
leaq -0x250(%rbp), %rdi
callq 0x6bd0
movq %rax, %rsi
leaq -0x280(%rbp), %rdi
callq 0x6bf0
jmp 0x5c37
movq 0xf39a(%rip), %rdi      # 0x14fd8
leaq -0x280(%rbp), %rsi
callq 0x32c0
movq %rax, -0x3a8(%rbp)
jmp 0x5c53
movq -0x3a8(%rbp), %rdi
leaq 0x8584(%rip), %rsi      # 0xe1e5
callq 0x3310
movq %rax, -0x3b0(%rbp)
jmp 0x5c6f
movq -0x3b0(%rbp), %rdi
movq 0xf343(%rip), %rsi      # 0x14fc0
callq 0x3370
jmp 0x5c84
movl -0x260(%rbp), %edi
callq 0x3540
jmp 0x5c91
leaq -0x280(%rbp), %rdi
callq 0x6c30
leaq -0x250(%rbp), %rdi
callq 0x6c50
jmp 0x5bfe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x62b0
jmp 0x60be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3200
jmp 0x60be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x6c30
jmp 0x60be
movl $0x0, -0x284(%rbp)
cmpl $0x3, -0x284(%rbp)
jge 0x5d3d
leaq 0xf5c1(%rip), %rdi      # 0x152e0
leaq -0x8(%rbp), %rsi
callq 0x6e10
jmp 0x5d2a
jmp 0x5d2c
movl -0x284(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x284(%rbp)
jmp 0x5d0f
jmp 0x6050
leaq -0x2c1(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x34e0
movq -0x3b8(%rbp), %rdx
leaq -0x2c0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x33f0
jmp 0x5d71
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
movl $0x26, %edx
callq 0xd360
jmp 0x5d8b
leaq -0x2c0(%rbp), %rdi
callq 0x3200
leaq -0x2c1(%rbp), %rdi
callq 0x3380
leaq -0x2a0(%rbp), %rdi
callq 0x68b0
movq %rax, %rcx
movb $0x0, -0x2e9(%rbp)
movb $0x0, -0x311(%rbp)
xorl %eax, %eax
cmpq $0x2, %rcx
movb %al, -0x3b9(%rbp)
jne 0x5e48
xorl %eax, %eax
movl %eax, %esi
leaq -0x2a0(%rbp), %rdi
callq 0x6560
movq %rax, %rsi
leaq -0x2e8(%rbp), %rdi
callq 0x3130
jmp 0x5def
movb $0x1, -0x2e9(%rbp)
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x6560
movq %rax, %rsi
leaq -0x310(%rbp), %rdi
callq 0x3130
jmp 0x5e18
movb $0x1, -0x311(%rbp)
leaq -0x2e8(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x47d0
movb %al, -0x3ba(%rbp)
jmp 0x5e3a
movb -0x3ba(%rbp), %al
movb %al, -0x3b9(%rbp)
jmp 0x5e48
movb -0x3b9(%rbp), %al
movb %al, -0x3bb(%rbp)
testb $0x1, -0x311(%rbp)
jne 0x5e5f
jmp 0x5e6b
leaq -0x310(%rbp), %rdi
callq 0x3200
testb $0x1, -0x2e9(%rbp)
jne 0x5e76
jmp 0x5e82
leaq -0x2e8(%rbp), %rdi
callq 0x3200
movb -0x3bb(%rbp), %al
testb $0x1, %al
jne 0x5e91
jmp 0x5ffc
leaq -0x338(%rbp), %rdi
callq 0xcf10
jmp 0x5e9f
movq 0xf132(%rip), %rdi      # 0x14fd8
leaq -0x338(%rbp), %rsi
callq 0x32c0
movq %rax, -0x3c8(%rbp)
jmp 0x5ebb
movq -0x3c8(%rbp), %rdi
leaq 0x8326(%rip), %rsi      # 0xe1ef
callq 0x3310
movq %rax, -0x3d0(%rbp)
jmp 0x5ed7
xorl %eax, %eax
movl %eax, %esi
leaq -0x2a0(%rbp), %rdi
callq 0x6560
movq -0x3d0(%rbp), %rdi
movq %rax, %rsi
callq 0x32c0
movq %rax, -0x3d8(%rbp)
jmp 0x5eff
movq -0x3d8(%rbp), %rdi
leaq 0x82f9(%rip), %rsi      # 0xe206
callq 0x3310
movq %rax, -0x3e0(%rbp)
jmp 0x5f1b
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x6560
movq -0x3e0(%rbp), %rdi
movq %rax, %rsi
callq 0x32c0
jmp 0x5f3d
leaq -0x338(%rbp), %rdi
callq 0x3200
jmp 0x602f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x3200
leaq -0x2c1(%rbp), %rdi
callq 0x3380
jmp 0x60be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x603d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5fc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
testb $0x1, -0x311(%rbp)
jne 0x5fbb
jmp 0x5fc7
leaq -0x310(%rbp), %rdi
callq 0x3200
jmp 0x5fc9
testb $0x1, -0x2e9(%rbp)
jne 0x5fd4
jmp 0x5fe0
leaq -0x2e8(%rbp), %rdi
callq 0x3200
jmp 0x603d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x3200
jmp 0x603d
movq 0xefd5(%rip), %rdi      # 0x14fd8
leaq 0x81ff(%rip), %rsi      # 0xe209
callq 0x3310
movq %rax, -0x3e8(%rbp)
jmp 0x6018
movq -0x3e8(%rbp), %rdi
movq 0xef9a(%rip), %rsi      # 0x14fc0
callq 0x3370
jmp 0x602d
jmp 0x602f
leaq -0x2a0(%rbp), %rdi
callq 0x6630
jmp 0x604b
leaq -0x2a0(%rbp), %rdi
callq 0x6630
jmp 0x60be
jmp 0x5917
leaq -0x170(%rbp), %rdi
callq 0x34b0
jmp 0x605e
leaq -0x178(%rbp), %rdi
callq 0x34b0
jmp 0x606c
leaq -0x180(%rbp), %rdi
callq 0x34b0
jmp 0x607a
movl 0xf308(%rip), %edi      # 0x15388
callq 0x3540
jmp 0x6087
movl $0x0, -0x4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x6e80
leaq -0x178(%rbp), %rdi
callq 0x6e80
leaq -0x170(%rbp), %rdi
callq 0x6e80
movl -0x4(%rbp), %eax
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
leaq -0x180(%rbp), %rdi
callq 0x6e80
leaq -0x178(%rbp), %rdi
callq 0x6e80
leaq -0x170(%rbp), %rdi
callq 0x6e80
movq -0x38(%rbp), %rdi
callq 0x34d0
nopl (%rax,%rax)