diff options
Diffstat (limited to 'vio')
-rwxr-xr-x | vio/CMakeLists.txt | 9 | ||||
-rw-r--r-- | vio/Makefile.am | 2 | ||||
-rw-r--r-- | vio/test-ssl.c | 26 | ||||
-rw-r--r-- | vio/test-sslclient.c | 6 | ||||
-rw-r--r-- | vio/test-sslserver.c | 8 | ||||
-rw-r--r-- | vio/vio.c | 68 | ||||
-rw-r--r-- | vio/vio_priv.h | 16 | ||||
-rw-r--r-- | vio/viosocket.c | 237 | ||||
-rw-r--r-- | vio/viossl.c | 26 | ||||
-rw-r--r-- | vio/viosslfactories.c | 23 | ||||
-rw-r--r-- | vio/viotest-ssl.c | 26 | ||||
-rw-r--r-- | vio/viotest-sslconnect.cc | 15 | ||||
-rw-r--r-- | vio/viotest.cc | 16 |
13 files changed, 311 insertions, 167 deletions
diff --git a/vio/CMakeLists.txt b/vio/CMakeLists.txt index e4940d54da8..164bcde7c4b 100755 --- a/vio/CMakeLists.txt +++ b/vio/CMakeLists.txt @@ -18,4 +18,11 @@ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -DSAFEMALLOC -DSAFE_MUT ADD_DEFINITIONS(-DUSE_SYMDIR) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/extra/yassl/include) -ADD_LIBRARY(vio vio.c viosocket.c viossl.c viosslfactories.c) + +SET(VIO_SOURCES vio.c viosocket.c viossl.c viosslfactories.c) + +IF(NOT SOURCE_SUBLIBS) + ADD_LIBRARY(vio ${VIO_SOURCES}) + ADD_DEPENDENCIES(vio GenError) +ENDIF(NOT SOURCE_SUBLIBS) + diff --git a/vio/Makefile.am b/vio/Makefile.am index d90eb2f0e99..27596bb2fa4 100644 --- a/vio/Makefile.am +++ b/vio/Makefile.am @@ -22,7 +22,7 @@ noinst_HEADERS = vio_priv.h libvio_a_SOURCES = vio.c viosocket.c viossl.c viosslfactories.c -EXTRA_DIST= CMakeLists.txt +EXTRA_DIST= CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/vio/test-ssl.c b/vio/test-ssl.c index 76833e25949..855dc5fbb3e 100644 --- a/vio/test-ssl.c +++ b/vio/test-ssl.c @@ -106,8 +106,8 @@ main(int argc, char** argv) child_pid = fork(); if (child_pid==-1) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("fork"); } if (child_pid==0) @@ -116,28 +116,28 @@ main(int argc, char** argv) char xbuf[100]; int r = vio_read(client_vio,xbuf, sizeof(xbuf)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[r] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); } else { const char* s = "Huhuhuh"; - int r = vio_write(server_vio,(gptr)s, strlen(s)); + int r = vio_write(server_vio,(uchar*)s, strlen(s)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("server:SSL_write"); } - my_free((gptr)server_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)server_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); } return 0; } diff --git a/vio/test-sslclient.c b/vio/test-sslclient.c index c8e14721375..e1b8461397b 100644 --- a/vio/test-sslclient.c +++ b/vio/test-sslclient.c @@ -84,13 +84,13 @@ main( int argc __attribute__((unused)), sslconnect(ssl_connector,client_vio,60L); err = vio_read(client_vio,xbuf, sizeof(xbuf)); if (err<=0) { - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[err] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); return 0; } #else /* HAVE_OPENSSL */ diff --git a/vio/test-sslserver.c b/vio/test-sslserver.c index 59456db1fd4..f55b5bae53a 100644 --- a/vio/test-sslserver.c +++ b/vio/test-sslserver.c @@ -59,9 +59,9 @@ do_ssl_stuff( TH_ARGS* args) /* ----------------------------------------------- */ /* TCP connection is ready. Do server side SSL. */ - err = write(server_vio->sd,(gptr)s, strlen(s)); + err = write(server_vio->sd,(uchar*)s, strlen(s)); sslaccept(args->ssl_acceptor,server_vio,60L); - err = server_vio->write(server_vio,(gptr)s, strlen(s)); + err = server_vio->write(server_vio,(uchar*)s, strlen(s)); DBUG_VOID_RETURN; } @@ -139,12 +139,12 @@ main(int argc __attribute__((unused)), char** argv) #if 0 if (err<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); fatal_error("server:SSL_write"); } #endif /* 0 */ - my_free((gptr)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); return 0; } #else /* HAVE_OPENSSL */ diff --git a/vio/vio.c b/vio/vio.c index 84b3e26fa52..486fe63da05 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. + Use is subject to license terms. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Note that we can't have assertion on file descriptors; The reason for @@ -43,7 +44,7 @@ static void vio_init(Vio* vio, enum enum_vio_type type, if ((flags & VIO_BUFFERED_READ) && !(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME)))) flags&= ~VIO_BUFFERED_READ; -#ifdef __WIN__ +#ifdef _WIN32 if (type == VIO_TYPE_NAMEDPIPE) { vio->viodelete =vio_delete; @@ -59,9 +60,14 @@ static void vio_init(Vio* vio, enum enum_vio_type type, vio->in_addr =vio_in_addr; vio->vioblocking =vio_blocking; vio->is_blocking =vio_is_blocking; - vio->timeout =vio_ignore_timeout; + + vio->timeout=vio_win32_timeout; + /* Set default timeout */ + vio->read_timeout_ms= INFINITE; + vio->write_timeout_ms= INFINITE; + vio->pipe_overlapped.hEvent= CreateEvent(NULL, TRUE, FALSE, NULL); + DBUG_VOID_RETURN; } - else /* default is VIO_TYPE_TCPIP */ #endif #ifdef HAVE_SMEM if (type == VIO_TYPE_SHARED_MEMORY) @@ -79,9 +85,14 @@ static void vio_init(Vio* vio, enum enum_vio_type type, vio->in_addr =vio_in_addr; vio->vioblocking =vio_blocking; vio->is_blocking =vio_is_blocking; - vio->timeout =vio_ignore_timeout; + + /* Currently, shared memory is on Windows only, hence the below is ok*/ + vio->timeout= vio_win32_timeout; + /* Set default timeout */ + vio->read_timeout_ms= INFINITE; + vio->write_timeout_ms= INFINITE; + DBUG_VOID_RETURN; } - else #endif #ifdef HAVE_OPENSSL if (type == VIO_TYPE_SSL) @@ -100,25 +111,23 @@ static void vio_init(Vio* vio, enum enum_vio_type type, vio->vioblocking =vio_ssl_blocking; vio->is_blocking =vio_is_blocking; vio->timeout =vio_timeout; + DBUG_VOID_RETURN; } - else /* default is VIO_TYPE_TCPIP */ #endif /* HAVE_OPENSSL */ - { - vio->viodelete =vio_delete; - vio->vioerrno =vio_errno; - vio->read= (flags & VIO_BUFFERED_READ) ? vio_read_buff : vio_read; - vio->write =vio_write; - vio->fastsend =vio_fastsend; - vio->viokeepalive =vio_keepalive; - vio->should_retry =vio_should_retry; - vio->was_interrupted=vio_was_interrupted; - vio->vioclose =vio_close; - vio->peer_addr =vio_peer_addr; - vio->in_addr =vio_in_addr; - vio->vioblocking =vio_blocking; - vio->is_blocking =vio_is_blocking; - vio->timeout =vio_timeout; - } + vio->viodelete =vio_delete; + vio->vioerrno =vio_errno; + vio->read= (flags & VIO_BUFFERED_READ) ? vio_read_buff : vio_read; + vio->write =vio_write; + vio->fastsend =vio_fastsend; + vio->viokeepalive =vio_keepalive; + vio->should_retry =vio_should_retry; + vio->was_interrupted=vio_was_interrupted; + vio->vioclose =vio_close; + vio->peer_addr =vio_peer_addr; + vio->in_addr =vio_in_addr; + vio->vioblocking =vio_blocking; + vio->is_blocking =vio_is_blocking; + vio->timeout =vio_timeout; DBUG_VOID_RETURN; } @@ -146,7 +155,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags) sprintf(vio->desc, (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"), vio->sd); -#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(__WIN__) #if !defined(NO_FCNTL_NONBLOCK) /* We call fcntl() to set the flags and then immediately read them back @@ -165,7 +174,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, uint flags) (void) ioctl(sd,FIOSNBIO,0); vio->fcntl_mode &= ~O_NONBLOCK; #endif -#else /* !defined(__WIN__) && !defined(__EMX__) */ +#else /* !defined(__WIN__) */ { /* set to blocking mode by default */ ulong arg=0, r; @@ -193,7 +202,7 @@ Vio *vio_new_win32pipe(HANDLE hPipe) } #ifdef HAVE_SMEM -Vio *vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, HANDLE handle_map, +Vio *vio_new_win32shared_memory(HANDLE handle_file_map, HANDLE handle_map, HANDLE event_server_wrote, HANDLE event_server_read, HANDLE event_client_wrote, HANDLE event_client_read, HANDLE event_conn_closed) @@ -212,7 +221,6 @@ Vio *vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, HANDLE handle_m vio->event_conn_closed= event_conn_closed; vio->shared_memory_remain= 0; vio->shared_memory_pos= handle_map; - vio->net= net; strmov(vio->desc, "shared memory"); } DBUG_RETURN(vio); @@ -228,8 +236,8 @@ void vio_delete(Vio* vio) if (vio->type != VIO_CLOSED) vio->vioclose(vio); - my_free((gptr) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR)); - my_free((gptr) vio,MYF(0)); + my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR)); + my_free((uchar*) vio,MYF(0)); } diff --git a/vio/vio_priv.h b/vio/vio_priv.h index 9036952d575..91fb641d0d3 100644 --- a/vio/vio_priv.h +++ b/vio/vio_priv.h @@ -1,4 +1,6 @@ -/* Copyright (C) 2003 MySQL AB +/* + Copyright (c) 2003, 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc. + Use is subject to license terms. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,7 +13,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* Structures and functions private to the vio package */ @@ -22,14 +25,17 @@ #include <m_string.h> #include <violite.h> -void vio_ignore_timeout(Vio *vio, uint which, uint timeout); +#ifdef _WIN32 +void vio_win32_timeout(Vio *vio, uint which, uint timeout); +#endif + void vio_timeout(Vio *vio,uint which, uint timeout); #ifdef HAVE_OPENSSL #include "my_net.h" /* needed because of struct in_addr */ -int vio_ssl_read(Vio *vio,gptr buf, int size); -int vio_ssl_write(Vio *vio,const gptr buf,int size); +size_t vio_ssl_read(Vio *vio,uchar* buf, size_t size); +size_t vio_ssl_write(Vio *vio,const uchar* buf, size_t size); /* When the workday is over... */ int vio_ssl_close(Vio *vio); diff --git a/vio/viosocket.c b/vio/viosocket.c index 8b48e215858..9d7133f8064 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. +/* + Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. Use is subject to license terms. This program is free software; you can redistribute it and/or modify @@ -12,7 +13,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* Note that we can't have assertion on file descriptors; The reason for @@ -29,11 +31,12 @@ int vio_errno(Vio *vio __attribute__((unused))) } -int vio_read(Vio * vio, gptr buf, int size) +size_t vio_read(Vio * vio, uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_read"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ DBUG_ASSERT(vio->read_end == vio->read_pos); @@ -44,12 +47,12 @@ int vio_read(Vio * vio, gptr buf, int size) r = read(vio->sd, buf, size); #endif /* __WIN__ */ #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) { DBUG_PRINT("vio_error", ("Got error %d during read",errno)); } #endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%ld", (long) r)); DBUG_RETURN(r); } @@ -59,16 +62,17 @@ int vio_read(Vio * vio, gptr buf, int size) reduce number of syscalls. */ -int vio_read_buff(Vio *vio, gptr buf, int size) +size_t vio_read_buff(Vio *vio, uchar* buf, size_t size) { - int rc; + size_t rc; #define VIO_UNBUFFERED_READ_MIN_SIZE 2048 DBUG_ENTER("vio_read_buff"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); if (vio->read_pos < vio->read_end) { - rc= min((int) (vio->read_end - vio->read_pos), size); + rc= min((size_t) (vio->read_end - vio->read_pos), size); memcpy(buf, vio->read_pos, rc); vio->read_pos+= rc; /* @@ -79,8 +83,8 @@ int vio_read_buff(Vio *vio, gptr buf, int size) } else if (size < VIO_UNBUFFERED_READ_MIN_SIZE) { - rc= vio_read(vio, vio->read_buffer, VIO_READ_BUFFER_SIZE); - if (rc > 0) + rc= vio_read(vio, (uchar*) vio->read_buffer, VIO_READ_BUFFER_SIZE); + if (rc != 0 && rc != (size_t) -1) { if (rc > size) { @@ -98,23 +102,24 @@ int vio_read_buff(Vio *vio, gptr buf, int size) } -int vio_write(Vio * vio, const gptr buf, int size) +size_t vio_write(Vio * vio, const uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_write"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); #ifdef __WIN__ r = send(vio->sd, buf, size,0); #else r = write(vio->sd, buf, size); #endif /* __WIN__ */ #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) { DBUG_PRINT("vio_error", ("Got error on write: %d",socket_errno)); } #endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } @@ -128,7 +133,7 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, DBUG_PRINT("enter", ("set_blocking_mode: %d old_mode: %d", (int) set_blocking_mode, (int) *old_mode)); -#if !defined(__WIN__) && !defined(__EMX__) +#if !defined(__WIN__) #if !defined(NO_FCNTL_NONBLOCK) if (vio->sd >= 0) { @@ -150,10 +155,8 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, #else r= set_blocking_mode ? 0 : 1; #endif /* !defined(NO_FCNTL_NONBLOCK) */ -#else /* !defined(__WIN__) && !defined(__EMX__) */ -#ifndef __EMX__ +#else /* !defined(__WIN__) */ if (vio->type != VIO_TYPE_NAMEDPIPE && vio->type != VIO_TYPE_SHARED_MEMORY) -#endif { ulong arg; int old_fcntl=vio->fcntl_mode; @@ -170,11 +173,9 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, if (old_fcntl != vio->fcntl_mode) r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg); } -#ifndef __EMX__ else r= test(!(vio->fcntl_mode & O_NONBLOCK)) != set_blocking_mode; -#endif /* __EMX__ */ -#endif /* !defined(__WIN__) && !defined(__EMX__) */ +#endif /* !defined(__WIN__) */ DBUG_PRINT("exit", ("%d", r)); DBUG_RETURN(r); } @@ -195,12 +196,12 @@ int vio_fastsend(Vio * vio __attribute__((unused))) int r=0; DBUG_ENTER("vio_fastsend"); -#if defined(IPTOS_THROUGHPUT) && !defined(__EMX__) +#if defined(IPTOS_THROUGHPUT) { int tos = IPTOS_THROUGHPUT; r= setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos)); } -#endif /* IPTOS_THROUGHPUT && !__EMX__ */ +#endif /* IPTOS_THROUGHPUT */ if (!r) { #ifdef __WIN__ @@ -263,19 +264,13 @@ int vio_close(Vio * vio) { int r=0; DBUG_ENTER("vio_close"); -#ifdef __WIN__ - if (vio->type == VIO_TYPE_NAMEDPIPE) - { -#if defined(__NT__) && defined(MYSQL_SERVER) - CancelIo(vio->hPipe); - DisconnectNamedPipe(vio->hPipe); -#endif - r=CloseHandle(vio->hPipe); - } - else -#endif /* __WIN__ */ + if (vio->type != VIO_CLOSED) { + DBUG_ASSERT(vio->type == VIO_TYPE_TCPIP || + vio->type == VIO_TYPE_SOCKET || + vio->type == VIO_TYPE_SSL); + DBUG_ASSERT(vio->sd >= 0); if (shutdown(vio->sd, SHUT_RDWR)) r= -1; @@ -419,42 +414,106 @@ void vio_timeout(Vio *vio, uint which, uint timeout) #ifdef __WIN__ -int vio_read_pipe(Vio * vio, gptr buf, int size) + +/* + Finish pending IO on pipe. Honor wait timeout +*/ +static size_t pipe_complete_io(Vio* vio, char* buf, size_t size, DWORD timeout_ms) { DWORD length; - DBUG_ENTER("vio_read_pipe"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, buf, size)); + DWORD ret; + + DBUG_ENTER("pipe_complete_io"); + + ret= WaitForSingleObject(vio->pipe_overlapped.hEvent, timeout_ms); + /* + WaitForSingleObjects will normally return WAIT_OBJECT_O (success, IO completed) + or WAIT_TIMEOUT. + */ + if(ret != WAIT_OBJECT_0) + { + CancelIo(vio->hPipe); + DBUG_PRINT("error",("WaitForSingleObject() returned %d", ret)); + DBUG_RETURN((size_t)-1); + } - if (!ReadFile(vio->hPipe, buf, size, &length, NULL)) - DBUG_RETURN(-1); + if (!GetOverlappedResult(vio->hPipe,&(vio->pipe_overlapped),&length, FALSE)) + { + DBUG_PRINT("error",("GetOverlappedResult() returned last error %d", + GetLastError())); + DBUG_RETURN((size_t)-1); + } - DBUG_PRINT("exit", ("%d", length)); DBUG_RETURN(length); } -int vio_write_pipe(Vio * vio, const gptr buf, int size) +size_t vio_read_pipe(Vio * vio, uchar *buf, size_t size) { - DWORD length; + DWORD bytes_read; + size_t retval; + DBUG_ENTER("vio_read_pipe"); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); + + if (ReadFile(vio->hPipe, buf, (DWORD)size, &bytes_read, + &(vio->pipe_overlapped))) + { + retval= bytes_read; + } + else + { + if (GetLastError() != ERROR_IO_PENDING) + { + DBUG_PRINT("error",("ReadFile() returned last error %d", + GetLastError())); + DBUG_RETURN((size_t)-1); + } + retval= pipe_complete_io(vio, buf, size,vio->read_timeout_ms); + } + + DBUG_PRINT("exit", ("%lld", (longlong)retval)); + DBUG_RETURN(retval); +} + + +size_t vio_write_pipe(Vio * vio, const uchar* buf, size_t size) +{ + DWORD bytes_written; + size_t retval; DBUG_ENTER("vio_write_pipe"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); - if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL)) - DBUG_RETURN(-1); + if (WriteFile(vio->hPipe, buf, (DWORD)size, &bytes_written, + &(vio->pipe_overlapped))) + { + retval= bytes_written; + } + else + { + if (GetLastError() != ERROR_IO_PENDING) + { + DBUG_PRINT("vio_error",("WriteFile() returned last error %d", + GetLastError())); + DBUG_RETURN((size_t)-1); + } + retval= pipe_complete_io(vio, (char *)buf, size, vio->write_timeout_ms); + } - DBUG_PRINT("exit", ("%d", length)); - DBUG_RETURN(length); + DBUG_PRINT("exit", ("%lld", (longlong)retval)); + DBUG_RETURN(retval); } + int vio_close_pipe(Vio * vio) { int r; DBUG_ENTER("vio_close_pipe"); -#if defined(__NT__) && defined(MYSQL_SERVER) - CancelIo(vio->hPipe); + + CloseHandle(vio->pipe_overlapped.hEvent); DisconnectNamedPipe(vio->hPipe); -#endif - r=CloseHandle(vio->hPipe); + r= CloseHandle(vio->hPipe); if (r) { DBUG_PRINT("vio_error", ("close() failed, error: %d",GetLastError())); @@ -466,24 +525,38 @@ int vio_close_pipe(Vio * vio) } -void vio_ignore_timeout(Vio *vio __attribute__((unused)), - uint which __attribute__((unused)), - uint timeout __attribute__((unused))) +void vio_win32_timeout(Vio *vio, uint which , uint timeout_sec) { + DWORD timeout_ms; + /* + Windows is measuring timeouts in milliseconds. Check for possible int + overflow. + */ + if (timeout_sec > UINT_MAX/1000) + timeout_ms= INFINITE; + else + timeout_ms= timeout_sec * 1000; + + /* which == 1 means "write", which == 0 means "read".*/ + if(which) + vio->write_timeout_ms= timeout_ms; + else + vio->read_timeout_ms= timeout_ms; } #ifdef HAVE_SMEM -int vio_read_shared_memory(Vio * vio, gptr buf, int size) +size_t vio_read_shared_memory(Vio * vio, uchar* buf, size_t size) { - int length; - int remain_local; + size_t length; + size_t remain_local; char *current_postion; HANDLE events[2]; DBUG_ENTER("vio_read_shared_memory"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); remain_local = size; current_postion=buf; @@ -498,11 +571,12 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size) /* WaitForMultipleObjects can return next values: WAIT_OBJECT_0+0 - event from vio->event_server_wrote - WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read anything + WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read + anything WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail. We can't read anything */ if (WaitForMultipleObjects(array_elements(events), events, FALSE, - vio->net->read_timeout*1000) != WAIT_OBJECT_0) + vio->read_timeout_ms) != WAIT_OBJECT_0) { DBUG_RETURN(-1); }; @@ -527,25 +601,28 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size) remain_local-=length; if (!vio->shared_memory_remain) - if (!SetEvent(vio->event_client_read)) DBUG_RETURN(-1); + { + if (!SetEvent(vio->event_client_read)) + DBUG_RETURN(-1); + } } while (remain_local); length = size; - DBUG_PRINT("exit", ("%d", length)); + DBUG_PRINT("exit", ("%lu", (ulong) length)); DBUG_RETURN(length); } -int vio_write_shared_memory(Vio * vio, const gptr buf, int size) +size_t vio_write_shared_memory(Vio * vio, const uchar* buf, size_t size) { - int length; - uint remain; - int sz; - char *current_postion; - HANDLE pos, events[2]; + size_t length, remain, sz; + HANDLE pos; + const uchar *current_postion; + HANDLE events[2]; DBUG_ENTER("vio_write_shared_memory"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, + size)); remain = size; current_postion = buf; @@ -556,23 +633,25 @@ int vio_write_shared_memory(Vio * vio, const gptr buf, int size) while (remain != 0) { if (WaitForMultipleObjects(array_elements(events), events, FALSE, - vio->net->write_timeout*1000) != WAIT_OBJECT_0) + vio->write_timeout_ms) != WAIT_OBJECT_0) { - DBUG_RETURN(-1); - }; + DBUG_RETURN((size_t) -1); + } - sz = remain > shared_memory_buffer_length ? shared_memory_buffer_length: remain; + sz= (remain > shared_memory_buffer_length ? shared_memory_buffer_length : + remain); int4store(vio->handle_map,sz); pos = vio->handle_map + 4; memcpy(pos,current_postion,sz); remain-=sz; current_postion+=sz; - if (!SetEvent(vio->event_client_wrote)) DBUG_RETURN(-1); + if (!SetEvent(vio->event_client_wrote)) + DBUG_RETURN((size_t) -1); } length = size; - DBUG_PRINT("exit", ("%d", length)); + DBUG_PRINT("exit", ("%lu", (ulong) length)); DBUG_RETURN(length); } diff --git a/vio/viossl.c b/vio/viossl.c index eea274cf92d..0651fd8b7a3 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -82,35 +82,36 @@ report_errors(SSL* ssl) } -int vio_ssl_read(Vio *vio, gptr buf, int size) +size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_ssl_read"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d ssl: 0x%lx", - vio->sd, (long) buf, size, (long) vio->ssl_arg)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", + vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); r= SSL_read((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); #endif - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } -int vio_ssl_write(Vio *vio, const gptr buf, int size) +size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_ssl_write"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, + (long) buf, (uint) size)); r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); #endif - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } @@ -133,8 +134,7 @@ int vio_ssl_close(Vio *vio) */ SSL_set_quiet_shutdown(ssl, 1); - switch ((r= SSL_shutdown(ssl))) - { + switch ((r= SSL_shutdown(ssl))) { case 1: /* Shutdown successful */ break; diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index 81b8c676002..3c0c2f3a7ec 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. + Copyright (c) 2000-2008 MySQL AB, 2009 Sun Microsystems, Inc. Use is subject to license terms. This program is free software; you can redistribute it and/or modify @@ -20,9 +20,8 @@ #ifdef HAVE_OPENSSL -static bool ssl_algorithms_added = FALSE; -static bool ssl_error_strings_loaded= FALSE; -static int verify_depth = 0; +static my_bool ssl_algorithms_added = FALSE; +static my_bool ssl_error_strings_loaded= FALSE; static unsigned char dh512_p[]= { @@ -208,6 +207,14 @@ new_VioSSLFd(const char *key_file, const char *cert_file, DH *dh; struct st_VioSSLFd *ssl_fd; DBUG_ENTER("new_VioSSLFd"); + DBUG_PRINT("enter", + ("key_file: '%s' cert_file: '%s' ca_file: '%s' ca_path: '%s' " + "cipher: '%s'", + key_file ? key_file : "NULL", + cert_file ? cert_file : "NULL", + ca_file ? ca_file : "NULL", + ca_path ? ca_path : "NULL", + cipher ? cipher : "NULL")); check_ssl_init(); @@ -307,7 +314,7 @@ new_VioSSLConnectorFd(const char *key_file, const char *cert_file, /************************ VioSSLAcceptorFd **********************************/ -struct st_VioSSLFd* +struct st_VioSSLFd * new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher, enum enum_ssl_init_error* error) @@ -336,4 +343,10 @@ new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, return ssl_fd; } + +void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd) +{ + SSL_CTX_free(fd->ssl_context); + my_free((uchar*) fd, MYF(0)); +} #endif /* HAVE_OPENSSL */ diff --git a/vio/viotest-ssl.c b/vio/viotest-ssl.c index 81d119ff207..b8abbac4ed6 100644 --- a/vio/viotest-ssl.c +++ b/vio/viotest-ssl.c @@ -106,8 +106,8 @@ int main(int argc, char **argv) child_pid = fork(); if (child_pid==-1) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("fork"); } if (child_pid==0) @@ -116,29 +116,29 @@ int main(int argc, char **argv) char xbuf[100]; int r = vio_ssl_read(client_vio,xbuf, sizeof(xbuf)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[r] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); sleep(1); } else { const char* s = "Huhuhuh"; - int r = vio_ssl_write(server_vio,(gptr)s, strlen(s)); + int r = vio_ssl_write(server_vio,(uchar*)s, strlen(s)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("server:SSL_write"); } - my_free((gptr)server_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)server_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); sleep(1); } return 0; diff --git a/vio/viotest-sslconnect.cc b/vio/viotest-sslconnect.cc index 89e1a6e7dfe..18e558159fa 100644 --- a/vio/viotest-sslconnect.cc +++ b/vio/viotest-sslconnect.cc @@ -1,3 +1,18 @@ +/* Copyright (c) 2000 MySQL AB + Use is subject to license terms. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* ** Virtual I/O library diff --git a/vio/viotest.cc b/vio/viotest.cc index 490a9ca6694..b1c11a85cf2 100644 --- a/vio/viotest.cc +++ b/vio/viotest.cc @@ -1,3 +1,19 @@ +/* Copyright (c) 2000 MySQL AB + Use is subject to license terms. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + /* ** Virtual I/O library ** Written by Andrei Errapart <andreie@no.spam.ee> |