Public Types | Public Member Functions | Private Types | Private Attributes

ACE::FTP::Session_T< ACE_SYNCH_DECL > Class Template Reference

#include <FTP_Session.h>

Collaboration diagram for ACE::FTP::Session_T< ACE_SYNCH_DECL >:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { FTP_PORT = 21 }
typedef
ACE::IOS::StreamHandler
< ACE_SOCK_STREAM,
ACE_SYNCH_USE > 
connection_type

Public Member Functions

 Session_T ()
 Session_T (const ACE_Time_Value &timeout)
virtual ~Session_T ()
bool is_connected () const
bool is_new_connection () const
void set_host (const ACE_CString &host, u_short port)
void set_host (const ACE_CString &host)
void set_port (u_short port)
const ACE_CStringget_host () const
u_short get_port () const
bool connect (bool use_reactor=false)
bool connect (connection_type *connection)
bool send_request (Request &request)
bool receive_response (Response &response)
bool send_interrupt ()
void close ()
bool supports_ftp_extensions () const
void set_ftp_extension_support (bool f)
bool is_reactive () const
const ACE_Time_Valuetimeout () const
void get_local_addr (ACE_INET_Addr &loc_addr) const

Private Types

enum  { DEFAULT_TIMEOUT = 30, INTERRUPT = 244 }
typedef
ACE::IOS::Sock_IOStreamBase
< ACE_SYNCH_USE > 
sock_stream_type

Private Attributes

ACE_CString host_
u_short port_
bool reactive_
connection_typeconnection_
sock_stream_typesock_stream_
ACE_Time_Value ftp_timeout_
bool cannot_reconnect_
bool has_ftp_ext_
bool new_connect_

Detailed Description

template<ACE_SYNCH_DECL>
class ACE::FTP::Session_T< ACE_SYNCH_DECL >

Definition at line 25 of file FTP_Session.h.


Member Typedef Documentation

template<ACE_SYNCH_DECL >
typedef ACE::IOS::StreamHandler<ACE_SOCK_STREAM, ACE_SYNCH_USE> ACE::FTP::Session_T< ACE_SYNCH_DECL >::connection_type

Definition at line 28 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
typedef ACE::IOS::Sock_IOStreamBase<ACE_SYNCH_USE> ACE::FTP::Session_T< ACE_SYNCH_DECL >::sock_stream_type [private]

Definition at line 88 of file FTP_Session.h.


Member Enumeration Documentation

template<ACE_SYNCH_DECL >
anonymous enum
Enumerator:
FTP_PORT 

Definition at line 30 of file FTP_Session.h.

          {

template<ACE_SYNCH_DECL >
anonymous enum [private]
Enumerator:
DEFAULT_TIMEOUT 
INTERRUPT 

Definition at line 78 of file FTP_Session.h.

                   :
              enum


Constructor & Destructor Documentation

template<ACE_SYNCH_DECL >
ACE::FTP::Session_T< ACE_SYNCH_DECL >::Session_T (  ) 

Definition at line 26 of file FTP_Session.cpp.

      : port_ (FTP_PORT),
        reactive_ (false),
        connection_ (0),
        sock_stream_ (0),
        ftp_timeout_ (DEFAULT_TIMEOUT),
        cannot_reconnect_ (false),
        has_ftp_ext_ (true),
        new_connect_ (true)
      {
        INET_TRACE ("ACE_FTP_Session - ctor");
      }

template<ACE_SYNCH_DECL >
ACE::FTP::Session_T< ACE_SYNCH_DECL >::Session_T ( const ACE_Time_Value timeout  ) 

Definition at line 40 of file FTP_Session.cpp.

      : port_ (FTP_PORT),
        reactive_ (false),
        connection_ (0),
        sock_stream_ (0),
        ftp_timeout_ (timeout),
        cannot_reconnect_ (false),
        has_ftp_ext_ (true),
        new_connect_ (true)
      {
        INET_TRACE ("ACE_FTP_Session - ctor");
      }

template<ACE_SYNCH_DECL >
ACE::FTP::Session_T< ACE_SYNCH_DECL >::~Session_T (  )  [virtual]

Definition at line 54 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session - dtor");
        this->close ();
      }


