summaryrefslogtreecommitdiff
path: root/ace/IOStream_T.i
blob: 9ae8f0017af06d2c27869c201dbaf987a9357baa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* -*- C++ -*- */

template <class STREAM> ssize_t
ACE_Streambuf_T<STREAM>::send (char *buf, ssize_t len)
{
  return peer_->send_n (buf,len);
}

template <class STREAM> ssize_t
ACE_Streambuf_T<STREAM>::recv (char *buf,
                               ssize_t len,
                               ACE_Time_Value *tv)
{
  return this->recv (buf, len, 0, tv);
}

template <class STREAM> ssize_t
ACE_Streambuf_T<STREAM>::recv (char *buf,
                               ssize_t len,
                               int flags,
                               ACE_Time_Value * tv)
{
  ssize_t rval = peer_->recv (buf, len, flags, tv);
  return rval;
}

template <class STREAM> ssize_t
ACE_Streambuf_T<STREAM>::recv_n (char *buf,
                                 ssize_t len,
                                 int flags,
                                 ACE_Time_Value *tv)
{
  ssize_t rval =  peer_->recv_n (buf, len, flags, tv);
  return rval;
}

template <class STREAM> ACE_HANDLE
ACE_Streambuf_T<STREAM>::get_handle (void)
{
  return peer_ ? peer_->get_handle () : 0;
}

template <class STREAM> ACE_INLINE int
ACE_IOStream<STREAM>::eof (void) const
{
#if 0
  char c;
  return ACE_OS::recv (this->get_handle (),
                       &c,
                       sizeof c,
                       MSG_PEEK) <= 0;
#endif /* 0 */
  // Get the timeout value of the streambuf
  ACE_Time_Value *timeout = this->streambuf_->recv_timeout (0);

  // Reset the timeout value of the streambuf.
  (void) this->streambuf_->recv_timeout (timeout);
 
  char c;
  int rval = this->streambuf_->recv_n (&c,
                                       sizeof c,
                                       MSG_PEEK,
                                       timeout);
 
  // If recv_n() didn't fail or failed because of timeout we're not at
  // EOF.
  return rval != -1 && ! this->streambuf_->timeout ();
}

template <class STREAM> ACE_INLINE
ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (void)
{
}

template <class STREAM> ACE_INLINE
ACE_SOCK_Dgram_SC<STREAM>::ACE_SOCK_Dgram_SC (STREAM &source,
                                              ACE_INET_Addr &dest)
  : STREAM (source),
    peer_ (dest)
{
}

template <class STREAM> ACE_INLINE ssize_t
ACE_SOCK_Dgram_SC<STREAM>::send_n (char *buf,
                                   ssize_t len)
{
  return STREAM::send (buf, len, peer_);
}

template <class STREAM> ACE_INLINE ssize_t
ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
                                 ssize_t len,
                                 ACE_Time_Value *tv)
{
  return recv (buf, len, 0, tv);
}

template <class STREAM> ACE_INLINE ssize_t
ACE_SOCK_Dgram_SC<STREAM>::recv (char *buf,
                                 ssize_t len,
                                 int flags,
                                 ACE_Time_Value *tv)
{
  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);
#if defined (ACE_WIN32)
  if (rval == SOCKET_ERROR)
    if (::WSAGetLastError () == WSAEMSGSIZE)
      if (ACE_BIT_ENABLED (flags, MSG_PEEK))
        rval = len;
#endif /* ACE_WIN32 */
  return rval < len ? rval : len;
}

template <class STREAM> ACE_INLINE ssize_t
ACE_SOCK_Dgram_SC<STREAM>::recv_n (char *buf,
                                   ssize_t len,
                                   int flags,
                                   ACE_Time_Value *tv)
{
  int rval = this->recv (buf, len, flags, tv);
  return rval;
}

template <class STREAM> ACE_INLINE int
ACE_SOCK_Dgram_SC<STREAM>::get_remote_addr (ACE_INET_Addr &addr) const
{
  addr = peer_;
  return 0;
}