Changeset 4887 for branches/erijo-dev

Show
Ignore:
Timestamp:
04/12/07 04:20:20 (20 months ago)
Author:
erijo
Message:

Keep a fd_set around instead of always creating it from scratch.

Location:
branches/erijo-dev/licq/src/event
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/erijo-dev/licq/src/event/fdset.cpp

    r4883 r4887  
    2626    return; 
    2727 
     28  bool updateFdSet = false; 
     29 
    2830  if (!RemoveFds.empty()) 
    2931  { 
    30     for (TFds::const_iterator it = RemoveFds.begin(); 
    31          it != RemoveFds.end(); ++it) 
     32    for (TFds::const_iterator it = RemoveFds.begin(); it != RemoveFds.end(); ++it) 
    3233    { 
    3334      for (TFds::iterator fd = Fds.begin(); fd != Fds.end(); ++fd) 
     
    4243    } 
    4344 
     45    updateFdSet = true; 
    4446    RemoveFds.clear(); 
    4547  } 
     
    4749  if (!AddFds.empty()) 
    4850  { 
    49     for (TFds::const_iterator it = AddFds.begin(); 
    50          it != AddFds.end(); ++it) 
     51    for (TFds::const_iterator it = AddFds.begin(); it != AddFds.end(); ++it) 
    5152    { 
    5253      Fds.push_back(*it); 
    5354    } 
    5455 
     56    updateFdSet = true; 
    5557    AddFds.clear(); 
     58  } 
     59 
     60  // Update cached fd_set if needed 
     61  if (updateFdSet) 
     62  { 
     63    MaxFd = 0; 
     64    FD_ZERO(&FdSet); 
     65 
     66    for (TFds::const_iterator it = Fds.begin(); it != Fds.end(); ++it) 
     67    { 
     68      FD_SET((*it)->Fd, &FdSet); 
     69      MaxFd = std::max(MaxFd, (*it)->Fd); 
     70    } 
    5671  } 
    5772} 
    5873 
    5974Licq::TFdSet::TFdSet() 
    60   : InFireActive(false) 
     75  : InFireActive(false), MaxFd(0) 
    6176{ 
    62   // Empty 
     77  FD_ZERO(&FdSet); 
    6378} 
    6479 
     
    6681{ 
    6782  std::for_each(Fds.begin(), Fds.end(), ObjectDeleter()); 
    68 } 
    69  
    70 bool Licq::TFdSet::empty() const 
    71 { 
    72   return Fds.empty(); 
    73 } 
    74  
    75 size_t Licq::TFdSet::size() const 
    76 { 
    77   return Fds.size(); 
    7883} 
    7984 
     
    114119{ 
    115120  assert(set != NULL); 
    116  
    117   int maxFd = 0; 
    118   FD_ZERO(set); 
    119  
    120   for (TFds::const_iterator it = Fds.begin(); it != Fds.end(); ++it) 
    121   { 
    122     FD_SET((*it)->Fd, set); 
    123     maxFd = std::max(maxFd, (*it)->Fd); 
    124   }   
    125  
    126   return maxFd; 
     121  ::memcpy(set, &FdSet, sizeof(fd_set)); 
     122  return MaxFd; 
    127123} 
    128124 
  • branches/erijo-dev/licq/src/event/fdset.h

    r4883 r4887  
    4747  void addRemoveFds(); 
    4848 
     49  fd_set FdSet; 
     50  int MaxFd; 
     51 
    4952public: 
    5053  TFdSet(); 
     
    6366} // namespace Licq 
    6467 
     68inline bool Licq::TFdSet::empty() const 
     69{ 
     70  return Fds.empty(); 
     71} 
     72 
     73inline size_t Licq::TFdSet::size() const 
     74{ 
     75  return Fds.size(); 
     76} 
     77 
    6578#endif