// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
leaq 0xf02a(%rip), %rax      # 0x182f5
testb $0x1, (%rax)
je 0x92dc
movl $0x1, -0x1d8(%rbp)
jmp 0x92e6
movl $0x0, -0x1d8(%rbp)
leaq 0x6863(%rip), %rax      # 0xfb50
movl (%rax), %eax
leaq -0x1d0(%rbp), %rdx
leaq 0x6753(%rip), %rdi      # 0xfa50
movl $0x32, %ecx
movzwl %ax, %esi
callq 0x26c0
movl %eax, -0x194(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x194(%rbp), %eax
je 0x9737
jmp 0x9323
callq 0x9290
xorb $-0x1, %al
testb $0x1, %al
jne 0x9333
jmp 0x972c
movslq 0xefca(%rip), %rax      # 0x18304
imulq $0x78, %rax, %rax
movq %rax, -0x1f0(%rbp)
leaq 0xefc4(%rip), %rcx      # 0x18310
movq %rcx, -0x1e8(%rbp)
movq 0x70(%rax,%rcx), %rdx
movq %rdx, -0x120(%rbp)
movups 0x60(%rax,%rcx), %xmm0
movaps %xmm0, -0x130(%rbp)
movups 0x50(%rax,%rcx), %xmm0
movaps %xmm0, -0x140(%rbp)
movups 0x40(%rax,%rcx), %xmm0
movaps %xmm0, -0x150(%rbp)
movups (%rax,%rcx), %xmm0
movups 0x10(%rax,%rcx), %xmm1
movups 0x20(%rax,%rcx), %xmm2
movups 0x30(%rax,%rcx), %xmm3
movaps %xmm3, -0x160(%rbp)
movaps %xmm2, -0x170(%rbp)
movaps %xmm1, -0x180(%rbp)
movaps %xmm0, -0x190(%rbp)
movl 0xef50(%rip), %eax      # 0x18308
decl %eax
movl %eax, 0xef48(%rip)      # 0x18308
movl 0xef3e(%rip), %edi      # 0x18304
callq 0x91d0
movl %eax, 0xef33(%rip)      # 0x18304
movl -0x190(%rbp), %eax
movl %eax, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
movl %eax, -0x1dc(%rbp)
subl $0x4, %eax
jb 0x941b
jmp 0x93f0
movl -0x1dc(%rbp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0x94e6
jmp 0x9404
movl -0x1dc(%rbp), %eax
addl $-0x6, %eax
subl $0x3, %eax
jb 0x9638
jmp 0x96a3
leaq -0x190(%rbp), %rax
addq $0x14, %rax
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
movslq -0x1d8(%rbp), %rcx
leaq 0x671e(%rip), %rax      # 0xfb60
movq (%rax,%rcx,8), %rdx
movl -0x10c(%rbp), %r8d
movq -0x188(%rbp), %r9
movl -0x180(%rbp), %r13d
movq -0xf8(%rbp), %rax
movl (%rax), %r12d
movq -0xf8(%rbp), %rax
movq 0x8(%rax), %r15
movq -0xf8(%rbp), %rax
movl 0x10(%rax), %r14d
movq -0xf8(%rbp), %rax
movl 0x14(%rax), %ebx
movq -0xf8(%rbp), %rax
movl 0x18(%rax), %r11d
movq -0xf8(%rbp), %rax
movl 0x1c(%rax), %r10d
movq -0xf8(%rbp), %rax
movl 0x20(%rax), %eax
movl $0xc8, %esi
movl $0x1, %ecx
movl %r13d, (%rsp)
movl %r12d, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movl %r10d, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movb $0x0, %al
callq 0x2320
movl %eax, -0x1d4(%rbp)
jmp 0x96c5
leaq -0x190(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x100(%rbp)
leaq -0xf0(%rbp), %rdi
movslq -0x1d8(%rbp), %rcx
leaq 0x6653(%rip), %rax      # 0xfb60
movq 0x10(%rax,%rcx,8), %rdx
movl -0x10c(%rbp), %r8d
movq -0x188(%rbp), %r9
movl -0x180(%rbp), %eax
movq -0x100(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, -0x208(%rbp)
movq -0x100(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, -0x204(%rbp)
movq -0x100(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, -0x200(%rbp)
movq -0x100(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, -0x1f8(%rbp)
movq -0x100(%rbp), %rcx
movl 0x14(%rcx), %r13d
movq -0x100(%rbp), %rcx
movl 0x18(%rcx), %r12d
movq -0x100(%rbp), %rcx
movl 0x1c(%rcx), %r15d
movq -0x100(%rbp), %rcx
movl 0x20(%rcx), %r14d
movq -0x100(%rbp), %rcx
movl 0x24(%rcx), %ebx
movq -0x100(%rbp), %rcx
movl 0x28(%rcx), %r11d
movq -0x100(%rbp), %rcx
movl 0x2c(%rcx), %r10d
movq -0x100(%rbp), %rcx
movl 0x30(%rcx), %ecx
movl %ecx, -0x1f4(%rbp)
movl $0xc8, %esi
movl $0x1, %ecx
movl %eax, (%rsp)
movl -0x208(%rbp), %eax
movl %eax, 0x8(%rsp)
movl -0x204(%rbp), %eax
movl %eax, 0x10(%rsp)
movq -0x200(%rbp), %rax
movq %rax, 0x18(%rsp)
movl -0x1f8(%rbp), %eax
movl %eax, 0x20(%rsp)
movl -0x1f4(%rbp), %eax
movl %r13d, 0x28(%rsp)
movl %r12d, 0x30(%rsp)
movl %r15d, 0x38(%rsp)
movl %r14d, 0x40(%rsp)
movl %ebx, 0x48(%rsp)
movl %r11d, 0x50(%rsp)
movl %r10d, 0x58(%rsp)
movl %eax, 0x60(%rsp)
movb $0x0, %al
callq 0x2320
movl %eax, -0x1d4(%rbp)
jmp 0x96c5
leaq -0x190(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x108(%rbp)
leaq -0xf0(%rbp), %rdi
movslq -0x1d8(%rbp), %rcx
leaq 0x6501(%rip), %rax      # 0xfb60
movq 0x20(%rax,%rcx,8), %rdx
movl -0x10c(%rbp), %r8d
movq -0x188(%rbp), %r9
movl -0x180(%rbp), %r10d
movq -0x108(%rbp), %rax
movl (%rax), %eax
movl $0xc8, %esi
movl $0x1, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x2320
movl %eax, -0x1d4(%rbp)
jmp 0x96c5
movl $0x0, -0x1d4(%rbp)
leaq -0xf0(%rbp), %rdi
leaq 0x1f1e(%rip), %rsi      # 0xb5d9
movl $0xc8, %edx
callq 0x76d0
cmpl $0x0, -0x1d4(%rbp)
jle 0x9727
movl -0x194(%rbp), %eax
movl %eax, -0x214(%rbp)
leaq -0xf0(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x20e0
movl -0x214(%rbp), %edi
movq -0x210(%rbp), %rsi
movl %eax, %edx
movl $0x5, %ecx
callq 0x2bf0
leaq -0xf0(%rbp), %rdx
movl $0x3, %edi
leaq 0x1950(%rip), %rsi      # 0xb070
movb $0x0, %al
callq 0x2480
jmp 0x9323
movl -0x194(%rbp), %edi
callq 0x2370
xorl %eax, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)