Logo Search packages:      
Sourcecode: pan version File versions

void NNTP_Pool::on_nntp_done ( NNTP nntp,
Health  health,
const StringView response 
) [private, virtual]

Called at the end of an NNTP command. If the command was one that produced a list, on_nntp_line() may have been called before this.

When this is called, the listener can safely clean up anything associated with processing the command.

Parameters:
health if OK, the command was successful. if RETRY, the command couldn't be processed now but might be successful later -- perhaps there was a bad connection. if FAIL, there's no point in retrying -- perhaps the article has expired.

Reimplemented from pan::NNTP::Listener.

Definition at line 177 of file nntp-pool.cc.

References pan::NNTP::_socket, pan::StringView::empty(), pan::FAIL, pan::ServerInfo::get_server_address(), pan::StringView::len, pan::OK, and pan::StringView::str.

{
   debug ("NNTP_Pool: on_nntp_done()");

   if (health == FAIL) // news server isn't accepting our connection!
   {
     std::string s (response.str, response.len);
     foreach (std::string, s, it) *it = tolower (*it);

     // too many connections.
     // there doesn't seem to be a reliable way to test for this:
     // response can be 502, 400, or 451... and the error messages
     // vary from server to server

     if (   (s.find ("too many") != s.npos)
         || (s.find ("limit reached") != s.npos)
         || (s.find ("maximum number of connections") != s.npos))
     {
       disallow_new_connections_for_n_seconds (TOO_MANY_CONNECTIONS_LOCKOUT_SECS);
     }
     else
     {
       const std::string addr (_server_info.get_server_address (_server));
       std::string s;
       char buf[4096];
       snprintf (buf, sizeof(buf), _("Unable to connect to \"%s\""), addr.c_str());
       s = buf;
       if (!response.empty()) {
         s += ":\n";
         s.append (response.str, response.len);
       }
       fire_pool_error (s.c_str());
     }
   }

   if (health != OK)
   {
      delete nntp->_socket;
      delete nntp;
      nntp = 0;
   }

   --_pending_connections;

   // if success...
   if (nntp != 0)
   {
      debug ("success with handshake to " << _server << ", nntp " << nntp);

      PoolItem i;
      i.nntp = nntp;
      i.is_checked_in = true;
      i.last_active_time = time (0);
      _pool_items.push_back (i);

      fire_pool_has_nntp_available ();
   }
}


Generated by  Doxygen 1.6.0   Back to index