// File: /workspace/github_cpp_makefile_star2_O3/nickgammon[P]tinymudserver/comms.cpp
// Function: MainLoop()
void MainLoop ()
{
  // loop processing input, output, events
  do
    {

    // We will go through this loop roughly every COMMS_WAIT_SEC/COMMS_WAIT_USEC
    // seconds (at present 0.5 seconds).
    PeriodicUpdates ();   // do things that don't rely on player input
      
    // delete players who have closed their comms - have to do it outside other loops to avoid 
    // access violations (iterating loops that have had items removed)
    RemoveInactivePlayers ();
      
    // get ready for "select" function ... 
    FD_ZERO (&in_set);
    FD_ZERO (&out_set);
    FD_ZERO (&exc_set);

    // add our control socket (for new connections)
    FD_SET (iControl, &in_set);

    // set bits in in_set, out_set etc. for each connected player
    int iMaxdesc = for_each (playerlist.begin (), playerlist.end (), 
                             setUpDescriptors (iControl)).GetMax ();
    
    // set up timeout interval
    struct timeval timeout;
    timeout.tv_sec = COMMS_WAIT_SEC;    // seconds
    timeout.tv_usec = COMMS_WAIT_USEC;  // + 1000th. of second

    // check for activity, timeout after 'timeout' seconds
    if (select (iMaxdesc + 1, &in_set, &out_set, &exc_set, &timeout) > 0)
      {
      // New connection on control port?
      if (FD_ISSET (iControl, &in_set))
        ProcessNewConnection ();
      
      // handle all player input/output
      for_each (playerlist.begin (), playerlist.end (), 
                processDescriptors ());      
      } // end of something happened
  
    }  while (!bStopNow);   // end of looping processing input

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x8541(%rip), %rbx      # 0x16a50
leaq 0x82fa(%rip), %r15      # 0x16810
leaq -0x40(%rbp), %r12
leaq -0x29(%rbp), %r13
callq 0x499c
callq 0xe357
xorps %xmm0, %xmm0
movups %xmm0, 0x858e(%rip)     # 0x16ac0
movups %xmm0, 0x8577(%rip)     # 0x16ab0
movups %xmm0, 0x8560(%rip)     # 0x16aa0
movups %xmm0, 0x8549(%rip)     # 0x16a90
movups %xmm0, 0x8532(%rip)     # 0x16a80
movups %xmm0, 0x851b(%rip)     # 0x16a70
movups %xmm0, 0x8504(%rip)     # 0x16a60
movups %xmm0, 0x84ed(%rip)     # 0x16a50
movups %xmm0, 0x8566(%rip)     # 0x16ad0
movups %xmm0, 0x856f(%rip)     # 0x16ae0
movups %xmm0, 0x8578(%rip)     # 0x16af0
movups %xmm0, 0x8581(%rip)     # 0x16b00
movups %xmm0, 0x858a(%rip)     # 0x16b10
movups %xmm0, 0x8593(%rip)     # 0x16b20
movups %xmm0, 0x859c(%rip)     # 0x16b30
movups %xmm0, 0x85a5(%rip)     # 0x16b40
movups %xmm0, 0x85ae(%rip)     # 0x16b50
movups %xmm0, 0x85b7(%rip)     # 0x16b60
movups %xmm0, 0x85c0(%rip)     # 0x16b70
movups %xmm0, 0x85c9(%rip)     # 0x16b80
movups %xmm0, 0x85d2(%rip)     # 0x16b90
movups %xmm0, 0x85db(%rip)     # 0x16ba0
movups %xmm0, 0x85e4(%rip)     # 0x16bb0
leaq 0x7d2d(%rip), %rax      # 0x16300
movl (%rax), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, (%rbx,%rax,8)
movups %xmm0, 0x85c2(%rip)     # 0x16bc0
movq (%r15), %r14
movl %edi, -0x40(%rbp)
cmpq %r15, %r14
je 0xe620
movq 0x10(%r14), %rsi
movq %r12, %rdi
callq 0xeda2
movq (%r14), %r14
cmpq %r15, %r14
jne 0xe609
movl -0x40(%rbp), %edi
movq $0x0, -0x40(%rbp)
movq $0x7a120, -0x38(%rbp)   # imm = 0x7A120
incl %edi
movq %rbx, %rsi
leaq 0x8494(%rip), %rdx      # 0x16ad0
leaq 0x850d(%rip), %rcx      # 0x16b50
movq %r12, %r8
callq 0x32c0
testl %eax, %eax
jle 0xe68e
leaq 0x7caa(%rip), %rax      # 0x16300
movl (%rax), %eax
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq (%rbx,%rcx,8), %rcx
btq %rax, %rcx
jae 0xe675
callq 0xdfad
movq (%r15), %r14
cmpq %r15, %r14
je 0xe68e
movq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0xee28
movq (%r14), %r14
jmp 0xe678
leaq 0x816b(%rip), %rax      # 0x16800
cmpb $0x1, (%rax)
jne 0xe51e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop