IOStream_T.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // IOStream_T.inl,v 4.3 2005/10/28 16:14:52 ossama Exp
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   return recv (buf, len, 0, tv);
00064 }
00065 
00066 template <class STREAM> ACE_INLINE ssize_t
00067 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
00068                                  ssize_t len,
00069                                  int flags,
00070                                  ACE_Time_Value *tv)
00071 {
00072   if (tv != 0)
00073     {
00074       ACE_HANDLE handle = this->get_handle ();
00075       ACE_Handle_Set handle_set;
00076 
00077       handle_set.set_bit (handle);
00078 
00079       switch (ACE_OS::select (int (handle) + 1,
00080                               (fd_set *) handle_set, // read_fds.
00081                               (fd_set *) 0,          // write_fds.
00082                               (fd_set *) 0,          // exception_fds.
00083                               tv))
00084         {
00085         case 0:
00086           errno = ETIME;
00087         case -1:
00088           return -1;
00089         default:
00090           ;     // Do the 'recv' below
00091         }
00092     }
00093 
00094   int rval = STREAM::recv (buf, len, peer_, flags);
00095 #if defined (ACE_WIN32)
00096   if (rval == SOCKET_ERROR)
00097     if (::WSAGetLastError () == WSAEMSGSIZE)
00098       if (ACE_BIT_ENABLED (flags, MSG_PEEK))
00099         rval = len;
00100 #endif /* ACE_WIN32 */
00101   return rval < len ? rval : len;
00102 }
00103 
00104 template <class STREAM> ACE_INLINE ssize_t
00105 ACE_SOCK_Dgram_SC<STREAM>::recv_n (char *buf,
00106                                    ssize_t len,
00107                                    int flags,
00108                                    ACE_Time_Value *tv)
00109 {
00110   int rval = this->recv (buf, len, flags, tv);
00111   return rval;
00112 }
00113 
00114 template <class STREAM> ACE_INLINE int
00115 ACE_SOCK_Dgram_SC<STREAM>::get_remote_addr (ACE_INET_Addr &addr) const
00116 {
00117   addr = peer_;
00118   return 0;
00119 }
00120 
00121 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:52 2006 for ACE by doxygen 1.3.6