// File: huanghuide[P]SimpleNetworkTunnel/Main.cpp
// Function: main
int main(int argc, char *argv[])
{
    fd_set readFdSet;
    fd_set writeFdSet;
    struct timeval timeout;
    int ret;

    gLog.Write("---------------------");
    gLog.Write("BBServer start !!!!!!");
    gLog.Write("---------------------");

    signal(SIGPIPE, SIG_IGN);
    ParseParamsAndInit(argc, argv);

    while (!gStopFlag)
    {
        FD_ZERO(&readFdSet);         
        readFdSet = gReadSockFdSet;
        writeFdSet = gWriteSockFdSet;

        timeout.tv_sec = 0;
        timeout.tv_usec = 100000;

        ret = select(gMaxSockFd + 1, &readFdSet, NULL, NULL, &timeout);

        if (ret > 0)
        {
            for (int sockFd = gMaxSockFd; sockFd > 0; sockFd--)
            {
                if (FD_ISSET(sockFd, &readFdSet))
                {
                    Runner* pRunner = gRunnerManager.FindRunnerByFd(sockFd);
                    
                    if (pRunner != NULL)
                    {
                        pRunner->SocketRead(sockFd);
                    }

                    FD_CLR(sockFd, &readFdSet);
                }

                if (FD_ISSET(sockFd, &writeFdSet))
                {
                    Runner* pRunner = gRunnerManager.FindRunnerByFd(sockFd);
                    
                    if (pRunner != NULL)
                    {
                        pRunner->SocketWrite(sockFd);
                    }
                
                    FD_CLR(sockFd, &writeFdSet);
                }
            }
        }
        else if (ret == 0)
        {
            gRunnerManager.RunnerTimeout();
        }
    }

    gLog.Write("~~~~~~~~~~~~~~~~~~~");
    gLog.Write("BBServer end !!!!!!");
    gLog.Write("~~~~~~~~~~~~~~~~~~~");
    gLog.Write("                   ");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x149(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x34d0
movq -0x278(%rbp), %rdx
leaq 0x4994(%rip), %rsi      # 0xb31e
leaq -0x148(%rbp), %rdi
callq 0x3ec0
jmp 0x6998
leaq 0xb559(%rip), %rdi      # 0x11ef8
leaq -0x148(%rbp), %rsi
callq 0x6280
jmp 0x69ad
leaq -0x148(%rbp), %rdi
callq 0x3210
leaq -0x149(%rbp), %rdi
callq 0x3390
leaq -0x181(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x34d0
movq -0x280(%rbp), %rdx
leaq 0x494e(%rip), %rsi      # 0xb334
leaq -0x180(%rbp), %rdi
callq 0x3ec0
jmp 0x69f4
leaq 0xb4fd(%rip), %rdi      # 0x11ef8
leaq -0x180(%rbp), %rsi
callq 0x6280
jmp 0x6a09
leaq -0x180(%rbp), %rdi
callq 0x3210
leaq -0x181(%rbp), %rdi
callq 0x3390
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x34d0
movq -0x288(%rbp), %rdx
leaq 0x48dc(%rip), %rsi      # 0xb31e
leaq -0x1a8(%rbp), %rdi
callq 0x3ec0
jmp 0x6a50
leaq 0xb4a1(%rip), %rdi      # 0x11ef8
leaq -0x1a8(%rbp), %rsi
callq 0x6280
jmp 0x6a65
leaq -0x1a8(%rbp), %rdi
callq 0x3210
leaq -0x1a9(%rbp), %rdi
callq 0x3390
movl $0xd, %edi
movl $0x1, %esi
callq 0x3410
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x6780
leaq 0x9821(%rip), %rax      # 0x102c0
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6aac
jmp 0x6e18
jmp 0x6aae
leaq -0x90(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl $0x0, -0x1b0(%rbp)
movl -0x1b0(%rbp), %eax
cmpq $0x10, %rax
jae 0x6bc5
movq -0x1b8(%rbp), %rax
movl -0x1b0(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x6ac6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x6b2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3210
leaq -0x149(%rbp), %rdi
callq 0x3390
jmp 0x7095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x6b71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x3210
leaq -0x181(%rbp), %rdi
callq 0x3390
jmp 0x7095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x6bb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3210
leaq -0x1a9(%rbp), %rdi
callq 0x3390
jmp 0x7095
jmp 0x6bc7
leaq -0x90(%rbp), %rdi
leaq 0xb36b(%rip), %rsi      # 0x11f40
movl $0x80, %edx
callq 0x32a0
leaq -0x110(%rbp), %rdi
leaq 0xb3d3(%rip), %rsi      # 0x11fc0
movl $0x80, %edx
callq 0x32a0
movq $0x0, -0x120(%rbp)
movq $0x186a0, -0x118(%rbp) # imm = 0x186A0
leaq 0xb42c(%rip), %rax      # 0x12040
movl (%rax), %edi
addl $0x1, %edi
leaq -0x90(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x120(%rbp), %r8
movq %rcx, %rdx
callq 0x3310
movl %eax, -0x124(%rbp)
cmpl $0x0, -0x124(%rbp)
jle 0x6dfc
leaq 0xb3f3(%rip), %rax      # 0x12040
movl (%rax), %eax
movl %eax, -0x1bc(%rbp)
cmpl $0x0, -0x1bc(%rbp)
jle 0x6dfa
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x90(%rbp,%rax,8), %rax
movq %rax, -0x290(%rbp)
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x290(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x6d23
movl -0x1bc(%rbp), %esi
leaq 0xb247(%rip), %rdi      # 0x11f00
callq 0x8160
movq %rax, -0x1c8(%rbp)
cmpq $0x0, -0x1c8(%rbp)
je 0x6ce2
movq -0x1c8(%rbp), %rdi
movl -0x1bc(%rbp), %esi
movq (%rdi), %rax
callq *0x10(%rax)
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
xorq $-0x1, %rcx
movl -0x1bc(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
andq -0x90(%rbp,%rax,8), %rcx
movq %rcx, -0x90(%rbp,%rax,8)
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x110(%rbp,%rax,8), %rax
movq %rax, -0x298(%rbp)
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x298(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x6de4
movl -0x1bc(%rbp), %esi
leaq 0xb186(%rip), %rdi      # 0x11f00
callq 0x8160
movq %rax, -0x1d0(%rbp)
cmpq $0x0, -0x1d0(%rbp)
je 0x6da3
movq -0x1d0(%rbp), %rdi
movl -0x1bc(%rbp), %esi
movq (%rdi), %rax
callq *0x18(%rax)
movl -0x1bc(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
xorq $-0x1, %rcx
movl -0x1bc(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
andq -0x110(%rbp,%rax,8), %rcx
movq %rcx, -0x110(%rbp,%rax,8)
jmp 0x6de6
movl -0x1bc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x6c55
jmp 0x6e13
cmpl $0x0, -0x124(%rbp)
jne 0x6e11
leaq 0xb0f4(%rip), %rdi      # 0x11f00
callq 0x8200
jmp 0x6e13
jmp 0x6a98
leaq -0x1f1(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x34d0
movq -0x2a0(%rbp), %rdx
leaq 0x4511(%rip), %rsi      # 0xb34a
leaq -0x1f0(%rbp), %rdi
callq 0x3ec0
jmp 0x6e47
leaq 0xb0aa(%rip), %rdi      # 0x11ef8
leaq -0x1f0(%rbp), %rsi
callq 0x6280
jmp 0x6e5c
leaq -0x1f0(%rbp), %rdi
callq 0x3210
leaq -0x1f1(%rbp), %rdi
callq 0x3390
leaq -0x219(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x34d0
movq -0x2a8(%rbp), %rdx
leaq 0x44c9(%rip), %rsi      # 0xb35e
leaq -0x218(%rbp), %rdi
callq 0x3ec0
jmp 0x6ea3
leaq 0xb04e(%rip), %rdi      # 0x11ef8
leaq -0x218(%rbp), %rsi
callq 0x6280
jmp 0x6eb8
leaq -0x218(%rbp), %rdi
callq 0x3210
leaq -0x219(%rbp), %rdi
callq 0x3390
leaq -0x241(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x34d0
movq -0x2b0(%rbp), %rdx
leaq 0x4459(%rip), %rsi      # 0xb34a
leaq -0x240(%rbp), %rdi
callq 0x3ec0
jmp 0x6eff
leaq 0xaff2(%rip), %rdi      # 0x11ef8
leaq -0x240(%rbp), %rsi
callq 0x6280
jmp 0x6f14
leaq -0x240(%rbp), %rdi
callq 0x3210
leaq -0x241(%rbp), %rdi
callq 0x3390
leaq -0x269(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x34d0
movq -0x2b8(%rbp), %rdx
leaq 0x4425(%rip), %rsi      # 0xb372
leaq -0x268(%rbp), %rdi
callq 0x3ec0
jmp 0x6f5b
leaq 0xaf96(%rip), %rdi      # 0x11ef8
leaq -0x268(%rbp), %rsi
callq 0x6280
jmp 0x6f70
leaq -0x268(%rbp), %rdi
callq 0x3210
leaq -0x269(%rbp), %rdi
callq 0x3390
movl -0x4(%rbp), %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x6fc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x3210
leaq -0x1f1(%rbp), %rdi
callq 0x3390
jmp 0x7095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x7009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3210
leaq -0x219(%rbp), %rdi
callq 0x3390
jmp 0x7095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x7049
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3210
leaq -0x241(%rbp), %rdi
callq 0x3390
jmp 0x7095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0x7089
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3210
leaq -0x269(%rbp), %rdi
callq 0x3390
movq -0x158(%rbp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)