IOStream_T.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: IOStream_T.inl 80826 2008-03-04 14:51:23Z wotte $
00004 
00005 #include "ace/Handle_Set.h"
00006 #include "ace/OS_NS_errno.h"
00007 #include "ace/OS_NS_sys_select.h"
00008 
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010 
00011 template <class STREAM> ACE_INLINE int
00012 ACE_IOStream<STREAM>::eof (void) const
00013 {
00014   // Get the timeout value of the streambuf
00015   ACE_Time_Value *timeout = this->streambuf_->recv_timeout (0);
00016 
00017   // Reset the timeout value of the streambuf.
00018   (void) this->streambuf_->recv_timeout (timeout);
00019 
00020   char c;
00021   int rval = this->streambuf_->recv_n (&c,
00022                                        sizeof c,
00023                                        MSG_PEEK,
00024                                        timeout);
00025 
00026   // Timeout, not an eof
00027   if (this->streambuf_->timeout())
00028     return 0;
00029 
00030   // No timeout, got enough data:  not eof
00031   if (rval == sizeof(char))
00032     return 0;
00033 
00034   // No timeout, not enough data:  definately eof
00035   return 1;
00036 }
00037 
00038 template <class STREAM> ACE_INLINE
00039 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (void)
00040 {
00041 }
00042 
00043 template <class STREAM> ACE_INLINE
00044 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (STREAM &source,
00045                                               ACE_INET_Addr &dest)
00046   : STREAM (source),
00047     peer_ (dest)
00048 {
00049 }
00050 
00051 template <class STREAM> ACE_INLINE ssize_t
00052 ACE_SOCK_Dgram_SC<STREAM>::send_n (char *buf,
00053                                    ssize_t len)
00054 {
00055   return STREAM::send (buf, len, peer_);
00056 }
00057 
00058 template <class STREAM> ACE_INLINE ssize_t
00059 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
00060                                  ssize_t len,
00061                                  ACE_Time_Value *tv)
00062 {
00063   //FUZZ: disable check_for_lack_ACE_OS
00064   return recv (buf, len, 0, tv);
00065   //FUZZ: enable check_for_lack_ACE_OS
00066 }
00067 
00068 template <class STREAM> ACE_INLINE ssize_t
00069 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
00070                                  ssize_t len,
00071                                  int flags,
00072                                  ACE_Time_Value *tv)
00073 {
00074   if (tv != 0)
00075     {
00076       ACE_HANDLE handle = this->get_handle ();
00077       ACE_Handle_Set handle_set;
00078 
00079       handle_set.set_bit (handle);
00080 
00081       switch (ACE_OS::select (int (handle) + 1,
00082                               (fd_set *) handle_set, // read_fds.
00083                               (fd_set *) 0,          // write_fds.
00084                               (fd_set *) 0,          // exception_fds.
00085                               tv))
00086         {
00087         case 0:
00088           errno = ETIME;
00089         case -1:
00090           return -1;
00091         default:
00092           ;     // Do the 'recv' below
00093         }
00094     }
00095 
00096   int rval = STREAM::recv (buf, len, peer_, flags);
00097 #if defined (ACE_WIN32)
00098   if (rval == SOCKET_ERROR)
00099     if (::WSAGetLastError () == WSAEMSGSIZE)
00100       if (ACE_BIT_ENABLED (flags, MSG_PEEK))
00101         rval = len;
00102 #endif /* ACE_WIN32 */
00103   return rval < len ? rval : len;
00104 }
00105 
00106 template <class STREAM> ACE_INLINE ssize_t
00107 ACE_SOCK_Dgram_SC<STREAM>::recv_n (char *buf,
00108                                    ssize_t len,
00109                                    int flags,
00110                                    ACE_Time_Value *tv)
00111 {
00112   int rval = this->recv (buf, len, flags, tv);
00113   return rval;
00114 }
00115 
00116 template <class STREAM> ACE_INLINE int
00117 ACE_SOCK_Dgram_SC<STREAM>::get_remote_addr (ACE_INET_Addr &addr) const
00118 {
00119   addr = peer_;
00120   return 0;
00121 }
00122 
00123 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:40 2010 for ACE by  doxygen 1.4.7