~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/viosocket.c

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  the file descriptior.
21
21
*/
22
22
 
23
 
#include "vio_priv.h"
 
23
#define DONT_MAP_VIO
 
24
#include <drizzled/global.h>
 
25
#include "vio.h"
 
26
#include <drizzled/util/test.h>
 
27
 
24
28
#include <sys/socket.h>
25
 
 
26
 
int vio_errno(Vio *vio __attribute__((unused)))
 
29
#include <string.h>
 
30
 
 
31
#include <netinet/tcp.h>
 
32
#include <sys/poll.h>
 
33
 
 
34
#include <netdb.h>
 
35
 
 
36
int drizzleclient_vio_errno(Vio *vio)
27
37
{
 
38
  (void)vio;
28
39
  return errno;
29
40
}
30
41
 
31
42
 
32
 
size_t vio_read(Vio * vio, unsigned char* buf, size_t size)
 
43
size_t drizzleclient_vio_read(Vio * vio, unsigned char* buf, size_t size)
33
44
{
34
45
  size_t r;
35
46
 
36
 
  /* Ensure nobody uses vio_read_buff and vio_read simultaneously */
 
47
  /* Ensure nobody uses drizzleclient_vio_read_buff and drizzleclient_vio_read simultaneously */
37
48
  assert(vio->read_end == vio->read_pos);
38
49
  r= read(vio->sd, buf, size);
39
50
 
46
57
  reduce number of syscalls.
47
58
*/
48
59
 
49
 
size_t vio_read_buff(Vio *vio, unsigned char* buf, size_t size)
 
60
size_t drizzleclient_vio_read_buff(Vio *vio, unsigned char* buf, size_t size)
50
61
{
51
62
  size_t rc;
52
63
#define VIO_UNBUFFERED_READ_MIN_SIZE 2048
58
69
    vio->read_pos+= rc;
59
70
    /*
60
71
      Do not try to read from the socket now even if rc < size:
61
 
      vio_read can return -1 due to an error or non-blocking mode, and
 
72
      drizzleclient_vio_read can return -1 due to an error or non-blocking mode, and
62
73
      the safest way to handle it is to move to a separate branch.
63
74
    */
64
75
  }
65
76
  else if (size < VIO_UNBUFFERED_READ_MIN_SIZE)
66
77
  {
67
 
    rc= vio_read(vio, (unsigned char*) vio->read_buffer, VIO_READ_BUFFER_SIZE);
 
78
    rc= drizzleclient_vio_read(vio, (unsigned char*) vio->read_buffer, VIO_READ_BUFFER_SIZE);
68
79
    if (rc != 0 && rc != (size_t) -1)
69
80
    {
70
81
      if (rc > size)
77
88
    }
78
89
  }
79
90
  else
80
 
    rc= vio_read(vio, buf, size);
 
91
    rc= drizzleclient_vio_read(vio, buf, size);
81
92
 
82
93
  return rc;
83
94
#undef VIO_UNBUFFERED_READ_MIN_SIZE
84
95
}
85
96
 
86
97
 
87
 
size_t vio_write(Vio * vio, const unsigned char* buf, size_t size)
 
98
size_t drizzleclient_vio_write(Vio * vio, const unsigned char* buf, size_t size)
88
99
{
89
100
  size_t r;
90
101
 
93
104
  return r;
94
105
}
95
106
 
96
 
int vio_blocking(Vio * vio, bool set_blocking_mode, bool *old_mode)
 
107
int drizzleclient_vio_blocking(Vio * vio, bool set_blocking_mode, bool *old_mode)
97
108
{
98
109
  int r=0;
99
110
 
120
131
}
121
132
 
122
133
bool
123
 
vio_is_blocking(Vio * vio)
 
134
drizzleclient_vio_is_blocking(Vio * vio)
124
135
{
125
136
  bool r;
126
137
  r = !(vio->fcntl_mode & O_NONBLOCK);
129
140
}
130
141
 
131
142
 
132
 
int vio_fastsend(Vio * vio __attribute__((unused)))
 
