35
35
/* Ensure nobody uses vio_read_buff and vio_read simultaneously */
36
36
assert(vio->read_end == vio->read_pos);
37
errno=0; /* For linux */
38
r = read(vio->sd, buf, size);
37
r= read(vio->sd, buf, size);
95
int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode,
95
int vio_blocking(Vio * vio, bool set_blocking_mode, bool *old_mode)
100
99
*old_mode= test(!(vio->fcntl_mode & O_NONBLOCK));
102
#if !defined(NO_FCNTL_NONBLOCK)
103
101
if (vio->sd >= 0)
105
103
int old_fcntl=vio->fcntl_mode;
135
131
int vio_fastsend(Vio * vio __attribute__((unused)))
139
#if defined(IPTOS_THROUGHPUT)
141
int tos = IPTOS_THROUGHPUT;
142
r= setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos));
144
#endif /* IPTOS_THROUGHPUT */
149
r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
150
IF_WIN(const char*, void*) &nodelay,
136
r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
137
&nodelay, sizeof(nodelay));
162
int vio_keepalive(Vio* vio, my_bool set_keep_alive)
143
int32_t vio_keepalive(Vio* vio, bool set_keep_alive)
167
if (vio->type != VIO_TYPE_NAMEDPIPE)
171
r= setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
151
r= setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, sizeof(opt));
180
158
vio_should_retry(Vio * vio __attribute__((unused)))
182
160
int en = socket_errno;
230
my_bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen)
208
bool vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen)
234
strmov(buf, "127.0.0.1");
240
char port_buf[NI_MAXSERV];
241
size_socket addrLen = sizeof(vio->remote);
242
if (getpeername(vio->sd, (struct sockaddr *) (&vio->remote),
247
vio->addrLen= (int)addrLen;
249
if ((error= getnameinfo((struct sockaddr *)(&vio->remote),
252
port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV)))
257
*port= (uint16)strtol(port_buf, (char **)NULL, 10);
260
A lot of users do not have IPv6 loopback resolving to localhost
261
correctly setup. Should this exist? No. If we do not do it though
262
we will be getting a lot of support questions from users who
263
have bad setups. This code should be removed by say... 2012.
266
if (!memcmp(buf, "::ffff:127.0.0.1", sizeof("::ffff:127.0.0.1")))
267
strmov(buf, "127.0.0.1");
211
char port_buf[NI_MAXSERV];
212
size_socket addrLen = sizeof(vio->remote);
214
if (getpeername(vio->sd, (struct sockaddr *) (&vio->remote),
219
vio->addrLen= (int)addrLen;
221
if ((error= getnameinfo((struct sockaddr *)(&vio->remote),
224
port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV)))
229
*port= (uint16_t)strtol(port_buf, (char **)NULL, 10);
287
247
return res < 0 ? false : true; /* Don't return 1 on errors */
289
249
return (fds.revents & (POLLIN | POLLERR | POLLHUP) ? false : true);
296
my_bool vio_peek_read(Vio *vio, uint *bytes)
253
bool vio_peek_read(Vio *vio, uint32_t *bytes)
298
#if FIONREAD_IN_SYS_IOCTL
300
if (ioctl(vio->sd, FIONREAD, &len) < 0)
306
256
ssize_t res= recv(vio->sd, &buf, sizeof(buf), MSG_PEEK);
260
*bytes= (uint32_t)res;
314
264
void vio_timeout(Vio *vio, uint which, uint timeout)
316
#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
320
268
/* POSIX specifies time as struct timeval. */
321
269
struct timeval wait_timeout;
322
270
wait_timeout.tv_sec= timeout;
325
273
r= setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
326
274
IF_WIN(const char*, const void*)&wait_timeout,
327
275
sizeof(wait_timeout));
332
Platforms not suporting setting of socket timeout should either use
333
thr_alarm or just run without read/write timeout(s)