// File: /workspace/github_cpp_makefile_star2_O3/huanghuide[P]SimpleNetworkTunnel/InnerInitiator.cpp
// Function: InnerInitiator::Init()
void InnerInitiator::Init()
{
    mSockFd = socket(AF_INET, SOCK_STREAM, 0);
    if (mSockFd < 0)
    {
        gLog.Write("Inner Initiator socket error!");
        exit(1);
    }

    // Set the timeout for sending and receiving
    struct timeval timeout = {3, 0};  
    
    int flags = setsockopt(mSockFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(struct timeval));
    if (flags != 0)
    {
        gLog.Write("Set socket send timeout error!");        
        exit(1); 
    }

    flags = setsockopt(mSockFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));
    if (flags != 0)
    {
        gLog.Write("Set socket receiving timeout error!");        
        exit(1);
    }

    // Set the send and recv buffer
    int bufSize = TCP_SOCK_BUF_SIZE;
    int bufLen = sizeof(int);
    
    flags = setsockopt(mSockFd, SOL_SOCKET, SO_SNDBUF, (char *)&bufSize, bufLen);
    if (flags != 0)
    {
        gLog.Write("Set socket sending buffer error!");        
        exit(1);
    }

    flags = setsockopt(mSockFd, SOL_SOCKET, SO_RCVBUF, (char *)&bufSize, bufLen);
    if (flags != 0)
    {
        gLog.Write("Set socket receiving buffer error!");        
        exit(1);
    }

    // Disable Nagle algorithm
    int enable = 1;
    flags = setsockopt(mSockFd, IPPROTO_TCP, TCP_NODELAY, (void*)&enable, sizeof(enable));
    if (flags != 0)
    {
        gLog.Write("Disable NAGLE algorithm error!");        
        exit(1);
    }


    bzero(&mAddr, sizeof(mAddr));
    
    mAddr.sin_family = AF_INET;
    mAddr.sin_port = htons(mListenPort);
    mAddr.sin_addr.s_addr = htonl(INADDR_ANY);

    // Reuse the socket
    int reuseFlag = 1;
    if (setsockopt(mSockFd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuseFlag, sizeof(int)) != 0)
    {
        gLog.Write("Cannot reuse the socket");
        
        exit(1);
    }

    // Bind the socket
    if (bind(mSockFd, (sockaddr*)&mAddr, mAddrLen) != 0)
    {
        gLog.Write("Inner Initiator bind socket error!");

        exit(1);
    }

    // Listen the socket
    if (listen(mSockFd, 256) != 0)
    {
        gLog.Write("Inner Initiator listen socket error!");

        exit(1);
    }

    // Add into runner manager
    AddSockFdIntoSet(mSockFd);   
    gRunnerManager.AddRunner(mSockFd, this);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdi, %rbx
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x20b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
js 0x2cb9
movups 0x36d4(%rip), %xmm0     # 0x6228
leaq -0x150(%rbp), %rcx
movaps %xmm0, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x15, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2cfc
movl 0xc(%rbx), %edi
leaq -0x150(%rbp), %rcx
movl $0x1, %esi
movl $0x14, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2d40
leaq -0x14(%rbp), %rcx
movl $0x40000, (%rcx)        # imm = 0x40000
movl 0xc(%rbx), %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2d84
movl 0xc(%rbx), %edi
leaq -0x14(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2dc8
leaq -0x1c(%rbp), %rcx
movl $0x1, (%rcx)
movl 0xc(%rbx), %edi
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2e0c
movq $0x0, 0x30(%rbx)
movw $0x2, 0x28(%rbx)
movzwl 0x3c(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2a(%rbx)
movl $0x0, 0x2c(%rbx)
leaq -0x18(%rbp), %rcx
movl $0x1, (%rcx)
movl 0xc(%rbx), %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2e50
leaq 0x28(%rbx), %rsi
movl 0xc(%rbx), %edi
movl 0x38(%rbx), %edx
callq 0x2060
testl %eax, %eax
jne 0x2e85
movl 0xc(%rbx), %edi
movl $0x100, %esi            # imm = 0x100
callq 0x22c0
testl %eax, %eax
jne 0x2eba
movl 0xc(%rbx), %edi
callq 0x270d
movl 0xc(%rbx), %esi
leaq 0x81bb(%rip), %rdi      # 0xae60
movq %rbx, %rdx
callq 0x4bdc
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r14
popq %rbp
retq
leaq -0x130(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3436(%rip), %rsi      # 0x6101
leaq 0x344c(%rip), %rdx      # 0x611e
leaq -0x140(%rbp), %rbx
movq %rbx, %rdi
callq 0x2a2e
leaq 0x8170(%rip), %rdi      # 0xae58
movq %rbx, %rsi
callq 0x387c
leaq -0x140(%rbp), %rdi
jmp 0x2eed
leaq -0x110(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3411(%rip), %rsi      # 0x611f
leaq 0x3428(%rip), %rdx      # 0x613d
leaq -0x120(%rbp), %rdi
callq 0x2a2e
leaq 0x8130(%rip), %rdi      # 0xae58
leaq -0x120(%rbp), %rsi
callq 0x387c
leaq -0x120(%rbp), %rdi
jmp 0x2eed
leaq -0xf0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33ec(%rip), %rsi      # 0x613e
leaq 0x3408(%rip), %rdx      # 0x6161
leaq -0x100(%rbp), %rdi
callq 0x2a2e
leaq 0x80ec(%rip), %rdi      # 0xae58
leaq -0x100(%rbp), %rsi
callq 0x387c
leaq -0x100(%rbp), %rdi
jmp 0x2eed
leaq -0xd0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33cc(%rip), %rsi      # 0x6162
leaq 0x33e5(%rip), %rdx      # 0x6182
leaq -0xe0(%rbp), %rdi
callq 0x2a2e
leaq 0x80a8(%rip), %rdi      # 0xae58
leaq -0xe0(%rbp), %rsi
callq 0x387c
leaq -0xe0(%rbp), %rdi
jmp 0x2eed
leaq -0xb0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33a9(%rip), %rsi      # 0x6183
leaq 0x33c4(%rip), %rdx      # 0x61a5
leaq -0xc0(%rbp), %rdi
callq 0x2a2e
leaq 0x8064(%rip), %rdi      # 0xae58
leaq -0xc0(%rbp), %rsi
callq 0x387c
leaq -0xc0(%rbp), %rdi
jmp 0x2eed
leaq -0x90(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3388(%rip), %rsi      # 0x61a6
leaq 0x339f(%rip), %rdx      # 0x61c4
leaq -0xa0(%rbp), %rdi
callq 0x2a2e
leaq 0x8020(%rip), %rdi      # 0xae58
leaq -0xa0(%rbp), %rsi
callq 0x387c
leaq -0xa0(%rbp), %rdi
jmp 0x2eed
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3366(%rip), %rsi      # 0x61c5
leaq 0x3376(%rip), %rdx      # 0x61dc
leaq -0x80(%rbp), %rdi
callq 0x2a2e
leaq 0x7fe2(%rip), %rdi      # 0xae58
leaq -0x80(%rbp), %rsi
callq 0x387c
leaq -0x80(%rbp), %rdi
jmp 0x2eed
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3349(%rip), %rsi      # 0x61dd
leaq 0x3364(%rip), %rdx      # 0x61ff
leaq -0x60(%rbp), %rdi
callq 0x2a2e
leaq 0x7fad(%rip), %rdi      # 0xae58
leaq -0x60(%rbp), %rsi
callq 0x387c
leaq -0x60(%rbp), %rdi
jmp 0x2eed
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3337(%rip), %rsi      # 0x6200
leaq 0x3354(%rip), %rdx      # 0x6224
leaq -0x40(%rbp), %rdi
callq 0x2a2e
leaq 0x7f78(%rip), %rdi      # 0xae58
leaq -0x40(%rbp), %rsi
callq 0x387c
leaq -0x40(%rbp), %rdi
callq 0x2130
movl $0x1, %edi
callq 0x2300
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x30(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x50(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x70(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x90(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0xb0(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0xd0(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0xf0(%rbp), %rsi
jmp 0x2ff3
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x110(%rbp), %rsi
jmp 0x2ff3
jmp 0x2fd8
jmp 0x2fd8
jmp 0x2fd8
jmp 0x2fd8
jmp 0x2fd8
jmp 0x2fd8
jmp 0x2fd8
movq %rax, %rbx
jmp 0x2ffb
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ffb
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x2380
nop