summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
Diffstat (limited to 'vio')
-rwxr-xr-xvio/CMakeLists.txt6
-rw-r--r--vio/Makefile.am2
-rw-r--r--vio/viosocket.c61
3 files changed, 57 insertions, 12 deletions
diff --git a/vio/CMakeLists.txt b/vio/CMakeLists.txt
new file mode 100755
index 00000000000..a3cbb304289
--- /dev/null
+++ b/vio/CMakeLists.txt
@@ -0,0 +1,6 @@
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -DSAFEMALLOC -DSAFE_MUTEX")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -DSAFEMALLOC -DSAFE_MUTEX")
+
+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)
diff --git a/vio/Makefile.am b/vio/Makefile.am
index e89191d57cd..cb70501046e 100644
--- a/vio/Makefile.am
+++ b/vio/Makefile.am
@@ -38,6 +38,6 @@ test_sslclient_LDADD= @CLIENT_EXTRA_LDFLAGS@ ../dbug/libdbug.a libvio.a \
../mysys/libmysys.a ../strings/libmystrings.a \
$(openssl_libs) $(yassl_libs)
libvio_a_SOURCES= vio.c viosocket.c viossl.c viosslfactories.c
-
+EXTRA_DIST= CMakeLists.txt
# Don't update the files from bitkeeper
%::SCCS/s.%
diff --git a/vio/viosocket.c b/vio/viosocket.c
index 87fb1e107eb..21b3dae906a 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -276,7 +276,7 @@ int vio_close(Vio * vio)
if (vio->type != VIO_CLOSED)
{
DBUG_ASSERT(vio->sd >= 0);
- if (shutdown(vio->sd,2))
+ if (shutdown(vio->sd, SHUT_RDWR))
r= -1;
if (closesocket(vio->sd))
r= -1;
@@ -379,16 +379,30 @@ my_bool vio_poll_read(Vio *vio,uint timeout)
}
-void vio_timeout(Vio *vio __attribute__((unused)),
- uint which __attribute__((unused)),
- uint timeout __attribute__((unused)))
+void vio_timeout(Vio *vio, uint which, uint timeout)
{
+/* TODO: some action should be taken if socket timeouts are not supported. */
+#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
+
#ifdef __WIN__
- ulong wait_timeout= (ulong) timeout * 1000;
- (void) setsockopt(vio->sd, SOL_SOCKET,
- which ? SO_SNDTIMEO : SO_RCVTIMEO, (char*) &wait_timeout,
- sizeof(wait_timeout));
-#endif /* __WIN__ */
+
+ /* Windows expects time in milliseconds as int. */
+ int wait_timeout= (int) timeout * 1000;
+
+#else /* ! __WIN__ */
+
+ /* POSIX specifies time as struct timeval. */
+ struct timeval wait_timeout;
+ wait_timeout.tv_sec= timeout;
+ wait_timeout.tv_usec= 0;
+
+#endif /* ! __WIN__ */
+
+ /* TODO: return value should be checked. */
+ (void) setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
+ (char*) &wait_timeout, sizeof(wait_timeout));
+
+#endif /* defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) */
}
@@ -545,9 +559,13 @@ int vio_write_shared_memory(Vio * vio, const gptr buf, int size)
}
+/**
+ Close shared memory and DBUG_PRINT any errors that happen on closing.
+ @return Zero if all closing functions succeed, and nonzero otherwise.
+*/
int vio_close_shared_memory(Vio * vio)
{
- int r;
+ int error_count= 0;
DBUG_ENTER("vio_close_shared_memory");
if (vio->type != VIO_CLOSED)
{
@@ -561,23 +579,44 @@ int vio_close_shared_memory(Vio * vio)
result if they are success.
*/
if (UnmapViewOfFile(vio->handle_map) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("UnmapViewOfFile() failed"));
+ }
if (CloseHandle(vio->event_server_wrote) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->esw) failed"));
+ }
if (CloseHandle(vio->event_server_read) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->esr) failed"));
+ }
if (CloseHandle(vio->event_client_wrote) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecw) failed"));
+ }
if (CloseHandle(vio->event_client_read) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecr) failed"));
+ }
if (CloseHandle(vio->handle_file_map) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->hfm) failed"));
+ }
if (CloseHandle(vio->event_conn_closed) == 0)
+ {
+ error_count++;
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecc) failed"));
+ }
}
vio->type= VIO_CLOSED;
vio->sd= -1;
- DBUG_RETURN(!r);
+ DBUG_RETURN(error_count);
}
#endif /* HAVE_SMEM */
#endif /* __WIN__ */