// -*- C++ -*- //============================================================================= /** * @file SSL_SOCK_Stream.h * * $Id$ * * @author John Heitmann * @author Carlos O'Ryan * @author Ossama Othman */ //============================================================================= #ifndef ACE_SSL_SOCK_STREAM_H #define ACE_SSL_SOCK_STREAM_H #include "ace/pre.h" #include "SSL_Export.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #include #include "SSL_SOCK.h" #include "SSL_Context.h" #include "ace/Synch_T.h" #include "ace/SOCK_Stream.h" /** * @class ACE_SSL_SOCK_Stream * * @brief Defines methods in the ACE_SSL_SOCK_Stream abstraction. * * This adds SSL functionality to an ACE_SOCK_IO interface by * wrapping around an ACE_SSL_SOCK_Stream implementation. * * @note The user must currently ensure that assignment or copy * operations are atomic! */ class ACE_SSL_Export ACE_SSL_SOCK_Stream : public ACE_SSL_SOCK { friend class ACE_SSL_SOCK_Connector; friend class ACE_SSL_SOCK_Acceptor; public: /// Constructor ACE_SSL_SOCK_Stream (ACE_SSL_Context *context = ACE_SSL_Context::instance ()); /// Destructor ~ACE_SSL_SOCK_Stream (void); /** * Send an byte buffer to the ssl socket using * the semantics of . ACE+SSL supports no * flags for sending at this time. */ ssize_t send (const void *buf, size_t n, int flags) const; /** * Recv an byte buffer from the ssl socket using * the semantics of . ACE+SSL supports MSG_PEEK, * but no other flags at this time. */ ssize_t recv (void *buf, size_t n, int flags) const; /// Send an byte buffer to the ssl socket using /// the semantics of . ssize_t send (const void *buf, size_t n) const; /// Recv an byte buffer from the ssl socket using /// the semantics of . ssize_t recv (void *buf, size_t n) const; /// Send an of size to the ssl socket. ssize_t sendv (const iovec iov[], size_t n) const; /** * Allows a client to read from a socket without having to provide a * buffer to read. This method determines how much data is in the * socket, allocates a buffer of this size, reads in the data, and * returns the number of bytes read. The caller is responsible for * deleting the member in the field of using * delete [] io_vec->iov_base. */ ssize_t recvv (iovec *io_vec, const ACE_Time_Value *timeout = 0) const; /** * Wait to to amount of time to send up to bytes into * (uses the call). If times out * a -1 is returned with . If it succeeds the * number of bytes sent is returned. No flags are supported. */ ssize_t send (const void *buf, size_t n, int flags, const ACE_Time_Value *timeout) const; /** * Wait up to amount of time to receive up to bytes * into (uses the call). If times * out a -1 is returned with . If it succeeds the * number of bytes received is returned. MSG_PEEK is the only * supported flag. */ ssize_t recv (void *buf, size_t n, int flags, const ACE_Time_Value *timeout) const; /** * Wait to to amount of time to send up to bytes into * (uses the call). If times out * a -1 is returned with . If it succeeds the * number of bytes sent is returned. */ ssize_t send (const void *buf, size_t n, const ACE_Time_Value *timeout) const; /** * Wait up to amount of time to receive up to bytes * into (uses the call). If times * out a -1 is returned with . If it succeeds the * number of bytes received is returned. */ ssize_t recv (void *buf, size_t n, const ACE_Time_Value *timeout) const; /// Send varargs messages to the connected ssl socket. ssize_t send (size_t n, ...) const; /// Recv varargs messages to the connected ssl socket. ssize_t recv (size_t n, ...) const; /// Send bytes, keep trying until are sent. ssize_t send_n (const void *buf, int n) const; /// Recv bytes, keep trying until are received. ssize_t recv_n (void *buf, int n) const; /** * @note In the following four methods, only MSG_PEEK is supported * for recv_n, and no flags are supported for send_n. */ //@{ /// Send bytes, keep trying until are sent. ssize_t send_n (const void *buf, int n, int flags) const; /// Recv bytes, keep trying until are sent. ssize_t recv_n (void *buf, int n, int flags) const; /** * Try to send exactly bytes into (uses * the call). If blocks for longer than the * number of bytes actually sent is returned with . * If a timeout does not occur, return (i.e., the * number of bytes requested to be sent). */ ssize_t send_n (const void *buf, size_t len, int flags, const ACE_Time_Value *timeout) const; /** * Try to recv exactly bytes into (uses * the call). The indicates how long * to blocking trying to receive. If == 0, the caller * will block until action is possible, else will wait until the * relative time specified in * elapses). If blocks * for longer than the number of bytes actually read is * returned with . If a timeout does not occur, * return (i.e., the number of bytes requested to be * read). */ ssize_t recv_n (void *buf, size_t len, int flags, const ACE_Time_Value *timeout) const; //@} /** * Send an of size to the connected socket. * Will block until all bytes are sent or an error * occurs. */ ssize_t sendv_n (const iovec iov[], size_t n) const; /// Receive an of size to the connected socket. ssize_t recvv_n (iovec iov[], size_t n) const; /** * Selectively close endpoints. */ //@{ /// Close down the reader. int close_reader (void); /// Close down the writer. int close_writer (void); //@} ///Close down the socket. int close (void); /// Meta-type info typedef ACE_INET_Addr PEER_ADDR; /// Declare the dynamic allocation hooks. ACE_ALLOC_HOOK_DECLARE; /** * Overridden set_handle() method. * * Only an ACE_SSL_SOCK_Acceptor or ACE_SSL_SOCK_Connector should * access this method since some state in the underlying "ssl_" data * structure is set during SSL connection establishment. */ void set_handle (ACE_HANDLE fd); /// Return a pointer to the underlying SSL structure. SSL *ssl (void) const; protected: /// Return the underlying which SSL runs atop of. ACE_SOCK_Stream & peer (void); private: ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_SSL_SOCK_Stream &)) ACE_UNIMPLEMENTED_FUNC (ACE_SSL_SOCK_Stream (const ACE_SSL_SOCK_Stream &)) protected: /// The SSL session. SSL *ssl_; /// The stream which works under the ssl connection. ACE_SOCK_Stream stream_; }; #if !defined (ACE_LACKS_INLINE_FUNCTIONS) #include "SSL_SOCK_Stream.i" #endif /* ACE_LACKS_INLINE_FUNCTIONS */ #include "ace/post.h" #endif /* ACE_SSL_SOCK_STREAM_H */