Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

SOCK_Stream.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    SOCK_Stream.h
00006  *
00007  *  $Id: SOCK_Stream.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_SOCK_STREAM_H
00014 #define ACE_SOCK_STREAM_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/SOCK_IO.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/INET_Addr.h"
00024 
00025 // Forward declarations.
00026 class ACE_Message_Block;
00027 
00028 /**
00029  * @class ACE_SOCK_Stream
00030  *
00031  * @brief Defines the methods in the <ACE_SOCK_Stream> abstraction.
00032  *
00033  * This adds additional wrapper methods atop the <ACE_SOCK_IO>
00034  * class.
00035  *
00036  * <buf> is the buffer to write from or receive into.
00037  * <len> is the number of bytes to transfer.
00038  * The <timeout> parameter in the following methods indicates how
00039  * long to blocking trying to transfer data.  If <timeout> == 0,
00040  * then the call behaves as a normal send/recv call, i.e., for
00041  * blocking sockets, the call will block until action is possible;
00042  * for non-blocking sockets, EWOULDBLOCK will be returned if no
00043  * action is immediately possible.
00044  * If <timeout> != 0, the call will wait for data to arrive no longer
00045  * than the relative time specified in *<timeout>.
00046  * The "_n()" I/O methods keep looping until all the data has been
00047  * transferred.  These methods also work for sockets in non-blocking
00048  * mode i.e., they keep looping on EWOULDBLOCK.  <timeout> is used
00049  * to make sure we keep making progress, i.e., the same timeout
00050  * value is used for every I/O operation in the loop and the timeout
00051  * is not counted down.
00052  * The return values for the "*_n()" methods match the return values
00053  * from the non "_n()" methods and are specified as follows:
00054  * - On complete transfer, the number of bytes transferred is returned.
00055  * - On timeout, -1 is returned, errno == ETIME.
00056  * - On error, -1 is returned, errno is set to appropriate error.
00057  * - On EOF, 0 is returned, errno is irrelevant.
00058  *
00059  * On partial transfers, i.e., if any data is transferred before
00060  * timeout/error/EOF, <bytes_transferred> will contain the number of
00061  * bytes transferred.
00062  * Methods with <iovec> parameter are I/O vector variants of the I/O
00063  * operations.
00064  * Methods with the extra <flags> argument will always result in
00065  * <send> getting called. Methods without the extra <flags> argument
00066  * will result in <send> getting called on Win32 platforms, and
00067  * <write> getting called on non-Win32 platforms.
00068  */
00069 class ACE_Export ACE_SOCK_Stream : public ACE_SOCK_IO
00070 {
00071 public:
00072   // Initialization and termination methods.
00073   /// Constructor.
00074   ACE_SOCK_Stream (void);
00075 
00076   /// Constructor (sets the underlying <ACE_HANDLE> with <h>).
00077   ACE_SOCK_Stream (ACE_HANDLE h);
00078 
00079   /// Destructor.
00080   ~ACE_SOCK_Stream (void);
00081 
00082   // = I/O functions.
00083 
00084   /// Try to recv exactly <len> bytes into <buf> from the connected socket.
00085   ssize_t recv_n (void *buf,
00086                   size_t len,
00087                   int flags,
00088                   const ACE_Time_Value *timeout = 0,
00089                   size_t *bytes_transferred = 0) const;
00090 
00091   /// Try to recv exactly <len> bytes into <buf> from the connected socket.
00092   ssize_t recv_n (void *buf,
00093                   size_t len,
00094                   const ACE_Time_Value *timeout = 0,
00095                   size_t *bytes_transferred = 0) const;
00096 
00097   /// Receive an <iovec> of size <iovcnt> from the connected socket.
00098   ssize_t recvv_n (iovec iov[],
00099                    int iovcnt,
00100                    const ACE_Time_Value *timeout = 0,
00101                    size_t *bytes_transferred = 0) const;
00102 
00103   /// Try to send exactly <len> bytes from <buf> to the connection socket.
00104   ssize_t send_n (const void *buf,
00105                   size_t len,
00106                   int flags,
00107                   const ACE_Time_Value *timeout = 0,
00108                   size_t *bytes_transferred = 0) const;
00109 
00110   /// Try to send exactly <len> bytes from <buf> to the connected socket.
00111   ssize_t send_n (const void *buf,
00112                   size_t len,
00113                   const ACE_Time_Value *timeout = 0,
00114                   size_t *bytes_transferred = 0) const;
00115 
00116   /// Send all the <message_block>s chained through their <next> and
00117   /// <cont> pointers.  This call uses the underlying OS gather-write
00118   /// operation to reduce the domain-crossing penalty.
00119   ssize_t send_n (const ACE_Message_Block *message_block,
00120                   const ACE_Time_Value *timeout = 0,
00121                   size_t *bytes_transferred = 0) const;
00122 
00123   /// Send an <iovec> of size <iovcnt> to the connected socket.
00124   ssize_t sendv_n (const iovec iov[],
00125                    int iovcnt,
00126                    const ACE_Time_Value *timeout = 0,
00127                    size_t *bytes_transferred = 0) const;
00128 
00129   // = Send/receive ``urgent'' data (see TCP specs...).
00130   ssize_t send_urg (const void *ptr,
00131                     size_t len = sizeof (char),
00132                     const ACE_Time_Value *timeout = 0) const;
00133 
00134   ssize_t recv_urg (void *ptr,
00135                     size_t len = sizeof (char),
00136                     const ACE_Time_Value *timeout = 0) const;
00137 
00138   // = Selectively close endpoints.
00139   /// Close down the reader.
00140   int close_reader (void);
00141 
00142   /// Close down the writer.
00143   int close_writer (void);
00144 
00145   /**
00146    * Close down the socket (we need this to make things work correctly
00147    * on Win32, which requires use to do a <close_writer> before doing
00148    * the close to avoid losing data).
00149    */
00150   int close (void);
00151 
00152   // = Meta-type info
00153   typedef ACE_INET_Addr PEER_ADDR;
00154 
00155   /// Dump the state of an object.
00156   void dump (void) const;
00157 
00158   /// Declare the dynamic allocation hooks.
00159   ACE_ALLOC_HOOK_DECLARE;
00160 };
00161 
00162 #if !defined (ACE_LACKS_INLINE_FUNCTIONS)
00163 #include "ace/SOCK_Stream.i"
00164 #endif
00165 
00166 #include "ace/post.h"
00167 #endif /* ACE_SOCK_STREAM_H */

Generated on Mon Jun 16 11:21:21 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002