Changeset 971


Ignore:
Timestamp:
11/10/2006 22:58:41 (5 years ago)
Author:
chris
Message:
  • More accurate timing (avoids spin loops of zero wait during the last second of polling)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/general/lib/server/SocketStreamTLS.cpp

    r582 r971  
    2424#include "ServerException.h" 
    2525#include "TLSContext.h" 
     26#include "BoxTime.h" 
    2627 
    2728#include "MemLeakFindOn.h" 
     
    245246        } 
    246247        p.revents = 0; 
    247         switch(::poll(&p, 1, (Timeout == IOStream::TimeOutInfinite)?INFTIM:Timeout)) 
     248 
     249        int64_t start, end; 
     250        start = BoxTimeToMilliSeconds(GetCurrentBoxTime()); 
     251        end   = start + Timeout; 
     252        int result; 
     253 
     254        do 
     255        { 
     256                int64_t now = BoxTimeToMilliSeconds(GetCurrentBoxTime()); 
     257                int poll_timeout = (int)(end - now); 
     258                if (poll_timeout < 0) poll_timeout = 0; 
     259                if (Timeout == IOStream::TimeOutInfinite) 
     260                { 
     261                        poll_timeout = INFTIM; 
     262                } 
     263                result = ::poll(&p, 1, poll_timeout); 
     264        } 
     265        while(result == -1 && errno == EINTR); 
     266 
     267        switch(result) 
    248268        { 
    249269        case -1: 
    250                 // error 
    251                 if(errno == EINTR) 
    252                 { 
    253                         // Signal. Do "time out" 
    254                         return false; 
    255                 } 
    256                 else 
    257                 { 
    258                         // Bad! 
    259                         THROW_EXCEPTION(ServerException, SocketPollError) 
    260                 } 
     270                // error - Bad! 
     271                THROW_EXCEPTION(ServerException, SocketPollError) 
    261272                break; 
    262273 
Note: See TracChangeset for help on using the changeset viewer.