// File: /workspace/github_cpp_makefile_star2_O1/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 -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x2a16(%rip), %rsi      # 0x819b
leaq 0x2a18(%rip), %rdx      # 0x81a4
leaq -0x110(%rbp), %rbx
movq %rbx, %rdi
callq 0x68ca
movl $0x22b8, %edi           # imm = 0x22B8
movq %rbx, %rsi
movl $0x1, %edx
callq 0x78a2
movl %eax, 0x5b9d(%rip)      # 0xb350
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x57c4
callq 0x32b0
movq 0x580d(%rip), %rbx      # 0xafd8
leaq 0x29d3(%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 0x29b9(%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 0x299d(%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, 0x5c22(%rip)     # 0xb4a8
leaq 0x5b8b(%rip), %rdi      # 0xb418
leaq 0x5abc(%rip), %rsi      # 0xb350
callq 0x6d58
leaq -0x50(%rbp), %rsi
movl $0x0, (%rsi)
leaq 0x5bce(%rip), %rdi      # 0xb478
callq 0x7516
leaq -0xb87(%rip), %rbx      # 0x4d2f
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x6230
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x6230
leaq -0xba6(%rip), %rsi      # 0x4d2f
leaq -0x58(%rbp), %rdi
callq 0x6230
leaq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq 0x5a6e(%rip), %r14      # 0xb368
movq %rdi, %r13
leaq 0x5b14(%rip), %rsi      # 0xb418
callq 0x6512
movq %r14, %r12
movq %r14, %rdi
movq %r13, %r14
movq %r13, %rsi
xorl %edx, %edx
callq 0x7983
movl %eax, %ebx
movl 0x5a2b(%rip), %r15d     # 0xb350
movq %r14, %rdi
callq 0x643a
cmpl %r15d, %ebx
movq %r12, %r14
jne 0x5948
leaq 0x596c(%rip), %rdi      # 0xb2a8
leaq 0x5a0d(%rip), %rsi      # 0xb350
callq 0x62b4
leaq -0x170(%rbp), %rdi
leaq 0x5af2(%rip), %rsi      # 0xb448
callq 0x6512
movq %r14, %rdi
leaq -0x170(%rbp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x7983
movl %eax, %r15d
movq %rbx, %rdi
callq 0x643a
movl %r15d, -0x6c(%rbp)
movq 0x5ad3(%rip), %rcx      # 0xb458
leaq 0x5ac4(%rip), %rax      # 0xb450
testq %rcx, %rcx
je 0x59af
leaq 0x5ab8(%rip), %rax      # 0xb450
xorl %edx, %edx
cmpl %r15d, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x5998
leaq 0x5a9a(%rip), %rcx      # 0xb450
cmpq %rcx, %rax
je 0x59d1
cmpl 0x20(%rax), %r15d
jl 0x59d1
leaq 0x58e0(%rip), %rdi      # 0xb2a8
leaq -0x6c(%rbp), %rsi
callq 0x62b4
leaq -0x140(%rbp), %rdi
leaq 0x5a99(%rip), %rsi      # 0xb478
callq 0x6512
movq %r14, %rdi
leaq -0x140(%rbp), %r15
movq %r15, %rsi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x7983
movl %eax, %ebx
movq %r15, %rdi
callq 0x643a
testl %ebx, %ebx
jne 0x5da0
movl $0xff, %edx
xorl %edi, %edi
leaq -0x2a0(%rbp), %rsi
callq 0x33d0
movb -0x2a0(%rbp), %al
movb -0x29f(%rbp), %cl
xorb $0x65, %al
xorb $0x6e, %cl
orb %al, %cl
movb -0x29e(%rbp), %al
xorb $0x64, %al
orb %cl, %al
setne %r12b
je 0x5b2f
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x2a0(%rbp), %rbx
movq %rbx, %rdi
callq 0x3110
leaq (%rax,%rbp), %rdx
addq $-0x2a0, %rdx           # imm = 0xFD60
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x68ca
leaq -0x88(%rbp), %rdi
movq %r15, %rsi
movl $0x26, %edx
callq 0x7ab4
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x5aad
callq 0x32b0
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rbx
subq %rax, %rbx
cmpq $0x40, %rbx
jne 0x5c75
leaq -0xa0(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x66b6
movq -0x88(%rbp), %rax
leaq -0xc0(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %r15
movq %r15, %rdi
callq 0x66b6
leaq -0xb0(%rbp), %rdi
movq %r15, %rsi
callq 0x49f3
movl %eax, %r15d
jmp 0x5c78
leaq -0x50(%rbp), %rdi
callq 0x781d
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x5491(%rip), %rdi      # 0xafd8
callq 0x3360
movq %rax, %r15
movl $0xf, %edx
movq %rax, %rdi
leaq 0x2693(%rip), %rsi      # 0x81f1
callq 0x3360
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5b9c
callq 0x32b0
movq 0x585d(%rip), %r15      # 0xb400
leaq 0x5846(%rip), %rax      # 0xb3f0
cmpq %rax, %r15
je 0x5c52
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x66b6
movl 0x40(%r15), %eax
movl %eax, -0x30(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x53f3(%rip), %rdi      # 0xafd8
callq 0x3360
movq %rax, %rbx
movl $0x9, %edx
movq %rax, %rdi
leaq 0x2605(%rip), %rsi      # 0x8201
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 -0x30(%rbp), %edi
callq 0x34e0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5c42
callq 0x32b0
movq %r15, %rdi
callq 0x3200
movq %rax, %r15
jmp 0x5ba3
movl $0x3, %ebx
leaq 0x564a(%rip), %rdi      # 0xb2a8
leaq -0x70(%rbp), %rsi
callq 0x62b4
decl %ebx
jne 0x5c57
movl $0x3, %eax
jmp 0x5d9b
xorl %r15d, %r15d
cmpq $0x40, %rbx
jne 0x5cae
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x5c96
callq 0x32b0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x5cae
callq 0x32b0
testb %r15b, %r15b
je 0x5d43
leaq -0x50(%rbp), %rdi
callq 0x781d
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x5309(%rip), %rdi      # 0xafd8
callq 0x3360
movq %rax, %rbx
movl $0x16, %edx
movq %rax, %rdi
leaq 0x2525(%rip), %rsi      # 0x820b
callq 0x3360
movq -0x88(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x3360
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0x250f(%rip), %rsi      # 0x8222
callq 0x3360
movq -0x88(%rbp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq %rbx, %rdi
callq 0x3360
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5d8d
callq 0x32b0
jmp 0x5d8d
movl $0x1c, %edx
movq 0x5289(%rip), %rdi      # 0xafd8
leaq 0x24cf(%rip), %rsi      # 0x8225
callq 0x3360
movq 0x5276(%rip), %rcx      # 0xafd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32d0
movsbl %al, %esi
movq 0x5258(%rip), %rdi      # 0xafd8
callq 0x3030
movq %rax, %rdi
callq 0x31f0
leaq -0x88(%rbp), %rdi
callq 0x60e2
xorl %eax, %eax
testb %r12b, %r12b
je 0x5da2
xorl %eax, %eax
testl %eax, %eax
movq %r13, %rdi
je 0x58fa
leaq -0x68(%rbp), %rdi
callq 0x3470
leaq -0x60(%rbp), %rdi
callq 0x3470
leaq -0x58(%rbp), %rdi
callq 0x3470
movl 0x5582(%rip), %edi      # 0xb350
callq 0x34e0
cmpq $0x0, -0x58(%rbp)
jne 0x5f14
cmpq $0x0, -0x60(%rbp)
jne 0x5f14
cmpq $0x0, -0x68(%rbp)
jne 0x5f14
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x5efe
movq %rax, %rbx
jmp 0x5f05
movq %rax, %rbx
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x5f0c
callq 0x32b0
jmp 0x5f0c
jmp 0x5e84
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x5e57
callq 0x32b0
jmp 0x5e57
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq -0x90(%rbp), %rdi
jne 0x5e99
jmp 0x5e9e
jmp 0x5edd
jmp 0x5edd
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
jmp 0x5eed
jmp 0x5edd
jmp 0x5edd
movq %rax, %rbx
jmp 0x5e9e
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5e9e
callq 0x32b0
leaq -0x88(%rbp), %rdi
callq 0x60e2
jmp 0x5ef7
jmp 0x5ee2
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x5ed0
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
jmp 0x5ed0
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x643a
jmp 0x5ef7
jmp 0x5edd
jmp 0x5edd
jmp 0x5edd
movq %rax, %rbx
jmp 0x5ef7
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5ef7
callq 0x32b0
cmpq $0x0, -0x58(%rbp)
jne 0x5f14
cmpq $0x0, -0x60(%rbp)
jne 0x5f14
cmpq $0x0, -0x68(%rbp)
jne 0x5f14
movq %rbx, %rdi
callq 0x3480
callq 0x30a0
nop