00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file DEV_IO.h 00006 * 00007 * DEV_IO.h,v 4.26 2005/10/28 16:14:52 ossama Exp 00008 * 00009 * @author Gerhard Lenzer 00010 * @author Douglas C. Schmidt 00011 */ 00012 //============================================================================= 00013 00014 #ifndef ACE_DEV_IO_H 00015 #define ACE_DEV_IO_H 00016 #include /**/ "ace/pre.h" 00017 00018 #include "ace/DEV.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #if defined (ACE_HAS_STREAM_PIPES) 00025 # include "ace/OS_NS_stropts.h" 00026 #endif /* ACE_HAS_STREAM_PIPES */ 00027 00028 #include "ace/os_include/os_stdio.h" 00029 #include "ace/os_include/sys/os_uio.h" 00030 00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 class ACE_Time_Value; 00034 00035 /** 00036 * @class ACE_DEV_IO 00037 * 00038 * @brief Read/Write operations on Devices. 00039 */ 00040 class ACE_Export ACE_DEV_IO : public ACE_DEV 00041 { 00042 public: 00043 friend class ACE_DEV_Connector; 00044 00045 /// Default constructor. 00046 ACE_DEV_IO (void); 00047 00048 // = Various send operations. 00049 /// send upto <n> bytes in <buf>. 00050 ssize_t send (const void *buf, size_t n) const; 00051 00052 /// Recv upto <n> bytes in <buf>. 00053 ssize_t recv (void *buf, size_t n) const; 00054 00055 /// Send n bytes, keep trying until n are sent. 00056 ssize_t send_n (const void *buf, 00057 size_t n) const; 00058 00059 /** 00060 * @name I/O operations 00061 * 00062 * Notes on common parameters: 00063 * 00064 * <buf> is the buffer to write from or receive into. 00065 * 00066 * <len> is the number of bytes to transfer. 00067 * 00068 * The <timeout> parameter in the following methods indicates how 00069 * long to blocking trying to transfer data. If <timeout> == 0, 00070 * then the call behaves as a normal send/recv call, i.e., for 00071 * blocking sockets, the call will block until action is possible; 00072 * for non-blocking sockets, EWOULDBLOCK will be returned if no 00073 * action is immediately possible. 00074 * 00075 * If <timeout> != 0, the call will wait until the relative time 00076 * specified in *<timeout> elapses. 00077 * 00078 * The "_n()" I/O methods keep looping until all the data has been 00079 * transferred. These methods also work for sockets in non-blocking 00080 * mode i.e., they keep looping on EWOULDBLOCK. <timeout> is used 00081 * to make sure we keep making progress, i.e., the same timeout 00082 * value is used for every I/O operation in the loop and the timeout 00083 * is not counted down. 00084 * 00085 * The return values for the "*_n()" methods match the return values 00086 * from the non "_n()" methods and are specified as follows: 00087 * 00088 * - On complete transfer, the number of bytes transferred is returned. 00089 * - On timeout, -1 is returned, errno == ETIME. 00090 * - On error, -1 is returned, errno is set to appropriate error. 00091 * - On EOF, 0 is returned, errno is irrelevant. 00092 * 00093 * On partial transfers, i.e., if any data is transferred before 00094 * timeout/error/EOF, <bytes_transferred> will contain the number of 00095 * bytes transferred. 00096 */ 00097 ssize_t recv_n (void *buf, 00098 size_t n, 00099 const ACE_Time_Value *timeout = 0, 00100 size_t *bytes_transferred = 0) const; 00101 00102 #if defined (ACE_HAS_STREAM_PIPES) 00103 /// Recv bytes via STREAM pipes using "band" mode. 00104 ssize_t recv (ACE_Str_Buf *cntl, 00105 ACE_Str_Buf *data, 00106 int *band, 00107 int *flags) const; 00108 00109 /// Send bytes via STREAM pipes using "band" mode. 00110 ssize_t send (const ACE_Str_Buf *cntl, 00111 const ACE_Str_Buf *data, 00112 int band, 00113 int flags) const; 00114 00115 /// Recv @a cntl and @a data via STREAM pipes. 00116 ssize_t recv (ACE_Str_Buf *cntl, 00117 ACE_Str_Buf *data, 00118 int *flags) const; 00119 00120 /// Send <cntl> and <data> via STREAM pipes. 00121 ssize_t send (const ACE_Str_Buf *cntl, 00122 const ACE_Str_Buf *data, 00123 int flags = 0) const; 00124 #endif /* ACE_HAS_STREAM_PIPES */ 00125 00126 /// Send iovecs via <::writev>. 00127 ssize_t send (const iovec iov[], size_t n) const; 00128 00129 /// Recv iovecs via <::readv>. 00130 ssize_t recv (iovec iov[], size_t n) const; 00131 00132 /** 00133 * Send N char *ptrs and int lengths. Note that the char *'s 00134 * precede the ints (basically, an varargs version of writev). The 00135 * count N is the *total* number of trailing arguments, *not* a 00136 * couple of the number of tuple pairs! 00137 */ 00138 ssize_t send (size_t n, ...) const; 00139 00140 /** 00141 * This is an interface to ::readv, that doesn't use the struct 00142 * iovec explicitly. The ... can be passed as an arbitrary number 00143 * of (char *ptr, int len) tuples. However, the count N is the 00144 * *total* number of trailing arguments, *not* a couple of the 00145 * number of tuple pairs! 00146 */ 00147 ssize_t recv (size_t n, ...) const; 00148 00149 /// Send <n> bytes via Win32 WriteFile using overlapped I/O. 00150 ssize_t send (const void *buf, size_t n, ACE_OVERLAPPED *overlapped) const; 00151 00152 /// Recv <n> bytes via Win32 ReadFile using overlapped I/O. 00153 ssize_t recv (void *buf, size_t n, ACE_OVERLAPPED *overlapped) const; 00154 00155 /// Dump the state of an object. 00156 void dump (void) const; 00157 00158 // = The following two methods are no-ops to keep the 00159 // <ACE_Connector> happy. 00160 /// Return the local endpoint address. 00161 int get_local_addr (ACE_DEV_Addr &) const; 00162 00163 /// Return the address of the remotely connected peer (if there is 00164 /// one). 00165 int get_remote_addr (ACE_DEV_Addr &) const; 00166 00167 /// Declare the dynamic allocation hooks. 00168 ACE_ALLOC_HOOK_DECLARE; 00169 00170 // = Meta-type info 00171 typedef ACE_DEV_Addr PEER_ADDR; 00172 00173 private: 00174 /// Address of device we are connected to. 00175 ACE_DEV_Addr addr_; 00176 }; 00177 00178 ACE_END_VERSIONED_NAMESPACE_DECL 00179 00180 #if defined (__ACE_INLINE__) 00181 #include "ace/DEV_IO.inl" 00182 #endif /* __ACE_INLINE__ */ 00183 00184 #include /**/ "ace/post.h" 00185 #endif /* ACE_DEV_IO_H */