// File: /workspace/github_cpp_makefile_star2_O3/qian-jiahong[P]uvncrep017-ws/repeaterevents.cpp
// Function: doEventWork()
static int doEventWork(void)
{
    char eventMessageToListener[MAX_EVENT_MSG_LEN];
    connectionEvent *connEv;
    sessionEvent *sessEv;
    startEndEvent *seEv;
    int eventNum;
    repeaterEvent ev;
    int connection;
    char eventListenerIp[MAX_IP_LEN];
    int msgLen;
    int formatStrInd;
    
    if (useHttpForEventListener) {
    	formatStrInd = 1;
    }
    else {
    	formatStrInd = 0;
    }
    
    connection = openConnectionToEventListener(eventListenerHost, eventListenerPort, eventListenerIp, MAX_IP_LEN);  
    if (-1 != connection) {
        while(!isFifoEmpty()) {
            ev = eventFifo[fifoTailInd];
            itemsInFifo--;
            fifoTailInd = advanceFifoIndex(fifoTailInd);
        
            eventNum = ev.eventNum;
    
            switch (eventNum) {
                case VIEWER_CONNECT:
                    //Fall through
                case VIEWER_DISCONNECT:
                    //Fall through
                case SERVER_CONNECT:
                    //Fall through
                case SERVER_DISCONNECT:
                    connEv = (connectionEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[0][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        connEv -> tableIndex, connEv -> code, connEv -> connMode, connEv->peerIp.a,
                        connEv->peerIp.b, connEv->peerIp.c, connEv->peerIp.d);  
                    break;
            
                case VIEWER_SERVER_SESSION_START:
                    //Fall through
                case VIEWER_SERVER_SESSION_END:
                    sessEv = (sessionEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[1][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        sessEv -> serverTableIndex, sessEv -> viewerTableIndex, sessEv -> code, sessEv -> connMode, 
                        sessEv->serverIp.a, sessEv->serverIp.b, sessEv->serverIp.c, sessEv->serverIp.d,
                        sessEv->viewerIp.a, sessEv->viewerIp.b, sessEv->viewerIp.c, sessEv->viewerIp.d);  
                    break;
            
                case REPEATER_STARTUP:
                    //Fall through
                case REPEATER_SHUTDOWN:
                    //Fall through
                case REPEATER_HEARTBEAT:
                    seEv = (startEndEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[2][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        seEv -> maxSessions);  
                    break;
            
                default:
                    msgLen = 0;
                    strlcpy(eventMessageToListener, "\n", MAX_EVENT_MSG_LEN);
                    break;
            }

            if (msgLen > 0) { 
                writeExact(connection, eventMessageToListener, 
                    strlen(eventMessageToListener), TIMEOUT_5SECS);
                    
                debug(LEVEL_3, "%s", eventMessageToListener);
            }
        }
    
        close(connection);
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
leaq 0xe9d9(%rip), %rax      # 0x152c5
movzbl (%rax), %eax
movq %rax, 0x8(%rsp)
leaq 0x6255(%rip), %rax      # 0xcb50
movzwl (%rax), %esi
leaq 0x614b(%rip), %rdi      # 0xca50
leaq 0x110(%rsp), %rdx
movl $0x32, %ecx
callq 0x35df
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x6b32
movl 0xe9ae(%rip), %eax      # 0x152d8
testl %eax, %eax
je 0x6b29
leaq 0xe9a7(%rip), %r14      # 0x152e0
movslq 0xe994(%rip), %rcx      # 0x152d4
imulq $0x78, %rcx, %rdx
decl %eax
leal 0x1(%rcx), %esi
cmpq $0x1f3, %rcx            # imm = 0x1F3
movl (%rdx,%r14), %r8d
movq 0x8(%rdx,%r14), %r9
movl 0x10(%rdx,%r14), %ecx
movl 0x14(%rdx,%r14), %edi
movl 0x18(%rdx,%r14), %r10d
movq %r10, 0x38(%rsp)
movq 0x1c(%rdx,%r14), %r10
movq %r10, 0x30(%rsp)
movl 0x24(%rdx,%r14), %r10d
movq %r10, 0x28(%rsp)
movl 0x28(%rdx,%r14), %r10d
movq %r10, 0x20(%rsp)
movl 0x2c(%rdx,%r14), %r13d
movl 0x30(%rdx,%r14), %r10d
movl 0x34(%rdx,%r14), %r15d
movl 0x38(%rdx,%r14), %r11d
movl %eax, 0xe933(%rip)      # 0x152d8
movl 0x3c(%rdx,%r14), %r12d
movl $0x0, %eax
cmovgel %eax, %esi
movl %esi, 0xe91c(%rip)      # 0x152d4
movl 0x40(%rdx,%r14), %ebp
movl 0x44(%rdx,%r14), %ebx
cmpl $0x8, %r8d
ja 0x6b11
movl $0xf, %eax
btl %r8d, %eax
jb 0x6a24
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl $0x1c0, %eax            # imm = 0x1C0
btl %r8d, %eax
jae 0x6a6b
movq 0x8(%rsp), %rax
leaq 0x5398(%rip), %rcx      # 0xbd90
movq 0x20(%rcx,%rax,8), %rdx
movl $0xc8, %esi
leaq 0x40(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0x2310
addq $0x10, %rsp
jmp 0x6ac7
movq 0x8(%rsp), %rax
movq %rcx, %r11
leaq 0x535d(%rip), %rcx      # 0xbd90
movq (%rcx,%rax,8), %rdx
movl $0xc8, %esi
movq %rdi, %rbx
leaq 0x40(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq %r15
pushq %r10
pushq %r13
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq 0x58(%rsp)
pushq %rbx
pushq %r11
callq 0x2310
addq $0x40, %rsp
jmp 0x6ac7
movq 0x8(%rsp), %rax
leaq 0x5319(%rip), %rcx      # 0xbd90
movq 0x10(%rcx,%rax,8), %rdx
subq $0x8, %rsp
movl $0xc8, %esi
leaq 0x48(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq %rbx
pushq %rbp
pushq %r12
pushq %r11
pushq %r15
pushq %r10
pushq %r13
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
callq 0x2310
addq $0x70, %rsp
testl %eax, %eax
jle 0x6b01
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x20d0
movl 0x4(%rsp), %edi
movq %rbx, %rsi
movl %eax, %edx
movl $0x5, %ecx
callq 0x3957
movl $0x3, %edi
leaq 0x1579(%rip), %rsi      # 0x8070
movq %rbx, %rdx
xorl %eax, %eax
callq 0x352c
movl 0xe7d1(%rip), %eax      # 0x152d8
testl %eax, %eax
jne 0x6939
jmp 0x6b29
movl $0xc8, %edx
leaq 0x40(%rsp), %rdi
leaq 0x1ab7(%rip), %rsi      # 0x85d9
callq 0x5804
jmp 0x6b01
movl 0x4(%rsp), %edi
callq 0x2360
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq