// File: /workspace/github_cpp_makefile_star2_O2/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, -0x4c(%rbp) # imm = 0xFFFFFE6C
leaq 0x28cf(%rip), %rsi      # 0x719b
leaq -0xb0(%rbp), %rdi
leaq -0x2a0(%rbp), %rdx
callq 0x30e0
leaq -0xb0(%rbp), %rsi
pushq $0x1
popq %rdx
movl $0x22b8, %edi           # imm = 0x22B8
callq 0x6a09
movl %eax, 0x6a3f(%rip)      # 0xb338
leaq 0x6a38(%rip), %rbx      # 0xb338
leaq -0xb0(%rbp), %rdi
callq 0x3110
movq 0x66c5(%rip), %r14      # 0xafd8
leaq 0x288b(%rip), %rsi      # 0x71a5
movq %r14, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3140
leaq 0x2895(%rip), %rsi      # 0x71c6
movq %r14, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3140
leaq 0x289d(%rip), %rsi      # 0x71e5
movq %r14, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3140
movl $0x10, 0x6b2e(%rip)     # 0xb490
leaq 0x6a97(%rip), %rdi      # 0xb400
movq %rbx, %rsi
callq 0x5d1c
leaq -0x90(%rbp), %rsi
andl $0x0, (%rsi)
leaq 0x6ade(%rip), %rdi      # 0xb460
callq 0x6632
leaq -0x71f(%rip), %rbx      # 0x426f
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x51ee
leaq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x51ee
leaq -0x73e(%rip), %rsi      # 0x426f
leaq -0x38(%rbp), %rdi
callq 0x51ee
leaq 0x6993(%rip), %rbx      # 0xb350
leaq -0x1a0(%rbp), %r12
movq 0x660d(%rip), %r14      # 0xafd8
leaq -0x170(%rbp), %rdi
leaq 0x6a27(%rip), %rsi      # 0xb400
callq 0x54a8
movq %rbx, %r15
movq %rbx, %rdi
leaq -0x170(%rbp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6ad9
movl %eax, %r13d
movq %rbx, %rdi
movl 0x6937(%rip), %ebx      # 0xb338
callq 0x53a4
cmpl %ebx, %r13d
movq %r15, %rbx
jne 0x4a21
leaq 0x687b(%rip), %rdi      # 0xb290
leaq 0x691c(%rip), %rsi      # 0xb338
callq 0x525c
leaq -0x140(%rbp), %rdi
leaq 0x6a01(%rip), %rsi      # 0xb430
callq 0x54a8
movq %rbx, %rdi
leaq -0x140(%rbp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0x6ad9
movl %eax, %r13d
movq %r15, %rdi
callq 0x53a4
movl %r13d, -0x2c(%rbp)
leaq 0x69d2(%rip), %rdi      # 0xb430
leaq -0x2c(%rbp), %rsi
callq 0x51ac
cmpq $0x1, %rax
jne 0x4a7d
leaq 0x681c(%rip), %rdi      # 0xb290
leaq -0x2c(%rbp), %rsi
callq 0x525c
movq %r12, %rdi
leaq 0x69d9(%rip), %rsi      # 0xb460
callq 0x54a8
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x6ad9
movl %eax, %r13d
movq %r12, %rdi
callq 0x53a4
testl %r13d, %r13d
jne 0x49cb
movl $0xff, %edx
xorl %edi, %edi
leaq -0x2a0(%rbp), %rsi
callq 0x33a0
cmpb $0x65, -0x2a0(%rbp)
jne 0x4ae2
cmpb $0x6e, -0x29f(%rbp)
jne 0x4ae2
cmpb $0x64, -0x29e(%rbp)
je 0x4c0c
leaq -0x110(%rbp), %r15
movq %r15, %rdi
leaq -0x2a0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x30e0
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
pushq $0x26
popq %rdx
callq 0x6bd1
movq %r15, %rdi
callq 0x3110
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x4be7
leaq -0xd0(%rbp), %rdi
callq 0x3380
movq %r12, %r14
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
leaq -0xf0(%rbp), %r12
movq %r12, %rdi
callq 0x3380
leaq -0xd0(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x408e
movl %eax, %r13d
movq %r12, %rdi
callq 0x3110
movq %r15, %rdi
callq 0x3110
testb %r13b, %r13b
movq %r14, %r12
movq 0x6455(%rip), %r14      # 0xafd8
je 0x4be7
leaq -0x90(%rbp), %r15
movq %r15, %rdi
callq 0x6999
movq %r14, %rdi
movq %r15, %rsi
callq 0x3260
movq %rax, %rdi
leaq 0x2662(%rip), %rsi      # 0x720b
callq 0x32b0
movq -0x68(%rbp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
leaq 0x265e(%rip), %rsi      # 0x7222
callq 0x32b0
movq -0x68(%rbp), %rsi
addq $0x20, %rsi
movq %rax, %rdi
callq 0x3260
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x4bfe
movq %r14, %rdi
leaq 0x2634(%rip), %rsi      # 0x7225
callq 0x32b0
movq %rax, %rdi
callq 0x3140
leaq -0x68(%rbp), %rdi
callq 0x5020
jmp 0x49cb
leaq -0x90(%rbp), %rdi
callq 0x6999
movq 0x63b9(%rip), %rdi      # 0xafd8
leaq -0x90(%rbp), %rsi
callq 0x3260
leaq 0x25bf(%rip), %rsi      # 0x71f1
movq %rax, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3140
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0x3110
movq 0x6790(%rip), %r12      # 0xb3e8
leaq 0x6779(%rip), %r13      # 0xb3d8
movq 0x6372(%rip), %r14      # 0xafd8
leaq 0x2594(%rip), %r15      # 0x7201
cmpq %r13, %r12
je 0x4cba
leaq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x51d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %rdi
movq %r15, %rsi
callq 0x32b0
movq %rax, %rdi
callq 0x3140
movl -0x70(%rbp), %edi
callq 0x34b0
movq %rbx, %rdi
callq 0x3110
movq %r12, %rdi
callq 0x31f0
movq %rax, %r12
jmp 0x4c6d
pushq $0x3
popq %r15
leaq 0x65cb(%rip), %rbx      # 0xb290
leaq -0x4c(%rbp), %r14
subl $0x1, %r15d
jb 0x4cdc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x525c
jmp 0x4cc9
leaq -0x48(%rbp), %rdi
callq 0x3430
leaq -0x40(%rbp), %rdi
callq 0x3430
leaq -0x38(%rbp), %rdi
callq 0x3430
movl 0x663b(%rip), %edi      # 0xb338
callq 0x34b0
leaq -0x38(%rbp), %rdi
callq 0x52b8
leaq -0x40(%rbp), %rdi
callq 0x52b8
leaq -0x48(%rbp), %rdi
callq 0x52b8
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4dfa
movq %rax, %rbx
jmp 0x4e06
movq %rax, %rbx
jmp 0x4e0f
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x3110
jmp 0x4e18
movq %rax, %rbx
jmp 0x4e18
jmp 0x4de7
jmp 0x4dfa
jmp 0x4db0
movq %rax, %rbx
jmp 0x4d82
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x3110
leaq -0xd0(%rbp), %rdi
jmp 0x4da9
jmp 0x4dfa
jmp 0x4dfa
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
jmp 0x4df1
jmp 0x4dfa
jmp 0x4dfa
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x4db3
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x5020
jmp 0x4dfd
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x4de0
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
jmp 0x4de0
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
callq 0x53a4
jmp 0x4dfd
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x4dfd
jmp 0x4dfa
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x52b8
leaq -0x40(%rbp), %rdi
callq 0x52b8
leaq -0x48(%rbp), %rdi
callq 0x52b8
movq %rbx, %rdi
callq 0x3440