// File: /workspace/github_cpp_makefile_star2_O1/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 0x2cb4
movups 0x36d8(%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 0x2cf7
movl 0xc(%rbx), %edi
leaq -0x150(%rbp), %rcx
movl $0x1, %esi
movl $0x14, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2d3b
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 0x2d7f
movl 0xc(%rbx), %edi
leaq -0x14(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
jne 0x2dc3
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 0x2e07
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%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 0x2e4b
leaq 0x28(%rbx), %rsi
movl 0xc(%rbx), %edi
movl 0x38(%rbx), %edx
callq 0x2060
testl %eax, %eax
jne 0x2e80
movl 0xc(%rbx), %edi
movl $0x100, %esi            # imm = 0x100
callq 0x22c0
testl %eax, %eax
jne 0x2eb5
movl 0xc(%rbx), %edi
callq 0x270d
movl 0xc(%rbx), %esi
leaq 0x81c0(%rip), %rdi      # 0xae60
movq %rbx, %rdx
callq 0x4c80
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r14
popq %rbp
retq
leaq -0x130(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x343b(%rip), %rsi      # 0x6101
leaq 0x3451(%rip), %rdx      # 0x611e
leaq -0x140(%rbp), %rbx
movq %rbx, %rdi
callq 0x2a2c
leaq 0x8175(%rip), %rdi      # 0xae58
movq %rbx, %rsi
callq 0x38c4
leaq -0x140(%rbp), %rdi
jmp 0x2ee8
leaq -0x110(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x3416(%rip), %rsi      # 0x611f
leaq 0x342d(%rip), %rdx      # 0x613d
leaq -0x120(%rbp), %rdi
callq 0x2a2c
leaq 0x8135(%rip), %rdi      # 0xae58
leaq -0x120(%rbp), %rsi
callq 0x38c4
leaq -0x120(%rbp), %rdi
jmp 0x2ee8
leaq -0xf0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33f1(%rip), %rsi      # 0x613e
leaq 0x340d(%rip), %rdx      # 0x6161
leaq -0x100(%rbp), %rdi
callq 0x2a2c
leaq 0x80f1(%rip), %rdi      # 0xae58
leaq -0x100(%rbp), %rsi
callq 0x38c4
leaq -0x100(%rbp), %rdi
jmp 0x2ee8
leaq -0xd0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33d1(%rip), %rsi      # 0x6162
leaq 0x33ea(%rip), %rdx      # 0x6182
leaq -0xe0(%rbp), %rdi
callq 0x2a2c
leaq 0x80ad(%rip), %rdi      # 0xae58
leaq -0xe0(%rbp), %rsi
callq 0x38c4
leaq -0xe0(%rbp), %rdi
jmp 0x2ee8
leaq -0xb0(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x33ae(%rip), %rsi      # 0x6183
leaq 0x33c9(%rip), %rdx      # 0x61a5
leaq -0xc0(%rbp), %rdi
callq 0x2a2c
leaq 0x8069(%rip), %rdi      # 0xae58
leaq -0xc0(%rbp), %rsi
callq 0x38c4
leaq -0xc0(%rbp), %rdi
jmp 0x2ee8
leaq -0x90(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x338d(%rip), %rsi      # 0x61a6
leaq 0x33a4(%rip), %rdx      # 0x61c4
leaq -0xa0(%rbp), %rdi
callq 0x2a2c
leaq 0x8025(%rip), %rdi      # 0xae58
leaq -0xa0(%rbp), %rsi
callq 0x38c4
leaq -0xa0(%rbp), %rdi
jmp 0x2ee8
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x336b(%rip), %rsi      # 0x61c5
leaq 0x337b(%rip), %rdx      # 0x61dc
leaq -0x80(%rbp), %rdi
callq 0x2a2c
leaq 0x7fe7(%rip), %rdi      # 0xae58
leaq -0x80(%rbp), %rsi
callq 0x38c4
leaq -0x80(%rbp), %rdi
jmp 0x2ee8
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x334e(%rip), %rsi      # 0x61dd
leaq 0x3369(%rip), %rdx      # 0x61ff
leaq -0x60(%rbp), %rdi
callq 0x2a2c
leaq 0x7fb2(%rip), %rdi      # 0xae58
leaq -0x60(%rbp), %rsi
callq 0x38c4
leaq -0x60(%rbp), %rdi
jmp 0x2ee8
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x333c(%rip), %rsi      # 0x6200
leaq 0x3359(%rip), %rdx      # 0x6224
leaq -0x40(%rbp), %rdi
callq 0x2a2c
leaq 0x7f7d(%rip), %rdi      # 0xae58
leaq -0x40(%rbp), %rsi
callq 0x38c4
leaq -0x40(%rbp), %rdi
callq 0x2130
movl $0x1, %edi
callq 0x2300
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x30(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x50(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x70(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x90(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0xb0(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0xd0(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0xf0(%rbp), %rsi
jmp 0x2fee
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x110(%rbp), %rsi
jmp 0x2fee
jmp 0x2fd3
jmp 0x2fd3
jmp 0x2fd3
jmp 0x2fd3
jmp 0x2fd3
jmp 0x2fd3
jmp 0x2fd3
movq %rax, %rbx
jmp 0x2ff6
movq %rax, %rbx
movq -0x140(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ff6
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x2380