// File: /workspace/github_cpp_makefile_star2_O1/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 0x84a4(%rip), %rbx      # 0x16a50
leaq 0x825d(%rip), %r15      # 0x16810
leaq -0x40(%rbp), %r12
leaq -0x29(%rbp), %r13
callq 0x499c
callq 0xe3db
xorps %xmm0, %xmm0
movups %xmm0, 0x84f1(%rip)     # 0x16ac0
movups %xmm0, 0x84da(%rip)     # 0x16ab0
movups %xmm0, 0x84c3(%rip)     # 0x16aa0
movups %xmm0, 0x84ac(%rip)     # 0x16a90
movups %xmm0, 0x8495(%rip)     # 0x16a80
movups %xmm0, 0x847e(%rip)     # 0x16a70
movups %xmm0, 0x8467(%rip)     # 0x16a60
movups %xmm0, 0x8450(%rip)     # 0x16a50
movups %xmm0, 0x84c9(%rip)     # 0x16ad0
movups %xmm0, 0x84d2(%rip)     # 0x16ae0
movups %xmm0, 0x84db(%rip)     # 0x16af0
movups %xmm0, 0x84e4(%rip)     # 0x16b00
movups %xmm0, 0x84ed(%rip)     # 0x16b10
movups %xmm0, 0x84f6(%rip)     # 0x16b20
movups %xmm0, 0x84ff(%rip)     # 0x16b30
movups %xmm0, 0x8508(%rip)     # 0x16b40
movups %xmm0, 0x8511(%rip)     # 0x16b50
movups %xmm0, 0x851a(%rip)     # 0x16b60
movups %xmm0, 0x8523(%rip)     # 0x16b70
movups %xmm0, 0x852c(%rip)     # 0x16b80
movups %xmm0, 0x8535(%rip)     # 0x16b90
leaq 0x7c9e(%rip), %rax      # 0x16300
movl (%rax), %eax
leal 0x3f(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
movups %xmm0, 0x852d(%rip)     # 0x16ba0
movl %edx, %esi
andl $-0x40, %esi
movl %eax, -0x40(%rbp)
movl %eax, %ecx
subl %esi, %ecx
movl $0x1, %eax
shlq %cl, %rax
sarl $0x6, %edx
movslq %edx, %rcx
orq %rax, (%rbx,%rcx,8)
movups %xmm0, 0x8518(%rip)     # 0x16bb0
movups %xmm0, 0x8521(%rip)     # 0x16bc0
movq (%r15), %r14
cmpq %r15, %r14
je 0xe6b8
movq 0x10(%r14), %rsi
movq %r12, %rdi
callq 0xee3c
movq (%r14), %r14
jmp 0xe6a2
movl -0x40(%rbp), %edi
movq $0x0, -0x40(%rbp)
movq $0x7a120, -0x38(%rbp)   # imm = 0x7A120
incl %edi
movq %rbx, %rsi
leaq 0x83f9(%rip), %rdx      # 0x16ad0
leaq 0x8472(%rip), %rcx      # 0x16b50
movq %r12, %r8
callq 0x32c0
testl %eax, %eax
jle 0xe729
leaq 0x7c0f(%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 0xe710
callq 0xe031
movq (%r15), %r14
cmpq %r15, %r14
je 0xe729
movq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0xeec2
movq (%r14), %r14
jmp 0xe713
leaq 0x80d0(%rip), %rax      # 0x16800
cmpb $0x1, (%rax)
jne 0xe5bb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq