1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Note that we can't have assertion on file descriptors; The reason for
18
this is that during mysql shutdown, another thread can close a file
19
we are working on. In this case we should just return read errors from
38
* Helper to fill most of the Vio* with defaults.
41
static void drizzleclient_vio_init(Vio* vio, enum enum_vio_type type,
42
int sd, uint32_t flags)
44
memset(vio, 0, sizeof(*vio));
47
if ((flags & VIO_BUFFERED_READ) &&
48
!(vio->read_buffer= (char*)malloc(VIO_READ_BUFFER_SIZE)))
49
flags&= ~VIO_BUFFERED_READ;
51
vio->viodelete =drizzleclient_vio_delete;
52
vio->vioerrno =drizzleclient_vio_errno;
53
vio->read= (flags & VIO_BUFFERED_READ) ? drizzleclient_vio_read_buff : drizzleclient_vio_read;
54
vio->write =drizzleclient_vio_write;
55
vio->fastsend =drizzleclient_vio_fastsend;
56
vio->viokeepalive =drizzleclient_vio_keepalive;
57
vio->should_retry =drizzleclient_vio_should_retry;
58
vio->was_interrupted=drizzleclient_vio_was_interrupted;
59
vio->vioclose =drizzleclient_vio_close;
60
vio->peer_addr =drizzleclient_vio_peer_addr;
61
vio->vioblocking =drizzleclient_vio_blocking;
62
vio->is_blocking =drizzleclient_vio_is_blocking;
63
vio->timeout =drizzleclient_vio_timeout;
68
/* Reset initialized VIO to use with another transport type */
70
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type,
71
int sd, uint32_t flags)
73
free(vio->read_buffer);
74
drizzleclient_vio_init(vio, type, sd, flags);
78
/* Open the socket or TCP/IP connection and read the fnctl() status */
80
Vio *drizzleclient_vio_new(int sd, enum enum_vio_type type, uint32_t flags)
82
Vio *vio = (Vio*) malloc(sizeof(Vio));
86
drizzleclient_vio_init(vio, type, sd, flags);
87
sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
89
We call fcntl() to set the flags and then immediately read them back
90
to make sure that we and the system are in agreement on the state of
93
An example of why we need to do this is FreeBSD (and apparently some
94
other BSD-derived systems, like Mac OS X), where the system sometimes
95
reports that the socket is set for non-blocking when it really will
98
fcntl(sd, F_SETFL, 0);
99
vio->fcntl_mode= fcntl(sd, F_GETFL);
105
void drizzleclient_vio_delete(Vio* vio)
108
return; /* It must be safe to delete null pointers. */
110
if (vio->type != VIO_CLOSED)
112
free((unsigned char*) vio->read_buffer);
113
free((unsigned char*) vio);
118
Cleanup memory allocated by vio or the
119
components below it when application finish
122
void drizzleclient_vio_end(void)