29
29
static void vio_init(Vio* vio, enum enum_vio_type type,
30
int sd, uint32_t flags)
30
my_socket sd, HANDLE hPipe, uint flags)
32
32
#ifndef HAVE_VIO_READ_BUFF
33
33
flags&= ~VIO_BUFFERED_READ;
35
memset(vio, 0, sizeof(*vio));
35
bzero((char*) vio, sizeof(*vio));
39
vio->localhost= flags & VIO_LOCALHOST;
38
40
if ((flags & VIO_BUFFERED_READ) &&
39
41
!(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
40
42
flags&= ~VIO_BUFFERED_READ;
59
61
/* Reset initialized VIO to use with another transport type */
61
63
void vio_reset(Vio* vio, enum enum_vio_type type,
62
int sd, uint32_t flags)
64
my_socket sd, HANDLE hPipe, uint flags)
64
free(vio->read_buffer);
65
vio_init(vio, type, sd, flags);
66
my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
67
vio_init(vio, type, sd, hPipe, flags);
69
71
/* Open the socket or TCP/IP connection and read the fnctl() status */
71
Vio *vio_new(int sd, enum enum_vio_type type, uint32_t flags)
73
Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags)
75
77
if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
77
vio_init(vio, type, sd, flags);
78
sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
79
vio_init(vio, type, sd, 0, flags);
81
(vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"),
83
#if !defined(NO_FCNTL_NONBLOCK)
80
85
We call fcntl() to set the flags and then immediately read them back
81
86
to make sure that we and the system are in agreement on the state of
89
94
fcntl(sd, F_SETFL, 0);
90
95
vio->fcntl_mode= fcntl(sd, F_GETFL);
96
#elif defined(HAVE_SYS_IOCTL_H) /* hpux */
97
/* Non blocking sockets doesn't work good on HPUX 11.0 */
98
(void) ioctl(sd,FIOSNBIO,0);
99
vio->fcntl_mode &= ~O_NONBLOCK;
101
111
if (vio->type != VIO_CLOSED)
102
112
vio->vioclose(vio);
103
free((unsigned char*) vio->read_buffer);
104
free((unsigned char*) vio);
113
my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
114
my_free((uchar*) vio,MYF(0));