Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / IOStream_T.inl
blob513d6ecb1d24cd8d16b22767579e94a6e38be049
1 // -*- C++ -*-
2 //
3 // $Id: IOStream_T.inl 80826 2008-03-04 14:51:23Z wotte $
5 #include "ace/Handle_Set.h"
6 #include "ace/OS_NS_errno.h"
7 #include "ace/OS_NS_sys_select.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 template <class STREAM> ACE_INLINE int
12 ACE_IOStream<STREAM>::eof (void) const
14   // Get the timeout value of the streambuf
15   ACE_Time_Value *timeout = this->streambuf_->recv_timeout (0);
17   // Reset the timeout value of the streambuf.
18   (void) this->streambuf_->recv_timeout (timeout);
20   char c;
21   int rval = this->streambuf_->recv_n (&c,
22                                        sizeof c,
23                                        MSG_PEEK,
24                                        timeout);
26   // Timeout, not an eof
27   if (this->streambuf_->timeout())
28     return 0;
30   // No timeout, got enough data:  not eof
31   if (rval == sizeof(char))
32     return 0;
34   // No timeout, not enough data:  definately eof
35   return 1;
38 template <class STREAM> ACE_INLINE
39 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (void)
43 template <class STREAM> ACE_INLINE
44 ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (STREAM &source,
45                                               ACE_INET_Addr &dest)
46   : STREAM (source),
47     peer_ (dest)
51 template <class STREAM> ACE_INLINE ssize_t
52 ACE_SOCK_Dgram_SC<STREAM>::send_n (char *buf,
53                                    ssize_t len)
55   return STREAM::send (buf, len, peer_);
58 template <class STREAM> ACE_INLINE ssize_t
59 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
60                                  ssize_t len,
61                                  ACE_Time_Value *tv)
63   //FUZZ: disable check_for_lack_ACE_OS
64   return recv (buf, len, 0, tv);
65   //FUZZ: enable check_for_lack_ACE_OS
68 template <class STREAM> ACE_INLINE ssize_t
69 ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
70                                  ssize_t len,
71                                  int flags,
72                                  ACE_Time_Value *tv)
74   if (tv != 0)
75     {
76       ACE_HANDLE handle = this->get_handle ();
77       ACE_Handle_Set handle_set;
79       handle_set.set_bit (handle);
81       switch (ACE_OS::select (int (handle) + 1,
82                               (fd_set *) handle_set, // read_fds.
83                               (fd_set *) 0,          // write_fds.
84                               (fd_set *) 0,          // exception_fds.
85                               tv))
86         {
87         case 0:
88           errno = ETIME;
89         case -1:
90           return -1;
91         default:
92           ;     // Do the 'recv' below
93         }
94     }
96   int rval = STREAM::recv (buf, len, peer_, flags);
97 #if defined (ACE_WIN32)
98   if (rval == SOCKET_ERROR)
99     if (::WSAGetLastError () == WSAEMSGSIZE)
100       if (ACE_BIT_ENABLED (flags, MSG_PEEK))
101         rval = len;
102 #endif /* ACE_WIN32 */
103   return rval < len ? rval : len;
106 template <class STREAM> ACE_INLINE ssize_t
107 ACE_SOCK_Dgram_SC<STREAM>::recv_n (char *buf,
108                                    ssize_t len,
109                                    int flags,
110                                    ACE_Time_Value *tv)
112   int rval = this->recv (buf, len, flags, tv);
113   return rval;
116 template <class STREAM> ACE_INLINE int
117 ACE_SOCK_Dgram_SC<STREAM>::get_remote_addr (ACE_INET_Addr &addr) const
119   addr = peer_;
120   return 0;
123 ACE_END_VERSIONED_NAMESPACE_DECL