Member Function Documentation

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::close ( void   ) 

Definition at line 268 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::close");

        if (this->connection_)
          {
            if (this->sock_stream_)
              {
                delete this->sock_stream_;
                this->sock_stream_ = 0;
              }
            // this should be the last referece and removing it
            // causes the connection to be destroyed
            this->connection_->remove_reference ();
            this->connection_ = 0;
          }
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::connect ( connection_type connection  ) 

Definition at line 167 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::connect(connection)");

        this->close ();

        if (connection->is_connected ())
          {
            ACE_INET_Addr remote;
            connection->peer ().get_remote_addr (remote);
            this->host_ = remote.get_host_name ();
            this->port_ = remote.get_port_number ();
          }
        else
          {
            typedef ACE_Connector<connection_type, ACE_SOCK_CONNECTOR> connector_type;

            connector_type connector;
            if (connector.connect (connection,
                                   ACE_INET_Addr (this->host_.c_str (),
                                                  this->port_)) == -1)
              {
                INET_ERROR (1, (LM_ERROR, DLINFO
                                ACE_TEXT ("(%d) ACE_FTP_Session::connect(connection) - ")
                                ACE_TEXT ("failed to connect; host=%C, port=%d"),
                                ACE_OS::last_error (), this->host_.c_str (), this->port_));
                return false;
              }
          }

        this->connection_ = connection;
        this->connection_->add_reference ();

        ACE_NEW_NORETURN (this->sock_stream_,
                          sock_stream_type (this->connection_));

        if (this->sock_stream_)
          {
            this->new_connect_ = true;
            this->cannot_reconnect_ = true;
            return true;
          }
        else
          {
            this->close ();
            return false;
          }
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::connect ( bool  use_reactor = false  ) 

Definition at line 113 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::connect");

        typedef ACE_Connector<connection_type, ACE_SOCK_CONNECTOR> connector_type;

        this->close ();

        unsigned long f_reactor = use_reactor ? ACE_Synch_Options::USE_REACTOR : 0;
        ACE_Synch_Options sync_opt (ACE_Synch_Options::USE_TIMEOUT | f_reactor,
                                    this->ftp_timeout_);
        connector_type connector;

        connection_type* new_connection = 0;
        ACE_NEW_RETURN (new_connection,
                        connection_type(sync_opt),
                        false);
        if (connector.connect (new_connection,
                               ACE_INET_Addr (this->port_,
                                              this->host_.c_str ()),
                               ACE_Synch_Options (0,this->ftp_timeout_)) == -1)
          {
            INET_ERROR (1, (LM_ERROR, DLINFO
                            ACE_TEXT ("(%d) ACE_FTP_Session::connect - ")
                            ACE_TEXT ("failed to connect; host=%C, port=%d"),
                            ACE_OS::last_error (), this->host_.c_str (), this->port_));
            // as the connection was dynamically allocated
            // the connector causes it to be destroyed after
            // the connection failure
            return false;
          }

        this->connection_ = new_connection;
        this->connection_->reference_counting_policy ().value (
            ACE_Event_Handler::Reference_Counting_Policy::ENABLED);

        ACE_NEW_NORETURN (this->sock_stream_,
                          sock_stream_type (this->connection_));
        if (this->sock_stream_)
          {
            this->new_connect_ = true;
            this->cannot_reconnect_ = false;
            this->reactive_ = use_reactor;

            return true;
          }
        else
          {
            this->close ();
            return false;
          }
      }

template<ACE_SYNCH_DECL >
const ACE_CString & ACE::FTP::Session_T< ACE_SYNCH_DECL >::get_host (  )  const

Definition at line 101 of file FTP_Session.cpp.

      {
        return this->host_;
      }

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::get_local_addr ( ACE_INET_Addr loc_addr  )  const

Definition at line 311 of file FTP_Session.cpp.

      {
        if (this->is_connected ())
          this->connection_->peer ().get_local_addr (loc_addr);
      }

template<ACE_SYNCH_DECL >
u_short ACE::FTP::Session_T< ACE_SYNCH_DECL >::get_port (  )  const

