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

IOStream_T.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: IOStream_T.i,v 1.1.1.2 2001/12/04 14:33:02 chad Exp $
00003 
00004 template <class STREAM> ssize_t
00005 ACE_Streambuf_T<STREAM>::send (char *buf, ssize_t len)
00006 {
00007   return peer_->send_n (buf,len);
00008 }
00009 
00010 template <class STREAM> ssize_t
00011 ACE_Streambuf_T<STREAM>::recv (char *buf,
00012                                ssize_t len,
00013                                ACE_Time_Value *tv)
00014 {
00015   return this->recv (buf, len, 0, tv);
00016 }
00017 
00018 template <class STREAM> ssize_t
00019 ACE_Streambuf_T<STREAM>::recv (char *buf,
00020                                ssize_t len,
00021                                int flags,
00022                                ACE_Time_Value * tv)
00023 {
00024   this->timeout_ = 0;
00025   errno = ESUCCESS;
00026   ssize_t rval = peer_->recv (buf, len, flags, tv);
00027   if (errno == ETIME)
00028     this->timeout_ = 1;
00029   return rval;
00030 }
00031 
00032 template <class STREAM> ssize_t
00033 ACE_Streambuf_T<STREAM>::recv_n (char *buf,
00034                                  ssize_t len,
00035                                  int flags,
00036                                  ACE_Time_Value *tv)
00037 {
00038   this->timeout_ = 0;
00039   errno = ESUCCESS;
00040   ssize_t rval = peer_->recv_n (buf, len, flags, tv);
00041   if (errno == ETIME)
00042     this->timeout_ = 1;
00043   return rval;
00044 }
00045 
00046 template <class STREAM> ACE_HANDLE
00047 ACE_Streambuf_T<STREAM>::get_handle (void)
00048 {
00049   return peer_ ? peer_->get_handle () : 0;
00050 }
00051 
00052 template <class STREAM> ACE_INLINE int
00053 ACE_IOStream<STREAM>::eof (void) const
00054 {
00055   // Get the timeout value of the streambuf
00056   ACE_Time_Value *timeout = this->streambuf_->recv_timeout (0);
00057 
00058   // Reset the timeout value of the streambuf.
00059   (void) this->streambuf_->recv_timeout (timeout);
00060 
00061   char c;
00062   int rval = this->streambuf_->recv_n (&c,
00063                                        sizeof c,
00064                                        MSG_PEEK,
00065                                        timeout);
00066 
00067   // Timeout, not an eof
00068   if (this->streambuf_->timeout())
00069     return 0;
00070 
00071   // No timeout, got enough data:  not eof
00072   if (rval == sizeof(char))
00073     return 0;
00074 
00075   // No timeout, not enough data:  definately eof
00076   return 1;
00077 }
00078 
00079 template <class STREAM> ACE_INLINE
00080 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (void)
00081 {
00082 }
00083 
00084 template <class STREAM> ACE_INLINE
00085 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (STREAM &source,
00086                                               ACE_INET_Addr &dest)
00087   : STREAM (source),
00088     peer_ (dest)
00089 {
00090 }
00091 
00092 template <class STREAM> ACE_INLINE ssize_t
00093 ACE_SOCK_Dgram_SC<STREAM>::send_n (char *buf,
00094                                    ssize_t len)
00095 {
00096   return STREAM::send (buf, len, peer_);
00097 }
00098 
00099 template <class STREAM> ACE_INLINE ssize_t
00100 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
00101                                  ssize_t len,
00102                                  ACE_Time_Value *tv)
00103 {
00104   return recv (buf, len, 0, tv);
00105 }
00106 
00107 template <class STREAM> ACE_INLINE ssize_t
00108 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
00109                                  ssize_t len,
00110                                  int flags,
00111                                  ACE_Time_Value *tv)
00112 {
00113   if (tv != 0)
00114     {
00115       ACE_HANDLE handle = this->get_handle ();
00116       ACE_Handle_Set handle_set;
00117 
00118       handle_set.set_bit (handle);
00119 
00120       switch (ACE_OS::select (int (handle) + 1,
00121                               (fd_set *) handle_set, // read_fds.
00122                               (fd_set *) 0,          // write_fds.
00123                               (fd_set *) 0,          // exception_fds.
00124                               tv))
00125         {
00126         case 0:
00127           errno = ETIME;
00128         case -1:
00129           return -1;
00130         default:
00131           ;     // Do the 'recv' below
00132         }
00133     }
00134 
00135   int rval = STREAM::recv (buf, len, peer_, flags);
00136 #if defined (ACE_WIN32)
00137   if (rval == SOCKET_ERROR)
00138     if (::WSAGetLastError () == WSAEMSGSIZE)
00139       if (ACE_BIT_ENABLED (flags, MSG_PEEK))
00140         rval = len;
00141 #endif /* ACE_WIN32 */
00142   return rval < len ? rval : len;
00143 }
00144 
00145 template <class STREAM> ACE_INLINE ssize_t
00146 ACE_SOCK_Dgram_SC<STREAM>::recv_n (char *buf,
00147                                    ssize_t len,
00148                                    int flags,
00149                                    ACE_Time_Value *tv)
00150 {
00151   int rval = this->recv (buf, len, flags, tv);
00152   return rval;
00153 }
00154 
00155 template <class STREAM> ACE_INLINE int
00156 ACE_SOCK_Dgram_SC<STREAM>::get_remote_addr (ACE_INET_Addr &addr) const
00157 {
00158   addr = peer_;
00159   return 0;
00160 }

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