20
20
the file descriptior.
26
38
* Helper to fill most of the Vio* with defaults.
29
static void vio_init(Vio* vio, enum enum_vio_type type,
41
static void drizzleclient_vio_init(Vio* vio, enum enum_vio_type type,
30
42
int sd, uint32_t flags)
32
#ifndef HAVE_VIO_READ_BUFF
33
flags&= ~VIO_BUFFERED_READ;
35
44
memset(vio, 0, sizeof(*vio));
38
47
if ((flags & VIO_BUFFERED_READ) &&
39
!(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
48
!(vio->read_buffer= (char*)malloc(VIO_READ_BUFFER_SIZE)))
40
49
flags&= ~VIO_BUFFERED_READ;
42
vio->viodelete =vio_delete;
43
vio->vioerrno =vio_errno;
44
vio->read= (flags & VIO_BUFFERED_READ) ? vio_read_buff : vio_read;
45
vio->write =vio_write;
46
vio->fastsend =vio_fastsend;
47
vio->viokeepalive =vio_keepalive;
48
vio->should_retry =vio_should_retry;
49
vio->was_interrupted=vio_was_interrupted;
50
vio->vioclose =vio_close;
51
vio->peer_addr =vio_peer_addr;
52
vio->vioblocking =vio_blocking;
53
vio->is_blocking =vio_is_blocking;
54
vio->timeout =vio_timeout;
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;
59
68
/* Reset initialized VIO to use with another transport type */
61
void vio_reset(Vio* vio, enum enum_vio_type type,
70
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type,
71
int sd, uint32_t flags)
64
my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
65
vio_init(vio, type, sd, flags);
73
free(vio->read_buffer);
74
drizzleclient_vio_init(vio, type, sd, flags);
69
78
/* Open the socket or TCP/IP connection and read the fnctl() status */
71
Vio *vio_new(int sd, enum enum_vio_type type, uint flags)
80
Vio *drizzleclient_vio_new(int sd, enum enum_vio_type type, uint32_t flags)
82
Vio *vio = (Vio*) malloc(sizeof(Vio));
75
if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
77
vio_init(vio, type, sd, flags);
86
drizzleclient_vio_init(vio, type, sd, flags);
78
87
sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
80
89
We call fcntl() to set the flags and then immediately read them back