// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movl $0xfffffe6c, -0x70(%rbp) # imm = 0xFFFFFE6C
leaq -0xf8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x2a20(%rip), %rsi      # 0x819b
leaq 0x2a22(%rip), %rdx      # 0x81a4
leaq -0x108(%rbp), %rbx
movq %rbx, %rdi
callq 0x68a0
movl $0x22b8, %edi           # imm = 0x22B8
movq %rbx, %rsi
movl $0x1, %edx
callq 0x7876
movl %eax, 0x5ba7(%rip)      # 0xb350
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x57ba
callq 0x32b0
movq 0x5817(%rip), %rbx      # 0xafd8
leaq 0x29dd(%rip), %rsi      # 0x81a5
movl $0x20, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
leaq 0x29c3(%rip), %rsi      # 0x81c6
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
leaq 0x29a7(%rip), %rsi      # 0x81e5
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movl $0x10, 0x5c2c(%rip)     # 0xb4a8
leaq 0x5b95(%rip), %rdi      # 0xb418
leaq 0x5ac6(%rip), %rsi      # 0xb350
callq 0x6d32
leaq -0x50(%rbp), %rsi
movl $0x0, (%rsi)
leaq 0x5bd8(%rip), %rdi      # 0xb478
callq 0x74ea
leaq -0xb7d(%rip), %rbx      # 0x4d2f
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x6206
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x6206
leaq -0xb9c(%rip), %rsi      # 0x4d2f
leaq -0x58(%rbp), %rdi
callq 0x6206
leaq -0x198(%rbp), %r15
leaq 0x5a86(%rip), %r14      # 0xb368
leaq -0x168(%rbp), %rbx
movq %r15, %rdi
leaq 0x5b25(%rip), %rsi      # 0xb418
callq 0x64e4
movq %r14, %r12
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x7957
movl %eax, %r13d
movl 0x5a3e(%rip), %r14d     # 0xb350
movq %r15, %rdi
callq 0x640c
cmpl %r14d, %r13d
movq %r12, %r14
jne 0x5935
leaq 0x597f(%rip), %rdi      # 0xb2a8
leaq 0x5a20(%rip), %rsi      # 0xb350
callq 0x627a
leaq -0x138(%rbp), %rdi
leaq 0x5b05(%rip), %rsi      # 0xb448
callq 0x64e4
movq %r14, %rdi
leaq -0x138(%rbp), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x7957
movl %eax, %r13d
movq %r12, %rdi
callq 0x640c
movl %r13d, -0x6c(%rbp)
movq 0x5ae6(%rip), %rax      # 0xb458
testq %rax, %rax
je 0x59b7
leaq 0x5ad2(%rip), %rcx      # 0xb450
xorl %edx, %edx
cmpl %r13d, 0x20(%rax)
setl %dl
cmovgeq %rax, %rcx
movq 0x10(%rax,%rdx,8), %rax
testq %rax, %rax
jne 0x597e
leaq 0x5ab4(%rip), %rax      # 0xb450
cmpq %rax, %rcx
je 0x59b7
cmpl 0x20(%rcx), %r13d
jl 0x59b7
leaq 0x58fa(%rip), %rdi      # 0xb2a8
leaq -0x6c(%rbp), %rsi
callq 0x627a
movq %rbx, %rdi
leaq 0x5ab7(%rip), %rsi      # 0xb478
callq 0x64e4
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x7957
movl %eax, %r13d
movq %rbx, %rdi
callq 0x640c
testl %r13d, %r13d
jne 0x58e9
movl $0xff, %edx
xorl %edi, %edi
leaq -0x2a0(%rbp), %rsi
callq 0x33d0
cmpb $0x65, -0x2a0(%rbp)
jne 0x5a1c
cmpb $0x6e, -0x29f(%rbp)
jne 0x5a1c
cmpb $0x64, -0x29e(%rbp)
je 0x5c1f
leaq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x2a0(%rbp), %r12
movq %r12, %rdi
callq 0x3110
leaq (%rax,%rbp), %rdx
addq $-0x2a0, %rdx           # imm = 0xFD60
leaq -0xe8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x68a0
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
movl $0x26, %edx
callq 0x7a6b
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x5a82
callq 0x32b0
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rcx
subq %rax, %rcx
cmpq $0x40, %rcx
jne 0x5bc4
leaq -0x98(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x6688
movq -0x88(%rbp), %rax
leaq -0xb8(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %r12
movq %r12, %rdi
callq 0x6688
leaq -0xa8(%rbp), %rdi
movq %r12, %rsi
callq 0x49f3
movl %eax, %r13d
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5b17
callq 0x32b0
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x5b2f
callq 0x32b0
testb %r13b, %r13b
je 0x5bc4
leaq -0x50(%rbp), %rdi
callq 0x77f1
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x5488(%rip), %rdi      # 0xafd8
callq 0x3360
movq %rax, %r13
movl $0x16, %edx
movq %rax, %rdi
leaq 0x26a4(%rip), %rsi      # 0x820b
callq 0x3360
movq -0x88(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r13, %rdi
callq 0x3360
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x268e(%rip), %rsi      # 0x8222
callq 0x3360
movq -0x88(%rbp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq %r13, %rdi
callq 0x3360
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5c0e
callq 0x32b0
jmp 0x5c0e
movl $0x1c, %edx
movq 0x5408(%rip), %rdi      # 0xafd8
leaq 0x264e(%rip), %rsi      # 0x8225
callq 0x3360
movq 0x53f5(%rip), %rcx      # 0xafd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq 0x53d7(%rip), %rdi      # 0xafd8
callq 0x3030
movq %rax, %rdi
callq 0x31f0
leaq -0x88(%rbp), %rdi
callq 0x60b2
jmp 0x58e9
leaq -0x50(%rbp), %rdi
callq 0x77f1
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x53a1(%rip), %rdi      # 0xafd8
callq 0x3360
movq %rax, %rbx
leaq 0x25ab(%rip), %rsi      # 0x81f1
movl $0xf, %edx
movq %rax, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5c8c
callq 0x32b0
movq 0x576d(%rip), %rbx      # 0xb400
leaq 0x5756(%rip), %r14      # 0xb3f0
cmpq %r14, %rbx
je 0x5d4c
movq 0x532e(%rip), %r15      # 0xafd8
leaq 0x2550(%rip), %r12      # 0x8201
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x6688
movl 0x40(%rbx), %eax
movl %eax, -0x30(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0x3360
movq %rax, %r13
movl $0x9, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3360
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movl -0x30(%rbp), %edi
callq 0x34e0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5d38
callq 0x32b0
movq %rbx, %rdi
callq 0x3200
movq %rax, %rbx
cmpq %r14, %rax
jne 0x5cb1
movl $0x3, %r15d
leaq 0x554f(%rip), %rbx      # 0xb2a8
leaq -0x70(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x627a
decl %r15d
jne 0x5d5d
leaq -0x68(%rbp), %rdi
callq 0x3470
leaq -0x60(%rbp), %rdi
callq 0x3470
leaq -0x58(%rbp), %rdi
callq 0x3470
movl 0x55c2(%rip), %edi      # 0xb350
callq 0x34e0
cmpq $0x0, -0x58(%rbp)
jne 0x5ee4
cmpq $0x0, -0x60(%rbp)
jne 0x5ee4
cmpq $0x0, -0x68(%rbp)
jne 0x5ee4
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ec4
movq %rax, %rbx
jmp 0x5ece
movq %rax, %rbx
jmp 0x5ed5
movq %rax, %rbx
movq -0x108(%rbp), %rdi
cmpq %r14, %rdi
je 0x5edc
callq 0x32b0
jmp 0x5edc
jmp 0x5ec4
jmp 0x5eab
jmp 0x5e9a
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5e29
callq 0x32b0
jmp 0x5e29
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
jmp 0x5e65
jmp 0x5ec4
jmp 0x5ec4
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
jmp 0x5eb6
jmp 0x5ec4
jmp 0x5ec4
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5e9d
callq 0x32b0
jmp 0x5e9d
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
jmp 0x5e93
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
jmp 0x5e93
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x640c
jmp 0x5ec7
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x60b2
jmp 0x5ec7
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5ec7
callq 0x32b0
jmp 0x5ec7
jmp 0x5ec4
movq %rax, %rbx
cmpq $0x0, -0x58(%rbp)
jne 0x5ee4
cmpq $0x0, -0x60(%rbp)
jne 0x5ee4
cmpq $0x0, -0x68(%rbp)
jne 0x5ee4
movq %rbx, %rdi
callq 0x3480
callq 0x30a0
nop