summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorunknown <wax@mysql.com>2002-11-15 00:16:30 +0500
committerunknown <wax@mysql.com>2002-11-15 00:16:30 +0500
commit64dd949c419898111c673eed4efadf32acd3e435 (patch)
treef80131afae1725b283113608c4f38e9e43ace61b /vio
parentccf7226c2759bf6549c2cdd615ef55e95318520b (diff)
downloadmariadb-git-64dd949c419898111c673eed4efadf32acd3e435.tar.gz
Add shared memory protocol and option --protocol
client/client_priv.h: Add OPT_MYSQL_PROTOCOL and OPT_SHARED_MEMORY_BASE_NAME include/config-win.h: Add shared memory protocol include/errmsg.h: Add error codes of shared memory protocol include/my_sys.h: Delete TYPELIB, moved to typelib.h include/mysql.h: Add shared memory protocol include/violite.h: Add shared memory protocol libmysql/errmsg.c: Add texts of errors of shared memory protocol sql/mysqld.cc: Add shared memory protocol and option --shared-memory, correct option --named-pipe sql/set_var.cc: Add shared memory protocol variables vio/vio.c: Add shared memory protocol vio/viosocket.c: Add shared memory protocol BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'vio')
-rw-r--r--vio/vio.c78
-rw-r--r--vio/viosocket.c184
2 files changed, 232 insertions, 30 deletions
diff --git a/vio/vio.c b/vio/vio.c
index bed380c6cd9..b1eb86fc948 100644
--- a/vio/vio.c
+++ b/vio/vio.c
@@ -45,7 +45,43 @@ void vio_reset(Vio* vio, enum enum_vio_type type,
vio->sd = sd;
vio->hPipe = hPipe;
vio->localhost= localhost;
-#ifdef HAVE_VIO
+#ifdef HAVE_VIO
+#ifdef __WIN__
+ if (type == VIO_TYPE_NAMEDPIPE)
+ {
+ vio->viodelete =vio_delete;
+ vio->vioerrno =vio_errno;
+ vio->read =vio_read_pipe;
+ vio->write =vio_write_pipe;
+ vio->fastsend =vio_fastsend;
+ vio->viokeepalive =vio_keepalive;
+ vio->should_retry =vio_should_retry;
+ vio->vioclose =vio_close_pipe;
+ vio->peer_addr =vio_peer_addr;
+ vio->in_addr =vio_in_addr;
+ vio->vioblocking =vio_blocking;
+ vio->is_blocking =vio_is_blocking;
+ }
+ else /* default is VIO_TYPE_TCPIP */
+#endif
+#ifdef HAVE_SMEM
+ if (type == VIO_TYPE_SHARED_MEMORY)
+ {
+ vio->viodelete =vio_delete;
+ vio->vioerrno =vio_errno;
+ vio->read =vio_read_shared_memory;
+ vio->write =vio_write_shared_memory;
+ vio->fastsend =vio_fastsend;
+ vio->viokeepalive =vio_keepalive;
+ vio->should_retry =vio_should_retry;
+ vio->vioclose =vio_close_shared_memory;
+ vio->peer_addr =vio_peer_addr;
+ vio->in_addr =vio_in_addr;
+ vio->vioblocking =vio_blocking;
+ vio->is_blocking =vio_is_blocking;
+ }
+ else
+#endif
#ifdef HAVE_OPENSSL
if (type == VIO_TYPE_SSL)
{
@@ -131,4 +167,44 @@ Vio *vio_new_win32pipe(HANDLE hPipe)
DBUG_RETURN(vio);
}
+#ifdef HAVE_SMEM
+Vio *vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, HANDLE handle_map,
+ HANDLE event_server_wrote, HANDLE event_server_read,
+ HANDLE event_client_wrote, HANDLE event_client_read)
+{
+ Vio *vio;
+ DBUG_ENTER("vio_new_win32shared_memory");
+ if ((vio = (Vio*) my_malloc(sizeof(Vio),MYF(MY_WME))))
+ {
+ vio_reset(vio, VIO_TYPE_SHARED_MEMORY, 0, 0, TRUE);
+ vio->handle_file_map = handle_file_map;
+ vio->handle_map = handle_map;
+ vio->event_server_wrote = event_server_wrote;
+ vio->event_server_read = event_server_read;
+ vio->event_client_wrote = event_client_wrote;
+ vio->event_client_read = event_client_read;
+ vio->shared_memory_remain = 0;
+ vio->shared_memory_pos = handle_map;
+ vio->net = net;
+ strmov(vio->desc, "shared memory");
+ }
+ DBUG_RETURN(vio);
+}
+#endif
#endif
+
+void vio_delete(Vio* vio)
+{
+ /* It must be safe to delete null pointers. */
+ /* This matches the semantics of C++'s delete operator. */
+ if (vio)
+ {
+ if (vio->type != VIO_CLOSED)
+#ifdef HAVE_VIO /*WAX*/
+ vio->vioclose(vio);
+#else
+ vio_close(vio);
+#endif
+ my_free((gptr) vio,MYF(0));
+ }
+}
diff --git a/vio/viosocket.c b/vio/viosocket.c
index f69eebd413a..76056704ec2 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -35,18 +35,6 @@
#define HANDLE void *
#endif
-void vio_delete(Vio* vio)
-{
- /* It must be safe to delete null pointers. */
- /* This matches the semantics of C++'s delete operator. */
- if (vio)
- {
- if (vio->type != VIO_CLOSED)
- vio_close(vio);
- my_free((gptr) vio,MYF(0));
- }
-}
-
int vio_errno(Vio *vio __attribute__((unused)))
{
return socket_errno; /* On Win32 this mapped to WSAGetLastError() */
@@ -58,14 +46,8 @@ int vio_read(Vio * vio, gptr buf, int size)
int r;
DBUG_ENTER("vio_read");
DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
+
#ifdef __WIN__
- if (vio->type == VIO_TYPE_NAMEDPIPE)
- {
- DWORD length;
- if (!ReadFile(vio->hPipe, buf, size, &length, NULL))
- DBUG_RETURN(-1);
- DBUG_RETURN(length);
- }
r = recv(vio->sd, buf, size,0);
#else
errno=0; /* For linux */
@@ -87,15 +69,8 @@ int vio_write(Vio * vio, const gptr buf, int size)
int r;
DBUG_ENTER("vio_write");
DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
-#if defined( __WIN__)
- if ( vio->type == VIO_TYPE_NAMEDPIPE)
- {
- DWORD length;
- if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL))
- DBUG_RETURN(-1);
- DBUG_RETURN(length);
- }
- r = send(vio->sd, buf, size, 0);
+#ifdef __WIN__
+ r = send(vio->sd, buf, size,0);
#else
r = write(vio->sd, buf, size);
#endif /* __WIN__ */
@@ -109,7 +84,6 @@ int vio_write(Vio * vio, const gptr buf, int size)
DBUG_RETURN(r);
}
-
int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode,
my_bool *old_mode)
{
@@ -332,3 +306,155 @@ my_bool vio_poll_read(Vio *vio,uint timeout)
DBUG_RETURN(fds.revents & POLLIN ? 0 : 1);
#endif
}
+
+#ifdef __WIN__
+int vio_read_pipe(Vio * vio, gptr buf, int size)
+{
+ DWORD length;
+ DBUG_ENTER("vio_read_pipe");
+ DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
+
+ if (!ReadFile(vio->hPipe, buf, size, &length, NULL))
+ DBUG_RETURN(-1);
+
+ DBUG_PRINT("exit", ("%d", length));
+ DBUG_RETURN(length);
+}
+
+
+int vio_write_pipe(Vio * vio, const gptr buf, int size)
+{
+ DWORD length;
+ DBUG_ENTER("vio_write_pipe");
+ DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
+
+ if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL))
+ DBUG_RETURN(-1);
+
+ DBUG_PRINT("exit", ("%d", length));
+ DBUG_RETURN(length);
+}
+
+int vio_close_pipe(Vio * vio)
+{
+ int r;
+ DBUG_ENTER("vio_close_pipe");
+#if defined(__NT__) && defined(MYSQL_SERVER)
+ CancelIo(vio->hPipe);
+ DisconnectNamedPipe(vio->hPipe);
+#endif
+ r=CloseHandle(vio->hPipe);
+ if (r)
+ {
+ DBUG_PRINT("vio_error", ("close() failed, error: %d",GetLastError()));
+ /* FIXME: error handling (not critical for MySQL) */
+ }
+ vio->type= VIO_CLOSED;
+ vio->sd= -1;
+ DBUG_RETURN(r);
+}
+
+#ifdef HAVE_SMEM
+
+int vio_read_shared_memory(Vio * vio, gptr buf, int size)
+{
+ int length;
+ int remain_local;
+ char *current_postion;
+
+ DBUG_ENTER("vio_read_shared_memory");
+ DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
+
+ remain_local = size;
+ current_postion=buf;
+ do
+ {
+ if (vio->shared_memory_remain == 0)
+ {
+ if (WaitForSingleObject(vio->event_server_wrote,vio->net->read_timeout*1000) != WAIT_OBJECT_0)
+ {
+ DBUG_RETURN(-1);
+ };
+ vio->shared_memory_pos = vio->handle_map;
+ vio->shared_memory_remain = uint4korr((ulong*)vio->shared_memory_pos);
+ vio->shared_memory_pos+=4;
+ }
+
+ length = size;
+
+ if (vio->shared_memory_remain < length)
+ length = vio->shared_memory_remain;
+ if (length > remain_local)
+ length = remain_local;
+
+ memcpy(current_postion,vio->shared_memory_pos,length);
+
+ vio->shared_memory_remain-=length;
+ vio->shared_memory_pos+=length;
+ current_postion+=length;
+ remain_local-=length;
+
+ if (!vio->shared_memory_remain)
+ if (!SetEvent(vio->event_client_read)) DBUG_RETURN(-1);
+ } while (remain_local);
+ length = size;
+
+ DBUG_PRINT("exit", ("%d", length));
+ DBUG_RETURN(length);
+}
+
+
+int vio_write_shared_memory(Vio * vio, const gptr buf, int size)
+{
+ int length;
+ uint remain;
+ HANDLE pos;
+ int sz;
+ char *current_postion;
+
+ DBUG_ENTER("vio_write_shared_memory");
+ DBUG_PRINT("enter", ("sd=%d, buf=%p, size=%d", vio->sd, buf, size));
+
+ remain = size;
+ current_postion = buf;
+ while (remain != 0)
+ {
+ if (WaitForSingleObject(vio->event_server_read,vio->net->write_timeout*1000) != WAIT_OBJECT_0)
+ {
+ DBUG_RETURN(-1);
+ };
+
+ 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);
+ }
+ length = size;
+
+ DBUG_PRINT("exit", ("%d", length));
+ DBUG_RETURN(length);
+}
+
+
+int vio_close_shared_memory(Vio * vio)
+{
+ int r;
+ DBUG_ENTER("vio_close_shared_memory");
+ r=UnmapViewOfFile(vio->handle_map) || CloseHandle(vio->event_server_wrote) ||
+ CloseHandle(vio->event_server_read) || CloseHandle(vio->event_client_wrote) ||
+ CloseHandle(vio->event_client_read) || CloseHandle(vio->handle_file_map);
+ if (r)
+ {
+ DBUG_PRINT("vio_error", ("close() failed, error: %d",r));
+ /* FIXME: error handling (not critical for MySQL) */
+ }
+ vio->type= VIO_CLOSED;
+ vio->sd= -1;
+ DBUG_RETURN(r);
+}
+#endif
+#endif