src/worker.cc
// Network listener IO work loop. Execute until marked done.
// Return false on fatal software error.
Network listener IO work loop. Execute until marked done.
Return false on fatal software error.
Network listener IO work loop . Execute until marked done . Return false on fatal software error .
bool NetworkListenThread::Work() {
  logprintf(9, "Log: Starting network listen thread %d\n",
            thread_num_);
  sock_ = 0;
  if (!CreateSocket(&sock_)) {
    status_ = false;
    return false;
  }
  logprintf(9, "Log: Listen thread created sock\n");
  int newsock = 0;
  Listen();
  logprintf(12, "Log: Listen thread waiting for incoming connections\n");
  int threadcount = 0;
  while (IsReadyToRun()) {
    if (Wait()) {
      logprintf(12, "Log: Listen thread found incoming connection\n");
      if (GetConnection(&newsock)) {
        SpawnSlave(newsock, threadcount);
        threadcount++;
      }
    }
  }
  ReapSlaves();
  for (ChildVector::iterator it = child_workers_.begin();
       it != child_workers_.end(); ++it) {
    (*it)->status.Destroy();
    delete *it;
  }
  child_workers_.clear();
  CloseSocket(sock_);
  status_ = true;
  logprintf(9,
            "Log: Completed %d: network listen thread status %d, "
            "%d pages copied\n",
            thread_num_, status_, pages_copied_);
  return true;
}
bool NetworkListenThread :: Work ( ) { logprintf ( 9 , " \n " , thread_num_ ) ; sock_ = 0 ; if ( ! CreateSocket ( & sock_ ) ) { status_ = false ; return false ; } logprintf ( 9 , " \n " ) ; int newsock = 0 ; Listen ( ) ; logprintf ( 12 , " \n " ) ; int threadcount = 0 ; while ( IsReadyToRun ( ) ) { if ( Wait ( ) ) { logprintf ( 12 , " \n " ) ; if ( GetConnection ( & newsock ) ) { SpawnSlave ( newsock , threadcount ) ; threadcount ++ ; } } } ReapSlaves ( ) ; for ( ChildVector :: iterator it = child_workers_ . begin ( ) ; it != child_workers_ . end ( ) ; ++ it ) { ( * it ) -> status . Destroy ( ) ; delete * it ; } child_workers_ . clear ( ) ; CloseSocket ( sock_ ) ; status_ = true ; logprintf ( 9 , " " " \n " , thread_num_ , status_ , pages_copied_ ) ; return true ; }
Network listener IO work loop.
Network listener IO work loop .
// Make a socket. // Allows incoming connections to be queued up by socket library. // Wait on incoming connections, and spawn worker threads for them. // Poll for connections that we can accept(). // Accept those connections. // Gather status and join spawned threads. // Delete the child workers.