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
DBUG_ENTER("vio_init");
33
DBUG_PRINT("enter", ("type: %d sd: %d flags: %d", type, sd, flags));
32
35
#ifndef HAVE_VIO_READ_BUFF
33
36
flags&= ~VIO_BUFFERED_READ;
35
memset(vio, 0, sizeof(*vio));
38
bzero((char*) vio, sizeof(*vio));
42
vio->localhost= flags & VIO_LOCALHOST;
38
43
if ((flags & VIO_BUFFERED_READ) &&
39
44
!(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
40
45
flags&= ~VIO_BUFFERED_READ;
53
58
vio->is_blocking =vio_is_blocking;
54
59
vio->timeout =vio_timeout;
59
65
/* Reset initialized VIO to use with another transport type */
61
67
void vio_reset(Vio* vio, enum enum_vio_type type,
62
int sd, uint32_t flags)
68
my_socket sd, HANDLE hPipe, uint flags)
64
free(vio->read_buffer);
65
vio_init(vio, type, sd, flags);
70
my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
71
vio_init(vio, type, sd, hPipe, flags);
69
75
/* 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)
77
Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags)
80
DBUG_ENTER("vio_new");
81
DBUG_PRINT("enter", ("sd: %d", sd));
75
82
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);
84
vio_init(vio, type, sd, 0, flags);
86
(vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"),
88
#if !defined(NO_FCNTL_NONBLOCK)
80
90
We call fcntl() to set the flags and then immediately read them back
81
91
to make sure that we and the system are in agreement on the state of
89
99
fcntl(sd, F_SETFL, 0);
90
100
vio->fcntl_mode= fcntl(sd, F_GETFL);
101
#elif defined(HAVE_SYS_IOCTL_H) /* hpux */
102
/* Non blocking sockets doesn't work good on HPUX 11.0 */
103
(void) ioctl(sd,FIOSNBIO,0);
104
vio->fcntl_mode &= ~O_NONBLOCK;
101
116
if (vio->type != VIO_CLOSED)
102
117
vio->vioclose(vio);
103
free((unsigned char*) vio->read_buffer);
104
free((unsigned char*) vio);
118
my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
119
my_free((uchar*) vio,MYF(0));