143
int drizzleclient_vio_fastsend(Vio * vio)
133
144
{
 
145
  (void)vio;
134
146
  int nodelay = 1;
135
147
  int error;
136
148
 
145
157
  return error;
146
158
}
147
159
 
148
 
int32_t vio_keepalive(Vio* vio, bool set_keep_alive)
 
160
int32_t drizzleclient_vio_keepalive(Vio* vio, bool set_keep_alive)
149
161
{
150
162
  int r= 0;
151
163
  uint32_t opt= 0;
165
177
 
166
178
 
167
179
bool
168
 
vio_should_retry(Vio * vio __attribute__((unused)))
 
180
drizzleclient_vio_should_retry(Vio * vio)
169
181
{
 
182
  (void)vio;
170
183
  int en = errno;
171
184
  return (en == EAGAIN || en == EINTR ||
172
185
          en == EWOULDBLOCK);
174
187
 
175
188
 
176
189
bool
177
 
vio_was_interrupted(Vio *vio __attribute__((unused)))
 
190
drizzleclient_vio_was_interrupted(Vio *vio)
178
191
{
 
192
  (void)vio;
179
193
  int en= errno;
180
194
  return (en == EAGAIN || en == EINTR ||
181
195
          en == EWOULDBLOCK || en == ETIMEDOUT);
182
196
}
183
197
 
184
198
 
185
 
int vio_close(Vio * vio)
 
199
int drizzleclient_vio_close(Vio * vio)
186
200
{
187
201
  int r=0;
188
202
 if (vio->type != VIO_CLOSED)
200
214
}
201
215
 
202
216
 
203
 
const char *vio_description(Vio * vio)
 
217
const char *drizzleclient_vio_description(Vio * vio)
204
218
{
205
219
  return vio->desc;
206
220
}
207
221
 
208
 
enum enum_vio_type vio_type(Vio* vio)
 
222
enum enum_vio_type drizzleclient_vio_type(Vio* vio)
209
223
{
210
224
  return vio->type;
211
225
}
212
226
 
213
 
int vio_fd(Vio* vio)
 
227
int drizzleclient_vio_fd(Vio* vio)
214
228
{
215
229
  return vio->sd;
216
230
}
217
231
 
218
 
bool vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen)
 
232
bool drizzleclient_vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen)
219
233
{
220
234
  int error;
221
235
  char port_buf[NI_MAXSERV];
228
242
  }
229
243
  vio->addrLen= (int)addrLen;
230
244
 
231
 
  if ((error= getnameinfo((struct sockaddr *)(&vio->remote), 
 
245
  if ((error= getnameinfo((struct sockaddr *)(&vio->remote),
232
246
                          addrLen,
233
247
                          buf, buflen,
234
248
                          port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV)))
244
258
 
245
259
/* Return 0 if there is data to be read */
246
260
 
247
 
bool vio_poll_read(Vio *vio, int32_t timeout)
 
261
bool drizzleclient_vio_poll_read(Vio *vio, int32_t timeout)
248
262
{
249
263
  struct pollfd fds;
250
264
  int res;
260
274
}
261
275
 
262
276
 
263
 
bool vio_peek_read(Vio *vio, uint32_t *bytes)
 
277
bool drizzleclient_vio_peek_read(Vio *vio, uint32_t *bytes)
264
278
{
265
279
  char buf[1024];
266
280
  ssize_t res= recv(vio->sd, &buf, sizeof(buf), MSG_PEEK);
271
285
  return false;
272
286
}
273
287
 
274
 
void vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout)
 
288
void drizzleclient_vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout)
275
289
{
276
290
  int error;
277
291
 
285
299
  error= setsockopt(vio->sd, SOL_SOCKET, is_sndtimeo ? SO_SNDTIMEO : SO_RCVTIMEO,
286
300
                    &wait_timeout,
287
301
                    (socklen_t)sizeof(struct timeval));
288
 
  if (error != 0)
 
302
  if (error == -1 && errno != ENOPROTOOPT)
289
303
  {
290
304
    perror("setsockopt");
291
305
    assert(error == 0);