40 static int no_io_wait(
Vio *vio __attribute__((unused)),
41 enum enum_vio_io_event
event __attribute__((unused)),
42 int timeout __attribute__((unused)))
49 static my_bool has_no_data(
Vio *vio __attribute__((unused)))
58 static void vio_init(
Vio *vio,
enum enum_vio_type
type,
59 my_socket sd, uint
flags)
61 DBUG_ENTER(
"vio_init");
62 DBUG_PRINT(
"enter", (
"type: %d sd: %d flags: %d", type, sd, flags));
64 #ifndef HAVE_VIO_READ_BUFF
65 flags&= ~VIO_BUFFERED_READ;
67 memset(vio, 0,
sizeof(*vio));
70 mysql_socket_setfd(&vio->mysql_socket, sd);
71 vio->localhost= flags & VIO_LOCALHOST;
72 vio->read_timeout= vio->write_timeout= -1;
73 if ((flags & VIO_BUFFERED_READ) &&
74 !(vio->read_buffer= (
char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
75 flags&= ~VIO_BUFFERED_READ;
77 if (type == VIO_TYPE_NAMEDPIPE)
79 vio->viodelete =vio_delete;
80 vio->vioerrno =vio_errno;
81 vio->read =vio_read_pipe;
82 vio->write =vio_write_pipe;
83 vio->fastsend =vio_fastsend;
84 vio->viokeepalive =vio_keepalive;
85 vio->should_retry =vio_should_retry;
86 vio->was_timeout =vio_was_timeout;
87 vio->vioshutdown =vio_shutdown_pipe;
88 vio->peer_addr =vio_peer_addr;
89 vio->io_wait =no_io_wait;
90 vio->is_connected =vio_is_connected_pipe;
91 vio->has_data =has_no_data;
96 if (type == VIO_TYPE_SHARED_MEMORY)
98 vio->viodelete =vio_delete_shared_memory;
99 vio->vioerrno =vio_errno;
100 vio->read =vio_read_shared_memory;
101 vio->write =vio_write_shared_memory;
102 vio->fastsend =vio_fastsend;
103 vio->viokeepalive =vio_keepalive;
104 vio->should_retry =vio_should_retry;
105 vio->was_timeout =vio_was_timeout;
106 vio->vioshutdown =vio_shutdown_shared_memory;
107 vio->peer_addr =vio_peer_addr;
108 vio->io_wait =no_io_wait;
109 vio->is_connected =vio_is_connected_shared_memory;
110 vio->has_data =has_no_data;
115 if (type == VIO_TYPE_SSL)
117 vio->viodelete =vio_ssl_delete;
118 vio->vioerrno =vio_errno;
119 vio->read =vio_ssl_read;
120 vio->write =vio_ssl_write;
121 vio->fastsend =vio_fastsend;
122 vio->viokeepalive =vio_keepalive;
123 vio->should_retry =vio_should_retry;
124 vio->was_timeout =vio_was_timeout;
125 vio->vioshutdown =vio_ssl_shutdown;
126 vio->peer_addr =vio_peer_addr;
127 vio->io_wait =vio_io_wait;
128 vio->is_connected =vio_is_connected;
129 vio->has_data =vio_ssl_has_data;
130 vio->timeout =vio_socket_timeout;
134 vio->viodelete =vio_delete;
135 vio->vioerrno =vio_errno;
136 vio->read= (flags & VIO_BUFFERED_READ) ? vio_read_buff : vio_read;
137 vio->write =vio_write;
138 vio->fastsend =vio_fastsend;
139 vio->viokeepalive =vio_keepalive;
140 vio->should_retry =vio_should_retry;
141 vio->was_timeout =vio_was_timeout;
142 vio->vioshutdown =vio_shutdown;
143 vio->peer_addr =vio_peer_addr;
144 vio->io_wait =vio_io_wait;
145 vio->is_connected =vio_is_connected;
146 vio->timeout =vio_socket_timeout;
147 vio->has_data= (flags & VIO_BUFFERED_READ) ?
148 vio_buff_has_data : has_no_data;
169 my_bool vio_reset(
Vio* vio,
enum enum_vio_type type,
170 my_socket sd,
void *ssl __attribute__((unused)), uint flags)
174 DBUG_ENTER(
"vio_reset");
177 DBUG_ASSERT(vio->type == VIO_TYPE_TCPIP || vio->type == VIO_TYPE_SOCKET);
183 my_free(vio->read_buffer);
185 vio_init(vio, type, sd, flags);
188 vio->mysql_socket.
m_psi= old_vio.mysql_socket.
m_psi;
199 if (old_vio.read_timeout >= 0)
200 ret|= vio_timeout(vio, 0, old_vio.read_timeout);
202 if (old_vio.write_timeout >= 0)
203 ret|= vio_timeout(vio, 1, old_vio.write_timeout);
205 DBUG_RETURN(
test(ret));
211 Vio *mysql_socket_vio_new(
MYSQL_SOCKET mysql_socket,
enum enum_vio_type type, uint flags)
214 my_socket sd= mysql_socket_getfd(mysql_socket);
215 DBUG_ENTER(
"mysql_socket_vio_new");
216 DBUG_PRINT(
"enter", (
"sd: %d", sd));
217 if ((vio = (
Vio*) my_malloc(
sizeof(*vio),MYF(MY_WME))))
219 vio_init(vio, type, sd, flags);
220 vio->mysql_socket= mysql_socket;
227 Vio *vio_new(my_socket sd,
enum enum_vio_type type, uint flags)
231 DBUG_ENTER(
"vio_new");
232 DBUG_PRINT(
"enter", (
"sd: %d", sd));
234 mysql_socket_setfd(&mysql_socket, sd);
235 vio = mysql_socket_vio_new(mysql_socket, type, flags);
242 Vio *vio_new_win32pipe(HANDLE hPipe)
245 DBUG_ENTER(
"vio_new_handle");
246 if ((vio = (
Vio*) my_malloc(
sizeof(
Vio),MYF(MY_WME))))
248 vio_init(vio, VIO_TYPE_NAMEDPIPE, 0, VIO_LOCALHOST);
250 vio->overlapped.hEvent= CreateEvent(NULL, FALSE, FALSE, NULL);
251 if (vio->overlapped.hEvent == NULL)
257 strmov(vio->desc,
"named pipe");
263 Vio *vio_new_win32shared_memory(HANDLE handle_file_map, HANDLE handle_map,
264 HANDLE event_server_wrote, HANDLE event_server_read,
265 HANDLE event_client_wrote, HANDLE event_client_read,
266 HANDLE event_conn_closed)
269 DBUG_ENTER(
"vio_new_win32shared_memory");
270 if ((vio = (
Vio*) my_malloc(
sizeof(
Vio),MYF(MY_WME))))
272 vio_init(vio, VIO_TYPE_SHARED_MEMORY, 0, VIO_LOCALHOST);
273 vio->handle_file_map= handle_file_map;
274 vio->handle_map= handle_map;
275 vio->event_server_wrote= event_server_wrote;
276 vio->event_server_read= event_server_read;
277 vio->event_client_wrote= event_client_wrote;
278 vio->event_client_read= event_client_read;
279 vio->event_conn_closed= event_conn_closed;
280 vio->shared_memory_remain= 0;
281 vio->shared_memory_pos= handle_map;
282 strmov(vio->desc,
"shared memory");
306 int vio_timeout(
Vio *vio, uint which,
int timeout_sec)
315 if (timeout_sec > INT_MAX/1000)
318 timeout_ms= (int) (timeout_sec * 1000);
321 old_mode= vio->write_timeout < 0 && vio->read_timeout < 0;
324 vio->write_timeout= timeout_ms;
326 vio->read_timeout= timeout_ms;
329 return vio->timeout ? vio->timeout(vio, which, old_mode) : 0;
333 void vio_delete(
Vio* vio)
338 if (vio->inactive == FALSE)
339 vio->vioshutdown(vio);
340 my_free(vio->read_buffer);
352 #if defined(HAVE_YASSL)
354 #elif defined(HAVE_OPENSSL)
359 CRYPTO_cleanup_all_ex_data();