diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-30 14:39:07 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-30 14:39:07 +0000 |
commit | 9770747c8ab4e7dac82aac61854b48d819460275 (patch) | |
tree | f70ed075e5b42275e2028fc64d0fea414bb24d88 /ace/IOStream.h | |
parent | d150d631a443ca003c604190f4b0550489b816a2 (diff) | |
download | ATCD-9770747c8ab4e7dac82aac61854b48d819460275.tar.gz |
James' updates to IOStream
Diffstat (limited to 'ace/IOStream.h')
-rw-r--r-- | ace/IOStream.h | 529 |
1 files changed, 401 insertions, 128 deletions
diff --git a/ace/IOStream.h b/ace/IOStream.h index 45d08db7830..86865241ef6 100644 --- a/ace/IOStream.h +++ b/ace/IOStream.h @@ -17,30 +17,123 @@ // // ============================================================================ +/* + Changes 4/5/97 + + ACE_Streambuf_T + + New public functions added + + char * reset_get_buffer( char * newbuf, u_int bufsiz, u_int inuse ) + char * reset_put_buffer( char * newbuf, u_int bufsiz, u_int inuse ) + + Resets the get/put buffer and returns a pointer to the + previous buffer. + + If newbuf is not NULL and bufsiz matches the current + streambuf_size_ value, then the current buffer will + be replaced by newbuf. If the stream sizes do not match, + a NULL pointer is returned and the buffer left unchanged. + + If newbuf is NULL, a new buffer will be allocated from + the heap. + + This kind of thing is handy if you're chaining streams. + For instance, I have a stream built on a message queue + which marshals and sends data from one thread to another. + The receiving thread then sends that data to a peer() + via a stream built on a socket. It is more efficient + to simply replace the socket stream's put buffer with that + of the message queue rather than copying the data from + one to another. + + u_int streambuf_size( void ) + + Get the size of the stream buffers. Note that the get + and put buffers are the same size. + + New protected functions added + + void reset_base( void ) + + Resets the base() pointers which toggle between get + and put mode as well as the cur_mode_ value. + + Constructor changed + + Initialization of the get/put buffers was moved here from + the derived class/template ACE_Streambuf<...> + + At the same time, the new functions reset_get/put_buffer + are now used instead of the previous monolithic function. + + ACE_Streambuf<...> + + Constructor changed: + + Initialization of the get/put buffers has been moved to the + baseclass ACE_Streambuf_T. This will reduce template bloat + as well as giving us more functionality as described above. + */ + #if !defined (ACE_IOSTREAM_H) #define ACE_IOSTREAM_H #include "ace/OS.h" +#include "ace/INET_Addr.h" #include <iomanip.h> #if defined (__GNUC__) && !defined (CHORUS) #include <String.h> +typedef String ACE_IOStream_String; +#endif /* __GNUC__ */ +// +#if defined (ACE_WIN32) +typedef CString ACE_IOStream_String; +#endif /* ACE_WIN32 */ -class QuotedString : public String +#if defined(__GNUC__) || defined(ACE_WIN32) + +class QuotedString : public ACE_IOStream_String { public: - inline QuotedString & operator =(char c) { return (QuotedString&) String::operator=(c); } - inline QuotedString & operator =(char* c) { return (QuotedString&) String::operator=(c); } + inline QuotedString() { + *this = ""; + } + inline QuotedString(const char * c) { + *this = ACE_IOStream_String(c); + } + inline QuotedString(const ACE_IOStream_String& s) { + *this = s; + } + inline QuotedString& operator=(const ACE_IOStream_String& s) { + return (QuotedString&) ACE_IOStream_String::operator=(s); + } + inline QuotedString & operator =(const char c) { + return (QuotedString&) ACE_IOStream_String::operator=(c); + } + inline QuotedString & operator =(const char* c) { + return (QuotedString&) ACE_IOStream_String::operator=(c); + } + inline bool operator < (const QuotedString& s) const { + return *(ACE_IOStream_String *)this < (ACE_IOStream_String)s; + } +#if defined (ACE_WIN32) + inline int length(void) { + return this->GetLength(); + } +#endif }; -#endif /* __GNUC__ */ -template <class STREAM> -class ACE_Streambuf : public streambuf +#endif /* __GNUC__ || ACE_WIN32 */ + +/////////////////////////////////////////////////////////////////////////// + +class ACE_Export ACE_Streambuf_T : public streambuf // = TITLE // Create your custom streambuf by providing and ACE_*_Stream // object to this template. I have tested it with // ACE_SOCK_Stream and it should work fine for others as well. - // I'm hoping to add functionality for ACE_SOCK_Dgram soon... // // = DESCRIPTION // For any iostream object, the real work is done by the @@ -99,19 +192,51 @@ class ACE_Streambuf : public streambuf // "syncing" the input. It simply remains buffered. { public: - ACE_Streambuf (STREAM * peer, int io_mode = ios::in | ios::out); - // We will be given a STREAM by the iostream object which creates - // us. See the ACE_IOStream template for how that works. Like - // other streambuf objects, we can be input-only, output-only or - // both. - virtual ~ACE_Streambuf (void); + virtual ~ACE_Streambuf_T (void); // If the default allocation strategey were used the common buffer // would be deleted when the object destructs. Since we are // providing separate read/write buffers, it is up to us to manage // their memory. + ACE_Time_Value * recv_timeout( ACE_Time_Value * tv = NULL ); + // Get the current Time_Value pointer and provide a new one. + + char * reset_put_buffer(char * newBuffer = NULL, u_int _streambuf_size = 0, u_int _pptr = 0 ); + // Use this to allocate a new/different buffer for put operations. If you + // do not provide a buffer pointer, one will be allocated. That is the + // preferred method. If you do provide a buffer, the size must match that + // being used by the get buffer. + // If successful, you will receive a pointer to the current put buffer. + // It is your responsibility to delete this memory when you are done with it. + + u_int put_avail(void); + // Return the number of bytes to be 'put' onto the stream media. + // pbase + put_avail = pptr + + char * reset_get_buffer(char * newBuffer = NULL, u_int _streambuf_size = 0, u_int _gptr = 0, u_int _egptr = 0 ); + // Use this to allocate a new/different buffer for get operations. If you + // do not provide a buffer pointer, one will be allocated. That is the + // preferred method. If you do provide a buffer, the size must match that + // being used by the put buffer. + // If successful, you will receive a pointer to the current get buffer. + // It is your responsibility to delete this memory when you are done with it. + + u_int get_waiting(void); + // Return the number of bytes not yet gotten. + // eback + get_waiting = gptr + // + u_int get_avail(void); + // Return the number of bytes in the get area (includes some already gotten); + // eback + get_avail = egptr + // + + u_int streambuf_size(void); + // Query the streambuf for the size of it's buffers. + protected: + ACE_Streambuf_T (u_int streambuf_size, int io_mode); + virtual int sync (void); // Sync both input and output. See syncin/syncout below for // descriptions. @@ -123,10 +248,11 @@ protected: // The overflow function receives the character which caused the // overflow. -private: - STREAM *peer_; - // This will be our ACE_SOCK_Stream or similar object. + void reset_base(void); + // Resets the base() pointer and streambuf mode. This is + // used internally when get/put buffers are allocatd. +protected: // = Two pointer sets for manipulating the read/write areas. char *eback_saved_; char *gptr_saved_; @@ -146,6 +272,15 @@ private: // mode tells us if we're working for an istream, ostream, or // iostream. + const u_int streambuf_size_; + // This defines the size of the input and output buffers. It can + // be set by the object constructor. + + ACE_Time_Value recv_timeout_value_; + ACE_Time_Value * recv_timeout_; + // We want to allow the user to provide Time_Value pointers to + // prevent infinite blocking while waiting to receive data. + int syncin (void); // syncin is called when the input needs to be synced with the // source file. In a filebuf, this results in the seek() system @@ -168,28 +303,68 @@ private: // underflow. It will attempt to fill the read buffer from the // peer. - int get_one_byte (void); + virtual int get_one_byte ( ); // Used by fillbuf and others to get exactly one byte from the peer. // recv_n is used to be sure we block until something is available. + // It is virtual because we really need to override it for + // datagram-derived objects. + + virtual ssize_t send ( char * buf, ssize_t len ) = 0; + virtual ssize_t recv ( char * buf, ssize_t len, ACE_Time_Value * tv = NULL ) = 0; + virtual ssize_t recv ( char * buf, ssize_t len, int flags, ACE_Time_Value * tv = NULL ) = 0; + virtual ssize_t recv_n( char * buf, ssize_t len, int flags = 0, ACE_Time_Value * tv = NULL ) = 0; + // Stream connections and "unconnected connections" (ie -- datagrams) + // need to work just a little differently. We derive custom + // Streambuf objects for them and provide these functions at that time. + + virtual ACE_HANDLE get_handle(void) + { + return 0; + } }; -// This macro defines the get operator for class MT into datatype DT. -// We will use it below to quickly override most (all?) iostream get -// operators. Notice how the ipfx() and isfx() functions are used. +/////////////////////////////////////////////////////////////////////////// -#define ACE_OPERATORG(MT,DT) \ - inline virtual MT& operator>> (DT v) { \ - if (ipfx ()) iostream::operator>> (v); isfx (); return *this; \ - } +template <class STREAM> +class ACE_Streambuf : public ACE_Streambuf_T +{ +public: + ACE_Streambuf (STREAM * peer, u_int streambuf_size = ACE_STREAMBUF_SIZE, int io_mode = ios::in | ios::out); + // We will be given a STREAM by the iostream object which creates + // us. See the ACE_IOStream template for how that works. Like + // other streambuf objects, we can be input-only, output-only or + // both. -// This macro defines the put operator for class MT into datatype DT. -// We will use it below to quickly override most (all?) iostream put -// operators. Notice how the opfx() and osfx() functions are used. + virtual ssize_t send ( char * buf, ssize_t len ) + { + return peer_->send_n(buf,len); + } + virtual ssize_t recv ( char * buf, ssize_t len, ACE_Time_Value * tv = NULL ) + { + return this->recv( buf, len, 0, tv ); + } + virtual ssize_t recv ( char * buf, ssize_t len, int flags, ACE_Time_Value * tv = NULL ) + { + ssize_t rval = peer_->recv(buf,len,flags,tv); + return rval; + } + virtual ssize_t recv_n( char * buf, ssize_t len, int flags = 0, ACE_Time_Value * tv = NULL ) + { + ssize_t rval = peer_->recv_n(buf,len,flags,tv); + return rval; + } + +protected: + STREAM * peer_; + // This will be our ACE_SOCK_Stream or similar object. + + virtual ACE_HANDLE get_handle(void) + { + return peer_ ? peer_->get_handle() : 0 ; + } +}; -#define ACE_OPERATORP(MT,DT) \ - inline virtual MT& operator<< (DT v) { \ - if (opfx ()) iostream::operator<< (v); osfx (); return *this; \ - } +/////////////////////////////////////////////////////////////////////////// // These typedefs are provided by G++ (on some systems?) without the // trailing '_'. Since we can't count on 'em, I've defined them to @@ -204,83 +379,95 @@ typedef ostream& (*__omanip_)(ostream&); // // virtual MT& operator<<(ios& (*func)(ios&)) { (*func)(*this); return *this; } + + +// This macro defines the get operator for class MT into datatype DT. +// We will use it below to quickly override most (all?) iostream get +// operators. Notice how the ipfx() and isfx() functions are used. + +#define GET_SIG(MT,DT) inline virtual MT& operator>> (DT v) +#define GET_CODE { if (ipfx ()) iostream::operator>> (v); isfx (); return *this; } +#define GET_PROT(MT,DT,CODE) GET_SIG(MT,DT) CODE +#define GET_FUNC(MT,DT) GET_PROT(MT,DT,GET_CODE) + +// This macro defines the put operator for class MT into datatype DT. +// We will use it below to quickly override most (all?) iostream put +// operators. Notice how the opfx() and osfx() functions are used. + +#define PUT_SIG(MT,DT) inline virtual MT& operator<< (DT v) +#define PUT_CODE { if (opfx ()) iostream::operator<< (v); osfx (); return *this; } +#define PUT_PROT(MT,DT,CODE) PUT_SIG(MT,DT) CODE +#define PUT_FUNC(MT,DT) PUT_PROT(MT,DT,PUT_CODE) + + // These are necessary in case somebody wants to derive from us and // override one of these with a custom approach. +#define GET_FUNC_SET0(MT,CODE,CODE2) \ + GET_PROT(MT,short &,CODE) \ + GET_PROT(MT,u_short &,CODE) \ + GET_PROT(MT,int &,CODE) \ + GET_PROT(MT,u_int &,CODE) \ + GET_PROT(MT,long &,CODE) \ + GET_PROT(MT,u_long &,CODE) \ + GET_PROT(MT,float &,CODE) \ + GET_PROT(MT,double &,CODE) \ + GET_PROT(MT,long double &,CODE) \ + GET_PROT(MT,char &,CODE) \ + GET_PROT(MT,u_char &,CODE) \ + GET_PROT(MT,char *,CODE) \ + GET_PROT(MT,u_char *,CODE) \ + inline virtual MT& operator>>(__omanip_ func) CODE2 \ + inline virtual MT& operator>>(__manip_ func) CODE2 + +#define PUT_FUNC_SET0(MT,CODE,CODE2) \ + PUT_PROT(MT,short,CODE) \ + PUT_PROT(MT,u_short,CODE) \ + PUT_PROT(MT,int,CODE) \ + PUT_PROT(MT,u_int,CODE) \ + PUT_PROT(MT,long,CODE) \ + PUT_PROT(MT,u_long,CODE) \ + PUT_PROT(MT,float,CODE) \ + PUT_PROT(MT,double,CODE) \ + PUT_PROT(MT,char,CODE) \ + PUT_PROT(MT,u_char,CODE) \ + PUT_PROT(MT,const char *,CODE) \ + PUT_PROT(MT,const u_char *,CODE) \ + PUT_PROT(MT,const void *,CODE) \ + inline virtual MT& operator<<(__omanip_ func) CODE2 \ + inline virtual MT& operator<<(__manip_ func) CODE2 + + #if defined (ACE_LACKS_SIGNED_CHAR) -#define ACE_OPERATORG_SET(MT) \ - ACE_OPERATORG(MT,short &); \ - ACE_OPERATORG(MT,u_short &); \ - ACE_OPERATORG(MT,int &); \ - ACE_OPERATORG(MT,u_int &); \ - ACE_OPERATORG(MT,long &); \ - ACE_OPERATORG(MT,u_long &); \ - ACE_OPERATORG(MT,float &); \ - ACE_OPERATORG(MT,double &); \ - ACE_OPERATORG(MT,long double &); \ - ACE_OPERATORG(MT,char &) \ - ACE_OPERATORG(MT,u_char &); \ - ACE_OPERATORG(MT,char *) \ - ACE_OPERATORG(MT,u_char *); \ - virtual MT& operator>>(__omanip_ func) { (*func)(*this); return *this; } \ - virtual MT& operator>>(__manip_ func) { (*func)(*this); return *this; } - -#define ACE_OPERATORP_SET(MT) \ - ACE_OPERATORP(MT,short); \ - ACE_OPERATORP(MT,u_short); \ - ACE_OPERATORP(MT,int); \ - ACE_OPERATORP(MT,u_int); \ - ACE_OPERATORP(MT,long); \ - ACE_OPERATORP(MT,u_long); \ - ACE_OPERATORP(MT,float); \ - ACE_OPERATORP(MT,double); \ - ACE_OPERATORP(MT,char); \ - ACE_OPERATORP(MT,u_char); \ - ACE_OPERATORP(MT,const char *); \ - ACE_OPERATORP(MT,const u_char *); \ - ACE_OPERATORP(MT,const void *); \ - virtual MT& operator<<(__omanip_ func) { (*func)(*this); return *this; } \ - virtual MT& operator<<(__manip_ func) { (*func)(*this); return *this; } + #define GET_FUNC_SET1(MT,CODE,CODE2) GET_FUNC_SET0(MT,CODE,CODE2) + #define PUT_FUNC_SET1(MT,CODE,CODE2) PUT_FUNC_SET0(MT,CODE,CODE2) #else -#define ACE_OPERATORG_SET(MT) \ - ACE_OPERATORG(MT,short &); \ - ACE_OPERATORG(MT,u_short &); \ - ACE_OPERATORG(MT,int &); \ - ACE_OPERATORG(MT,u_int &); \ - ACE_OPERATORG(MT,long &); \ - ACE_OPERATORG(MT,u_long &); \ - ACE_OPERATORG(MT,float &); \ - ACE_OPERATORG(MT,double &); \ - ACE_OPERATORG(MT,long double &); \ - ACE_OPERATORG(MT,char &) \ - ACE_OPERATORG(MT,u_char &); \ - ACE_OPERATORG(MT,signed char &); \ - ACE_OPERATORG(MT,char *) \ - ACE_OPERATORG(MT,u_char *); \ - ACE_OPERATORG(MT,signed char *); \ - virtual MT& operator>>(__omanip_ func) { (*func)(*this); return *this; } \ - virtual MT& operator>>(__manip_ func) { (*func)(*this); return *this; } - -#define ACE_OPERATORP_SET(MT) \ - ACE_OPERATORP(MT,short); \ - ACE_OPERATORP(MT,u_short); \ - ACE_OPERATORP(MT,int); \ - ACE_OPERATORP(MT,u_int); \ - ACE_OPERATORP(MT,long); \ - ACE_OPERATORP(MT,u_long); \ - ACE_OPERATORP(MT,float); \ - ACE_OPERATORP(MT,double); \ - ACE_OPERATORP(MT,char); \ - ACE_OPERATORP(MT,u_char); \ - ACE_OPERATORP(MT,signed char); \ - ACE_OPERATORP(MT,const char *); \ - ACE_OPERATORP(MT,const u_char *); \ - ACE_OPERATORP(MT,const signed char *); \ - ACE_OPERATORP(MT,const void *); \ - virtual MT& operator<<(__omanip_ func) { (*func)(*this); return *this; } \ - virtual MT& operator<<(__manip_ func) { (*func)(*this); return *this; } + #define GET_FUNC_SET1(MT,CODE,CODE2) \ + GET_PROT(MT,signed char &,CODE) \ + GET_PROT(MT,signed char *,CODE) \ + GET_FUNC_SET0(MT,CODE,CODE2) + + #define PUT_FUNC_SET1(MT,CODE,CODE2) \ + PUT_FUNC(MT,signed char) \ + PUT_FUNC(MT,const signed char *) \ + PUT_FUNC_SET0(MT,CODE,CODE2) #endif /* ACE_LACKS_SIGNED_CHAR */ +#define GET_MANIP_CODE { if( ipfx() ) { (*func)(*this); } isfx(); return *this; } +#define PUT_MANIP_CODE { if( opfx() ) { (*func)(*this); } osfx(); return *this; } + +#define GET_FUNC_SET(MT) GET_FUNC_SET1(MT,GET_CODE,GET_MANIP_CODE) +#define PUT_FUNC_SET(MT) PUT_FUNC_SET1(MT,PUT_CODE,PUT_MANIP_CODE) +#define GETPUT_FUNC_SET(MT) GET_FUNC_SET(MT) PUT_FUNC_SET(MT) + + +#define GET_SIG_SET(MT) GET_FUNC_SET1(MT,= 0;,= 0;) +#define PUT_SIG_SET(MT) PUT_FUNC_SET1(MT,= 0;,= 0;) +#define GETPUT_SIG_SET(MT) GET_SIG_SET(MT) PUT_SIG_SET(MT) + + +/////////////////////////////////////////////////////////////////////////// + template <class STREAM> class ACE_IOStream : public iostream, public STREAM // = TITLE @@ -316,12 +503,12 @@ class ACE_IOStream : public iostream, public STREAM // customize only one or two. { public: - ACE_IOStream (void); + ACE_IOStream ( STREAM & stream, u_int streambuf_size = ACE_STREAMBUF_SIZE); + ACE_IOStream ( u_int streambuf_size = ACE_STREAMBUF_SIZE); // The default constructor. This will initiailze your STREAM and // then setup the iostream baseclass to use a custom streambuf based // on STREAM. - virtual ~ACE_IOStream (void); // We have to get rid of the streambuf_ ourselves since we gave it // to iostream(); @@ -330,43 +517,35 @@ public: // The only ambituity in the multiple inheritance is the close() // function. -#if defined (__GNUC__) - virtual ACE_IOStream& operator>>(String & v); +#if defined(__GNUC__) || defined(ACE_WIN32) + virtual ACE_IOStream & operator>>(ACE_IOStream_String & v); // A simple string operator. The base iostream has 'em for char* // but that isn't always the best thing for a String. If we don't // provide our own here, we may not get what we want. - virtual ACE_IOStream& operator>>(QuotedString &v); + virtual ACE_IOStream & operator<<(ACE_IOStream_String & v); + // The converse of the String put operator. + + virtual ACE_IOStream & operator>>(QuotedString &v); // A more clever operator that handles quoted strings so that we // can get strings containing whitespace! - virtual ACE_IOStream& operator<<(QuotedString &v); + virtual ACE_IOStream & operator<<(QuotedString &v); // The converse of the QuotedString put operator. -#endif /* __GNUG__ */ +#endif /* __GNUC__ || ACE_WIN32 */ -#if !defined (ACE_LACKS_IOSTREAM_SETGET) // = Using the macros to provide get/set operators. - ACE_OPERATORG_SET (ACE_IOStream<STREAM>); - ACE_OPERATORP_SET (ACE_IOStream<STREAM>); +#if !defined (ACE_LACKS_IOSTREAM_SETGET) + GETPUT_FUNC_SET (ACE_IOStream<STREAM>) #endif /* ACE_LACKS_IOSTREAM_SETSET */ - // = These are handy to have around for overriding. - - // The *pfx functions are called at the beginning of each get/put - // operator. The *sfx are called at the end. In a derivative - // class, I've overridden the osfx() operator such that a space will - // be inserted after every put operation so that my transmitted - // "fields" are always separated. - #if defined (ACE_LACKS_IOSTREAM_FX) - // These should be faked out to do the right thing, if we knew - // what that was. Instead, they're just faked out. - virtual int ipfx (int need = 0) { ACE_UNUSED_ARG (need); return 1; } - virtual int ipfx0(void) { return 1; } // Optimized ipfx(0) - virtual int ipfx1(void) { return 1; } // Optimized ipfx(1) - virtual void isfx (void) { /* null */ } - virtual int opfx (void) { return 1; } - virtual void osfx (void) { /* null */ } + virtual int ipfx (int need = 0) { ACE_UNUSED_ARG (need); return good(); } + virtual int ipfx0(void) { return good(); } // Optimized ipfx(0) + virtual int ipfx1(void) { return good(); } // Optimized ipfx(1) + virtual void isfx (void) { } + virtual int opfx (void) { return good(); } + virtual void osfx (void) { put(' '); } #else #if defined (__GNUC__) virtual int ipfx0(void) { return(iostream::ipfx0()); } // Optimized ipfx(0) @@ -381,11 +560,17 @@ public: virtual void osfx (void) { iostream::osfx(); } #endif /* ACE_LACKS_IOSTREAM_FX */ + ACE_IOStream & operator>>( ACE_Time_Value *& tv ); + // Allow the programmer to provide a timeout for read operations. + // Give it a pointer to NULL to block forever. + protected: + ACE_Streambuf<STREAM> *streambuf_; // This is where all of the action takes place. The // streambuf_ is the interface to the underlying STREAM. +private: // We move these into the private section so that they cannot // be used by the application programmer. This is necessary // because streambuf_ will be buffering IO on the STREAM @@ -397,8 +582,96 @@ protected: ssize_t recv_n (...); }; +/////////////////////////////////////////////////////////////////////////// + +template <class STREAM> +class ACE_SOCK_Dgram_SC : public STREAM +// Datagrams don't have the notion of a "peer". Each send and receive +// on a datagram can go to a different peer if you want. If you're +// using datagrams for stream activity, you probably want 'em all to +// go to (and come from) the same place. That's what this class is +// for. BTW: 'Dgram_SC' is short for 'Datagram-Self-Contained'. +// Here, we keep an address object so that we can remember who last +// sent us data. When we write back, we're then able to write back +// to that same address. +{ +protected: + ACE_INET_Addr peer_; + +public: + ACE_SOCK_Dgram_SC() : STREAM() + { + } + + ACE_SOCK_Dgram_SC ( STREAM & source, ACE_INET_Addr & dest ) + : STREAM( source ), peer_ ( dest ) + { + } + + inline ssize_t send_n( char * buf,ssize_t len ) + { + return STREAM::send(buf,len,peer_); + } + inline ssize_t recv ( char * buf,ssize_t len, ACE_Time_Value * tv = NULL) + { + return recv( buf, len, 0, tv ); + } + inline ssize_t recv ( char * buf,ssize_t len, int flags, ACE_Time_Value * tv = NULL) + { + if( tv != 0 ) + { + ACE_HANDLE handle = this->get_handle(); + ACE_Handle_Set handle_set; + + handle_set.set_bit (handle); + + switch (ACE_OS::select (int (handle) + 1, + (fd_set *) handle_set, // read_fds. + (fd_set *) 0, // write_fds. + (fd_set *) 0, // exception_fds. + tv)) + { + case 0: + errno = ETIME; + case -1: + return -1; + default: + ; // Do the 'recv' below + } + } + + int rval = STREAM::recv (buf,len,peer_,flags); +#ifdef WIN32 + if( rval == SOCKET_ERROR ) + if( WSAGetLastError() == WSAEMSGSIZE ) + if( flags & MSG_PEEK ) + rval = len; +#endif + + return (rval<len)?rval:len; + } + inline ssize_t recv_n( char * buf,ssize_t len, int flags = 0, ACE_Time_Value * tv = NULL ) + { + int rval = this->recv( buf, len, flags, tv ); + return rval; + } + inline int get_remote_addr (ACE_INET_Addr & addr) const + { + addr = peer_; + return 0; + } + +}; + +/////////////////////////////////////////////////////////////////////////// + + #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "IOStream.cpp" +# if ! defined( ACE_IOSTREAM_C ) +# define ACE_IOSTREAM_BUILDING_TEMPLATE +# endif +# include "IOStream.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #endif /* ACE_IOSTREAM_H */ + |