Definition at line 107 of file FTP_Session.cpp.

      {
        return this->port_;
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::is_connected (  )  const

Definition at line 61 of file FTP_Session.cpp.

      {
        return this->connection_ && this->connection_->is_connected ();
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::is_new_connection (  )  const

Definition at line 67 of file FTP_Session.cpp.

      {
        return this->new_connect_;
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::is_reactive (  )  const

Definition at line 299 of file FTP_Session.cpp.

      {
        return this->reactive_;
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::receive_response ( Response response  ) 

Definition at line 242 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::receive_response");

        this->sock_stream_->flush ();

        response.reset ();
        return response.read (*this->sock_stream_);
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::send_interrupt (  ) 

Definition at line 253 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::send_interrupt");

        if (this->is_connected ())
          {
            this->sock_stream_->put (ACE_Utils::truncate_cast<char> (int (INTERRUPT)));
            this->sock_stream_->sync ();
            return this->sock_stream_->good ();
          }

        return false;
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::send_request ( Request request  ) 

Definition at line 217 of file FTP_Session.cpp.

      {
        INET_TRACE ("ACE_FTP_Session::send_request");

        if (!this->is_connected ())
          {
            if (this->cannot_reconnect_ || !this->connect(this->reactive_))
              {
                if (!this->cannot_reconnect_)
                  INET_ERROR (1, (LM_ERROR, DLINFO
                                  ACE_TEXT ("(%d) FTP_Session::send_request - ")
                                  ACE_TEXT ("reconnect failed\n"),
                                  ACE_OS::last_error ()));
                return ACE::IOS::Null::out_stream_;
              }
          }

        this->new_connect_ = false;

        request.write (*this->sock_stream_);

        return this->is_connected () && this->sock_stream_->good ();
      }

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::set_ftp_extension_support ( bool  f  ) 

Definition at line 293 of file FTP_Session.cpp.

      {
        this->has_ftp_ext_ = f;
      }

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::set_host ( const ACE_CString host,
u_short  port 
)

Definition at line 73 of file FTP_Session.cpp.

      {
        if (!this->is_connected ())
          {
            this->host_ = host;
            this->port_ = port;
          }
      }

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::set_host ( const ACE_CString host  ) 

Definition at line 83 of file FTP_Session.cpp.

      {
        if (!this->is_connected ())
          {
            this->host_ = host;
          }
      }

template<ACE_SYNCH_DECL >
void ACE::FTP::Session_T< ACE_SYNCH_DECL >::set_port ( u_short  port  ) 

Definition at line 92 of file FTP_Session.cpp.

      {
        if (!this->is_connected ())
          {
            this->port_ = port;
          }
      }

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::supports_ftp_extensions (  )  const

Definition at line 287 of file FTP_Session.cpp.

      {
        return this->has_ftp_ext_;
      }

template<ACE_SYNCH_DECL >
const ACE_Time_Value & ACE::FTP::Session_T< ACE_SYNCH_DECL >::timeout ( void   )  const

Definition at line 305 of file FTP_Session.cpp.

      {
        return this->ftp_timeout_;
      }


Member Data Documentation

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::cannot_reconnect_ [private]

Definition at line 94 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
connection_type* ACE::FTP::Session_T< ACE_SYNCH_DECL >::connection_ [private]

Definition at line 91 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
ACE_Time_Value ACE::FTP::Session_T< ACE_SYNCH_DECL >::ftp_timeout_ [private]

Definition at line 93 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::has_ftp_ext_ [private]

Definition at line 95 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
ACE_CString ACE::FTP::Session_T< ACE_SYNCH_DECL >::host_ [private]

Definition at line 85 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::new_connect_ [private]

Definition at line 96 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
u_short ACE::FTP::Session_T< ACE_SYNCH_DECL >::port_ [private]

Definition at line 86 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
bool ACE::FTP::Session_T< ACE_SYNCH_DECL >::reactive_ [private]

Definition at line 90 of file FTP_Session.h.

template<ACE_SYNCH_DECL >
sock_stream_type* ACE::FTP::Session_T< ACE_SYNCH_DECL >::sock_stream_ [private]

Definition at line 92 of file FTP_Session.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines