From 20d04c924b824de637e18750687dccbb28eb650c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 May 2001 17:18:25 +0300 Subject: Support for VIO library Makefile.am: Added vio include/mysql_com.h: Removed ancient defines from Vio++ times include/violite.h: Added vio libmysql/Makefile.shared: Removed sqlobject line with violite.lo libmysql/libmysql.c: Openssl stuff & sons sql/Makefile.am: Added vio sql/mini_client.cc: Added vio sql/mysqld.cc: Added vio sql/net_serv.cc: Added vio sql/sql_parse.cc: Added vio vio/Makefile.am: Removed C++ stuff vio/vio.c: st_vio -> Vio vio/viosocket.c: st_vio -> Vio vio/viossl.c: st_vio -> Vio vio/viosslfactories.c: vio.h-> violite.h --- BUILD/compile-pentium-debug-openssl | 13 ++ Makefile.am | 2 +- include/mysql_com.h | 7 - include/violite.h | 170 +++++++++++++++-- libmysql/Makefile.shared | 3 - libmysql/libmysql.c | 26 +-- sql/Makefile.am | 8 +- sql/mini_client.cc | 14 +- sql/mysqld.cc | 3 +- sql/net_serv.cc | 1 - sql/sql_parse.cc | 6 +- vio/Makefile.am | 16 +- vio/vio.c | 21 ++- vio/viosocket.c | 352 ++++++++++++++++++++++++++++++++++++ vio/viossl.c | 35 ++-- vio/viosslfactories.c | 3 +- vio/viotcpip.c | 351 ----------------------------------- 17 files changed, 583 insertions(+), 448 deletions(-) create mode 100755 BUILD/compile-pentium-debug-openssl create mode 100644 vio/viosocket.c delete mode 100644 vio/viotcpip.c diff --git a/BUILD/compile-pentium-debug-openssl b/BUILD/compile-pentium-debug-openssl new file mode 100755 index 00000000000..aa120e3175a --- /dev/null +++ b/BUILD/compile-pentium-debug-openssl @@ -0,0 +1,13 @@ +#! /bin/sh + +path=`dirname $0` +. "$path/SETUP.sh" + +extra_flags="$pentium_cflags $debug_cflags" +c_warnings="$c_warnings $debug_extra_warnings" +cxx_warnings="$cxx_warnings $debug_extra_warnings" +extra_configs="$pentium_configs $debug_configs" + +extra_configs="$extra_configs --with-debug=full --with-vio --with-openssl" + +. "$path/FINISH.sh" diff --git a/Makefile.am b/Makefile.am index 7343f617449..d6bfb156d29 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ TAR = gtar EXTRA_DIST = INSTALL-SOURCE README \ COPYING COPYING.LIB MIRRORS SUBDIRS = include @docs_dirs@ @readline_dir@ \ - @thread_dirs@ @pstack_dirs@ @sql_client_dirs@ \ + @thread_dirs@ @pstack_dirs@ vio @sql_client_dirs@ \ @sql_server_dirs@ @libmysqld_dirs@ scripts tests man \ @bench_dirs@ support-files @fs_dirs@ diff --git a/include/mysql_com.h b/include/mysql_com.h index 874430910ef..6c2357f8c77 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -100,15 +100,8 @@ enum enum_server_command {COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY, #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ -#ifndef Vio_defined -#define Vio_defined -#ifdef HAVE_VIO -class Vio; /* Fill Vio class in C++ */ -#else struct st_vio; /* Only C */ typedef struct st_vio Vio; -#endif -#endif typedef struct st_net { Vio* vio; diff --git a/include/violite.h b/include/violite.h index 7b14dae3610..a88b5c0db51 100644 --- a/include/violite.h +++ b/include/violite.h @@ -25,9 +25,6 @@ #include "my_net.h" /* needed because of struct in_addr */ -#ifdef HAVE_VIO -#include /* Full VIO interface */ -#else /* Simple vio interface in C; The functions are implemented in violite.c */ @@ -35,14 +32,8 @@ extern "C" { #endif /* __cplusplus */ -#ifndef Vio_defined -#define Vio_defined -struct st_vio; /* Only C */ -typedef struct st_vio Vio; -#endif - enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, - VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL}; + VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL}; Vio* vio_new(my_socket sd, enum enum_vio_type type, @@ -87,7 +78,7 @@ my_bool vio_should_retry( Vio* vio); /* * When the workday is over... */ -int vio_close( Vio* vio); +int vio_close(Vio* vio); /* * Short text description of the socket for those, who are curious.. */ @@ -97,15 +88,15 @@ const char* vio_description( Vio* vio); enum enum_vio_type vio_type(Vio* vio); /* Return last error number */ -int vio_errno(Vio *vio); +int vio_errno(Vio*vio); /* Get socket number */ -my_socket vio_fd(Vio *vio); +my_socket vio_fd(Vio*vio); /* * Remote peer's address and name in text form. */ -my_bool vio_peer_addr(Vio * vio, char *buf); +my_bool vio_peer_addr(Vio* vio, char *buf); /* Remotes in_addr */ @@ -117,5 +108,154 @@ my_bool vio_poll_read(Vio *vio,uint timeout); #ifdef __cplusplus } #endif -#endif /* HAVE_VIO */ #endif /* vio_violite_h_ */ +#ifdef HAVE_VIO +#ifndef DONT_MAP_VIO +#define vio_delete(vio) (vio)->viodelete(vio) +#define vio_errno(vio) (vio)->vioerrno(vio) +#define vio_read(vio, buf, size) (vio)->read(vio,buf,size) +#define vio_write(vio, buf, size) (vio)->write(vio, buf, size) +#define vio_blocking(vio, set_blocking_mode) (vio)->vioblocking(vio, set_blocking_mode) +#define vio_is_blocking(vio) (vio)->is_blocking(vio) +#define vio_fastsend(vio) (vio)->fastsend(vio) +#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive) +#define vio_should_retry(vio) (vio)->should_retry(vio) +#define vio_close(vio) ((vio)->vioclose)(vio) +#define vio_peer_addr(vio, buf) (vio)->peer_addr(vio, buf) +#define vio_in_addr(vio, in) (vio)->in_addr(vio, in) +#define vio_poll_read(vio,timeout) (vio)->poll_read(vio,timeout) +#endif /* !DONT_MAP_VIO */ +#endif /* HAVE_VIO */ + + +#ifdef HAVE_OPENSSL +#include +#include +#include +#include +#include +#include "my_net.h" /* needed because of struct in_addr */ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void vio_ssl_delete(Vio* vio); + +#ifdef EMBEDDED_LIBRARY +void vio_reset(Vio *vio); +#endif + +int vio_ssl_read(Vio* vio,gptr buf, int size); +int vio_ssl_write(Vio* vio,const gptr buf,int size); +int vio_ssl_blocking(Vio* vio,my_bool onoff); +my_bool vio_ssl_is_blocking(Vio* vio); + +/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible. */ + int vio_ssl_fastsend(Vio* vio); +/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible. */ +int vio_ssl_keepalive(Vio* vio, my_bool onoff); +/* Whenever we should retry the last read/write operation. */ +my_bool vio_ssl_should_retry(Vio* vio); +/* When the workday is over... */ +int vio_ssl_close(Vio* vio); +/* Return last error number */ +int vio_ssl_errno(Vio *vio); +my_bool vio_ssl_peer_addr(Vio* vio, char *buf); +void vio_ssl_in_addr(Vio *vio, struct in_addr *in); + +/* Return 1 if there is data to be read */ +my_bool vio_ssl_poll_read(Vio *vio,uint timeout); + +#ifdef HAVE_OPENSSL + +/* Single copy for server */ +struct st_VioSSLAcceptorFd +{ + SSL_CTX* ssl_context_; + SSL_METHOD* ssl_method_; + struct st_VioSSLAcceptorFd* session_id_context_; + enum { + state_connect = 1, + state_accept = 2 + }; + BIO* bio_; + char *ssl_cip_; + char desc_[100]; + Vio* sd_; + + /* function pointers which are only once for SSL server + Vio*(*sslaccept)(struct st_VioSSLAcceptorFd*,Vio*); */ +}; + +/* One copy for client */ +struct st_VioSSLConnectorFd +{ + BIO* bio_; + gptr ssl_; + SSL_CTX* ssl_context_; + SSL_METHOD* ssl_method_; + /* function pointers which are only once for SSL client */ +}; +Vio *sslaccept(struct st_VioSSLAcceptorFd*, Vio*); +Vio *sslconnect(struct st_VioSSLConnectorFd*, Vio*); + +#else /* HAVE_OPENSSL */ +/* This dummy is required to maintain proper size of st_mysql in mysql.h */ +struct st_VioSSLConnectorFd {}; +#endif /* HAVE_OPENSSL */ +struct st_VioSSLConnectorFd *new_VioSSLConnectorFd( + const char* key_file,const char* cert_file,const char* ca_file,const char* ca_path); +struct st_VioSSLAcceptorFd *new_VioSSLAcceptorFd( + const char* key_file,const char* cert_file,const char* ca_file,const char* ca_path); +Vio* new_VioSSL(struct st_VioSSLAcceptorFd* fd, Vio* sd,int state); +//static int +//init_bio_(struct st_VioSSLAcceptorFd* fd, Vio* sd, int state, int bio_flags); +//void report_errors(); + +#ifdef __cplusplus +} +#endif +#endif /* HAVE_OPENSSL */ + +#ifndef __WIN__ +#define HANDLE void * +#endif + +/* This structure is for every connection on both sides */ +struct st_vio +{ + my_socket sd; /* my_socket - real or imaginary */ + HANDLE hPipe; + my_bool localhost; /* Are we from localhost? */ + int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ + struct sockaddr_in local; /* Local internet address */ + struct sockaddr_in remote; /* Remote internet address */ + enum enum_vio_type type; /* Type of connection */ + char desc[30]; /* String description */ +#ifdef HAVE_VIO + /* function pointers. They are similar for socket/SSL/whatever */ + void (*viodelete)(Vio*); + int(*vioerrno)(Vio*); + int(*read)(Vio*, gptr, int); + int(*write)(Vio*, gptr, int); + int(*vioblocking)(Vio*, my_bool); + my_bool(*is_blocking)(Vio*); + int(*viokeepalive)(Vio*, my_bool); + int(*fastsend)(Vio*); + my_bool(*peer_addr)(Vio*, gptr); + void(*in_addr)(Vio*, struct in_addr*); + my_bool(*should_retry)(Vio*); + int(*vioclose)(Vio*); + my_bool(*poll_read)(Vio*,uint); + +#ifdef HAVE_OPENSSL + BIO* bio_; + SSL* ssl_; + my_bool open_; +#endif /* HAVE_OPENSSL */ +#endif /* HAVE_VIO */ +}; + + diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index 7b220e12346..e1ae1fa1ea6 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -34,9 +34,6 @@ LTCHARSET_OBJS= ${CHARSET_OBJS:.o=.lo} target_sources = libmysql.c net.c password.c \ get_password.c errmsg.c -#quick easy dirty hack to make it work after Tonu's changes -#In my opinion, violite.c really belongs into mysys - Sasha -sqlobjects = violite.lo mystringsobjects = strmov.lo strxmov.lo strnmov.lo strmake.lo strend.lo \ strnlen.lo strfill.lo is_prefix.lo \ int2str.lo str2int.lo strinstr.lo strcont.lo \ diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 9221812ea65..d9e7b28d468 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1070,13 +1070,15 @@ mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, mysql->options.ssl_cert = cert==0 ? 0 : my_strdup(cert,MYF(0)); mysql->options.ssl_ca = ca==0 ? 0 : my_strdup(ca,MYF(0)); mysql->options.ssl_capath = capath==0 ? 0 : my_strdup(capath,MYF(0)); - mysql->options.use_ssl = true; - mysql->connector_fd = new_VioSSLConnectorFd(key, cert, ca, capath); + mysql->options.use_ssl = TRUE; + mysql->connector_fd = (gptr)new_VioSSLConnectorFd(key, cert, ca, capath); + DBUG_PRINT("info",("mysql_ssl_set, context: %p",((struct st_VioSSLConnectorFd *)(mysql->connector_fd))->ssl_context_)); + return 0; } /************************************************************************** -**************************************************************************/ +************************************************************************** char * STDCALL mysql_ssl_cipher(MYSQL *mysql) @@ -1085,10 +1087,10 @@ mysql_ssl_cipher(MYSQL *mysql) } -/************************************************************************** +************************************************************************** ** Free strings in the SSL structure and clear 'use_ssl' flag. ** NB! Errors are not reported until you do mysql_real_connect. -**************************************************************************/ +************************************************************************** int STDCALL mysql_ssl_clear(MYSQL *mysql) @@ -1105,7 +1107,7 @@ mysql_ssl_clear(MYSQL *mysql) mysql->connector_fd->delete(); mysql->connector_fd = 0; return 0; -} +}*/ #endif /* HAVE_OPENSSL */ /************************************************************************** @@ -1496,11 +1498,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, goto error; /* Do the SSL layering. */ DBUG_PRINT("info", ("IO layer change in progress...")); - VioSSLConnectorFd* connector_fd = (VioSSLConnectorFd*) - (mysql->connector_fd); - VioSocket* vio_socket = (VioSocket*)(mysql->net.vio); - VioSSL* vio_ssl = connector_fd->connect(vio_socket); - mysql->net.vio = (NetVio*)(vio_ssl); + DBUG_PRINT("info", ("IO context %p",((struct st_VioSSLConnectorFd*)mysql->connector_fd)->ssl_context_)); + mysql->net.vio = sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd),mysql->net.vio); + DBUG_PRINT("info", ("IO layer change done!")); } #endif /* HAVE_OPENSSL */ @@ -1680,8 +1680,8 @@ mysql_close(MYSQL *mysql) bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->net.vio = 0; #ifdef HAVE_OPENSSL - ((VioConnectorFd*)(mysql->connector_fd))->delete(); - mysql->connector_fd = 0; +/* ((VioConnectorFd*)(mysql->connector_fd))->delete(); + mysql->connector_fd = 0;*/ #endif /* HAVE_OPENSSL */ if (mysql->free_me) my_free((gptr) mysql,MYF(0)); diff --git a/sql/Makefile.am b/sql/Makefile.am index c4ed5c05cd3..f4ff799b49b 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -39,8 +39,8 @@ LDADD = ../isam/libnisam.a \ ../mysys/libmysys.a \ ../dbug/libdbug.a \ ../regex/libregex.a \ - ../strings/libmystrings.a - #../vio/libvio.a + ../strings/libmystrings.a \ + ../vio/libvio.a mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \ @bdb_libs@ @innodb_libs@ @pstack_libs@ \ @@ -64,7 +64,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ thr_malloc.cc item_create.cc \ field.cc key.cc sql_class.cc sql_list.cc \ - net_serv.cc violite.c net_pkg.cc lock.cc my_lock.c \ + net_serv.cc net_pkg.cc lock.cc my_lock.c \ sql_string.cc sql_manager.cc sql_map.cc \ mysqld.cc password.c hash_filo.cc hostname.cc \ convert.cc sql_parse.cc sql_yacc.yy \ @@ -86,7 +86,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ md5.c stacktrace.c gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS) -mysqlbinlog_SOURCES = mysqlbinlog.cc mini_client.cc net_serv.cc violite.c \ +mysqlbinlog_SOURCES = mysqlbinlog.cc mini_client.cc net_serv.cc \ mini_client_errors.c password.c mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) $(mysqld_LDADD) diff --git a/sql/mini_client.cc b/sql/mini_client.cc index b99e63a59d7..28119cc33fd 100644 --- a/sql/mini_client.cc +++ b/sql/mini_client.cc @@ -28,6 +28,7 @@ #include #endif #include +#include #include #include #include @@ -37,7 +38,6 @@ #include "mysql_version.h" #include "mysqld_error.h" #include "errmsg.h" -#include extern "C" { // Because of SCO 3.2V4.2 #include @@ -748,18 +748,18 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, #ifdef HAVE_OPENSSL /* Oops.. are we careful enough to not send ANY information */ /* without encryption? */ - if (client_flag & CLIENT_SSL) +/* if (client_flag & CLIENT_SSL) { if (my_net_write(net,buff,(uint) (2)) || net_flush(net)) - goto error; + goto error;*/ /* Do the SSL layering. */ - DBUG_PRINT("info", ("IO layer change in progress...")); + /* DBUG_PRINT("info", ("IO layer change in progress...")); VioSSLConnectorFd* connector_fd = (VioSSLConnectorFd*) (mysql->connector_fd); VioSocket* vio_socket = (VioSocket*)(mysql->net.vio); VioSSL* vio_ssl = connector_fd->connect(vio_socket); mysql->net.vio = (NetVio*)(vio_ssl); - } + }*/ #endif /* HAVE_OPENSSL */ int3store(buff+2,max_allowed_packet); @@ -829,8 +829,8 @@ mc_mysql_close(MYSQL *mysql) bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->net.vio = 0; #ifdef HAVE_OPENSSL - ((VioConnectorFd*)(mysql->connector_fd))->delete(); - mysql->connector_fd = 0; +/* ((VioConnectorFd*)(mysql->connector_fd))->delete(); + mysql->connector_fd = 0;*/ #endif /* HAVE_OPENSSL */ if (mysql->free_me) my_free((gptr) mysql,MYF(0)); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f25174896ac..7371262f035 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -34,7 +34,6 @@ #include #include #include -#include "vio.h" #ifndef DBUG_OFF #define ONE_THREAD @@ -244,7 +243,7 @@ static char *opt_ssl_key = 0; static char *opt_ssl_cert = 0; static char *opt_ssl_ca = 0; static char *opt_ssl_capath = 0; -static struct st_VioSSLAcceptorFd * ssl_acceptor_fd = 0; +struct st_VioSSLAcceptorFd * ssl_acceptor_fd = 0; #endif /* HAVE_OPENSSL */ diff --git a/sql/net_serv.cc b/sql/net_serv.cc index a5600dffa4c..f03d8f31760 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -39,7 +39,6 @@ #include #include #include -#include #include extern "C" { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7742df4a2bf..656fea7a955 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -59,7 +59,7 @@ const char *command_name[]={ bool volatile abort_slave = 0; #ifdef HAVE_OPENSSL -extern VioSSLAcceptorFd* ssl_acceptor_fd; +extern struct st_VioSSLAcceptorFd * ssl_acceptor_fd; #endif /* HAVE_OPENSSL */ #ifdef __WIN__ @@ -423,9 +423,7 @@ check_connections(THD *thd) DBUG_PRINT("info", ("Agreed to change IO layer to SSL") ); /* Do the SSL layering. */ DBUG_PRINT("info", ("IO layer change in progress...")); - VioSocket* vio_socket = my_reinterpret_cast(VioSocket*)(net->vio); - VioSSL* vio_ssl = ssl_acceptor_fd->accept(vio_socket); - net->vio = my_reinterpret_cast(NetVio*) (vio_ssl); + net->vio = sslaccept(ssl_acceptor_fd, net->vio); DBUG_PRINT("info", ("Reading user information over SSL layer")); if ((pkt_len=my_net_read(net)) == packet_error || pkt_len < NORMAL_HANDSHAKE_SIZE) diff --git a/vio/Makefile.am b/vio/Makefile.am index 9bb8691eee6..c1a69b26058 100644 --- a/vio/Makefile.am +++ b/vio/Makefile.am @@ -14,20 +14,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -INCLUDES = -I$(srcdir)/../include -I../include \ - @OPENSSL_INCLUDES@ -LDADD = libvio.la -pkglib_LTLIBRARIES = libvio.la +INCLUDES = -I$(srcdir)/../include -I../include $(openssl_includes) +LDADD = libvio.a $(openssl_libs) +pkglib_LIBRARIES = libvio.a noinst_PROGRAMS = noinst_HEADERS = -libvio_la_SOURCES = \ - Vio.cc VioAcceptorFd.cc \ - VioConnectorFd.cc VioFd.cc \ - VioHandle.cc VioSSL.cc \ - VioSSLFactoriesFd.cc VioSocket.cc \ - auto.cc hostnamexx.cc \ - vdbug.cc version.cc \ - vmem.cc violitexx.cc +libvio_a_SOURCES = vio.c viosocket.c viossl.c viosslfactories.c OMIT_DEPENDENCIES = pthread.h stdio.h __stdio.h stdlib.h __stdlib.h math.h\ __math.h time.h __time.h unistd.h __unistd.h types.h \ diff --git a/vio/vio.c b/vio/vio.c index 9775c002737..689a01f4475 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -23,10 +23,11 @@ #define DONT_MAP_VIO #include +#include +#include #include #include -#include #include #include #include @@ -58,14 +59,14 @@ /* - * Helper to fill most of the st_vio* with defaults. + * Helper to fill most of the Vio* with defaults. */ -void vio_reset(st_vio* vio, enum enum_vio_type type, +void vio_reset(Vio* vio, enum enum_vio_type type, my_socket sd, HANDLE hPipe, my_bool localhost) { - bzero((char*) vio, sizeof(st_vio)); + bzero((char*) vio, sizeof(Vio)); vio->type = type; vio->sd = sd; vio->hPipe = hPipe; @@ -102,12 +103,12 @@ if(type == VIO_TYPE_SSL){ /* Open the socket or TCP/IP connection and read the fnctl() status */ -st_vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) +Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) { - st_vio *vio; + Vio *vio; DBUG_ENTER("vio_new"); DBUG_PRINT("enter", ("sd=%d", sd)); - if ((vio = (st_vio*) my_malloc(sizeof(*vio),MYF(MY_WME)))) + if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME)))) { vio_reset(vio, type, sd, 0, localhost); sprintf(vio->desc, @@ -134,11 +135,11 @@ st_vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) #ifdef __WIN__ -st_vio *vio_new_win32pipe(HANDLE hPipe) +Vio *vio_new_win32pipe(HANDLE hPipe) { - st_vio *vio; + Vio *vio; DBUG_ENTER("vio_new_handle"); - if ((vio = (st_vio*) my_malloc(sizeof(st_vio),MYF(MY_WME)))) + if ((vio = (Vio*) my_malloc(sizeof(Vio),MYF(MY_WME)))) { vio_reset(vio, VIO_TYPE_NAMEDPIPE, 0, hPipe, TRUE); strmov(vio->desc, "named pipe"); diff --git a/vio/viosocket.c b/vio/viosocket.c new file mode 100644 index 00000000000..16260f92596 --- /dev/null +++ b/vio/viosocket.c @@ -0,0 +1,352 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* + Note that we can't have assertion on file descriptors; The reason for + this is that during mysql shutdown, another thread can close a file + we are working on. In this case we should just return read errors from + the file descriptior. +*/ + +#define DONT_MAP_VIO +#include +#include + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_POLL +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + +#if defined(__EMX__) +#define ioctlsocket ioctl +#endif /* defined(__EMX__) */ + +#if defined(MSDOS) || defined(__WIN__) +#ifdef __WIN__ +#undef errno +#undef EINTR +#undef EAGAIN +#define errno WSAGetLastError() +#define EINTR WSAEINTR +#define EAGAIN WSAEINPROGRESS +#endif /* __WIN__ */ +#define O_NONBLOCK 1 /* For emulation of fcntl() */ +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK EAGAIN +#endif + +#ifndef __WIN__ +#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 errno; /* On Win32 this mapped to WSAGetLastError() */ +} + + +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 */ + r = read(vio->sd, buf, size); +#endif /* __WIN__ */ +#ifndef DBUG_OFF + if (r < 0) + { + DBUG_PRINT("error", ("Got error %d during read",errno)); + } +#endif /* DBUG_OFF */ + DBUG_PRINT("exit", ("%d", r)); + DBUG_RETURN(r); +} + + +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)); +#ifdef __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); +#else + r = write(vio->sd, buf, size); +#endif /* __WIN__ */ +#ifndef DBUG_OFF + if (r < 0) + { + DBUG_PRINT("error", ("Got error on write: %d",errno)); + } +#endif /* DBUG_OFF */ + DBUG_PRINT("exit", ("%d", r)); + DBUG_RETURN(r); +} + + +int vio_blocking(Vio * vio, my_bool set_blocking_mode) +{ + int r=0; + DBUG_ENTER("vio_blocking"); + DBUG_PRINT("enter", ("set_blocking_mode: %d", (int) set_blocking_mode)); + +#if !defined(___WIN__) && !defined(__EMX__) +#if !defined(NO_FCNTL_NONBLOCK) + + if (vio->sd >= 0) + { + int old_fcntl=vio->fcntl_mode; + if (set_blocking_mode) + vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */ + else + vio->fcntl_mode |= O_NONBLOCK; /* set bit */ + if (old_fcntl != vio->fcntl_mode) + r = fcntl(vio->sd, F_SETFL, vio->fcntl_mode); + } +#endif /* !defined(NO_FCNTL_NONBLOCK) */ +#else /* !defined(__WIN__) && !defined(__EMX__) */ +#ifndef __EMX__ + if (vio->type != VIO_TYPE_NAMEDPIPE) +#endif + { + ulong arg; + int old_fcntl=vio->fcntl_mode; + if (set_blocking_mode) + { + arg = 0; + vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */ + } + else + { + arg = 1; + vio->fcntl_mode |= O_NONBLOCK; /* set bit */ + } + if (old_fcntl != vio->fcntl_mode) + r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg)); + } +#endif /* !defined(__WIN__) && !defined(__EMX__) */ + DBUG_RETURN(r); +} + +my_bool +vio_is_blocking(Vio * vio) +{ + my_bool r; + DBUG_ENTER("vio_is_blocking"); + r = !(vio->fcntl_mode & O_NONBLOCK); + DBUG_PRINT("exit", ("%d", (int) r)); + DBUG_RETURN(r); +} + + +int vio_fastsend(Vio * vio __attribute__((unused))) +{ + int r=0; + DBUG_ENTER("vio_fastsend"); + +#ifdef IPTOS_THROUGHPUT + { +#ifndef __EMX__ + int tos = IPTOS_THROUGHPUT; + if (!setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos))) +#endif /* !__EMX__ */ + { + int nodelay = 1; + if (setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, (void *) &nodelay, + sizeof(nodelay))) { + DBUG_PRINT("warning", + ("Couldn't set socket option for fast send")); + r= -1; + } + } + } +#endif /* IPTOS_THROUGHPUT */ + DBUG_PRINT("exit", ("%d", r)); + DBUG_RETURN(r); +} + +int vio_keepalive(Vio* vio, my_bool set_keep_alive) +{ + int r=0; + uint opt = 0; + DBUG_ENTER("vio_keepalive"); + DBUG_PRINT("enter", ("sd=%d, set_keep_alive=%d", vio->sd, (int) + set_keep_alive)); + if (vio->type != VIO_TYPE_NAMEDPIPE) + { + if (set_keep_alive) + opt = 1; + r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, + sizeof(opt)); + } + DBUG_RETURN(r); +} + + +my_bool +vio_should_retry(Vio * vio __attribute__((unused))) +{ + int en = errno; + return en == EAGAIN || en == EINTR || en == EWOULDBLOCK; +} + + +int vio_close(Vio * vio) +{ + int r; + 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 if (vio->type != VIO_CLOSED) +#endif /* __WIN__ */ + { + r=0; + if (shutdown(vio->sd,2)) + r= -1; + if (closesocket(vio->sd)) + r= -1; + } + if (r) + { + DBUG_PRINT("error", ("close() failed, error: %d",errno)); + /* FIXME: error handling (not critical for MySQL) */ + } + vio->type= VIO_CLOSED; + vio->sd= -1; + DBUG_RETURN(r); +} + + +const char *vio_description(Vio * vio) +{ + return vio->desc; +} + +enum enum_vio_type vio_type(Vio* vio) +{ + return vio->type; +} + +my_socket vio_fd(Vio* vio) +{ + return vio->sd; +} + + +my_bool vio_peer_addr(Vio * vio, char *buf) +{ + DBUG_ENTER("vio_peer_addr"); + DBUG_PRINT("enter", ("sd=%d", vio->sd)); + if (vio->localhost) + { + strmov(buf,"127.0.0.1"); + } + else + { + size_socket addrLen = sizeof(struct sockaddr); + if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)), + &addrLen) != 0) + { + DBUG_PRINT("exit", ("getpeername, error: %d", errno)); + DBUG_RETURN(1); + } + /* FIXME */ +/* my_inet_ntoa(vio->remote.sin_addr,buf); */ + } + DBUG_PRINT("exit", ("addr=%s", buf)); + DBUG_RETURN(0); +} + + +void vio_in_addr(Vio *vio, struct in_addr *in) +{ + DBUG_ENTER("vio_in_addr"); + if (vio->localhost) + bzero((char*) in, sizeof(*in)); /* This should never be executed */ + else + *in=vio->remote.sin_addr; + DBUG_VOID_RETURN; +} + + +/* Return 0 if there is data to be read */ + +my_bool vio_poll_read(Vio *vio,uint timeout) +{ +#ifndef HAVE_POLL + return 0; +#else + struct pollfd fds; + int res; + DBUG_ENTER("vio_poll"); + fds.fd=vio->sd; + fds.events=POLLIN; + fds.revents=0; + if ((res=poll(&fds,1,(int) timeout*1000)) <= 0) + { + DBUG_RETURN(res < 0 ? 0 : 1); /* Don't return 1 on errors */ + } + DBUG_RETURN(fds.revents & POLLIN ? 0 : 1); +#endif +} + diff --git a/vio/viossl.c b/vio/viossl.c index 5600bc1a800..696d7d54a29 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -23,10 +23,11 @@ */ #include +#include #include #include -#include +#include #include #include #include @@ -62,7 +63,7 @@ #ifdef HAVE_OPENSSL -void vio_ssl_delete(st_vio * vio) +void vio_ssl_delete(Vio * vio) { /* It must be safe to delete null pointers. */ /* This matches the semantics of C++'s delete operator. */ @@ -74,13 +75,13 @@ void vio_ssl_delete(st_vio * vio) } } -int vio_ssl_errno(st_vio *vio __attribute__((unused))) +int vio_ssl_errno(Vio *vio __attribute__((unused))) { return errno; /* On Win32 this mapped to WSAGetLastError() */ } -int vio_ssl_read(st_vio * vio, gptr buf, int size) +int vio_ssl_read(Vio * vio, gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_read"); @@ -96,7 +97,7 @@ int vio_ssl_read(st_vio * vio, gptr buf, int size) } -int vio_ssl_write(st_vio * vio, const gptr buf, int size) +int vio_ssl_write(Vio * vio, const gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_write"); @@ -112,7 +113,7 @@ int vio_ssl_write(st_vio * vio, const gptr buf, int size) } -int vio_ssl_fastsend(st_vio * vio __attribute__((unused))) +int vio_ssl_fastsend(Vio * vio __attribute__((unused))) { int r=0; DBUG_ENTER("vio_ssl_fastsend"); @@ -138,7 +139,7 @@ int vio_ssl_fastsend(st_vio * vio __attribute__((unused))) DBUG_RETURN(r); } -int vio_ssl_keepalive(st_vio* vio, my_bool set_keep_alive) +int vio_ssl_keepalive(Vio* vio, my_bool set_keep_alive) { int r=0; uint opt = 0; @@ -157,14 +158,14 @@ int vio_ssl_keepalive(st_vio* vio, my_bool set_keep_alive) my_bool -vio_ssl_should_retry(st_vio * vio __attribute__((unused))) +vio_ssl_should_retry(Vio * vio __attribute__((unused))) { int en = errno; return en == EAGAIN || en == EINTR || en == EWOULDBLOCK; } -int vio_ssl_close(st_vio * vio) +int vio_ssl_close(Vio * vio) { int r; DBUG_ENTER("vio_ssl_close"); @@ -191,23 +192,23 @@ int vio_ssl_close(st_vio * vio) } -const char *vio_ssl_description(st_vio * vio) +const char *vio_ssl_description(Vio * vio) { return vio->desc; } -enum enum_vio_type vio_ssl_type(st_vio* vio) +enum enum_vio_type vio_ssl_type(Vio* vio) { return vio->type; } -my_socket vio_ssl_fd(st_vio* vio) +my_socket vio_ssl_fd(Vio* vio) { return vio->sd; } -my_bool vio_ssl_peer_addr(st_vio * vio, char *buf) +my_bool vio_ssl_peer_addr(Vio * vio, char *buf) { DBUG_ENTER("vio_ssl_peer_addr"); DBUG_PRINT("enter", ("sd=%d", vio->sd)); @@ -232,7 +233,7 @@ my_bool vio_ssl_peer_addr(st_vio * vio, char *buf) } -void vio_ssl_in_addr(st_vio *vio, struct in_addr *in) +void vio_ssl_in_addr(Vio *vio, struct in_addr *in) { DBUG_ENTER("vio_ssl_in_addr"); if (vio->localhost) @@ -245,7 +246,7 @@ void vio_ssl_in_addr(st_vio *vio, struct in_addr *in) /* Return 0 if there is data to be read */ -my_bool vio_ssl_poll_read(st_vio *vio,uint timeout) +my_bool vio_ssl_poll_read(Vio *vio,uint timeout) { #ifndef HAVE_POLL return 0; @@ -286,7 +287,7 @@ report_errors() /* FIXME: There are some duplicate code in * sslaccept()/sslconnect() which maybe can be eliminated */ -struct st_vio *sslaccept(struct st_VioSSLAcceptorFd* ptr, struct st_vio* sd) +Vio *sslaccept(struct st_VioSSLAcceptorFd* ptr, Vio* sd) { DBUG_ENTER("sslaccept"); DBUG_PRINT("enter", ("sd=%s ptr=%p", sd->desc,ptr)); @@ -319,7 +320,7 @@ struct st_vio *sslaccept(struct st_VioSSLAcceptorFd* ptr, struct st_vio* sd) DBUG_RETURN(sd); } -struct st_vio *sslconnect(struct st_VioSSLConnectorFd* ptr, struct st_vio* sd) +Vio *sslconnect(struct st_VioSSLConnectorFd* ptr, Vio* sd) { DBUG_ENTER("sslconnect"); DBUG_PRINT("enter", ("sd=%s ptr=%p ctx: %p", sd->desc,ptr,ptr->ssl_context_)); diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index 2b2eaf4fff5..dfe67b503f8 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -2,7 +2,8 @@ #include #include -#include +#include +#include #ifdef HAVE_OPENSSL diff --git a/vio/viotcpip.c b/vio/viotcpip.c deleted file mode 100644 index f0dfc81cf4f..00000000000 --- a/vio/viotcpip.c +++ /dev/null @@ -1,351 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Note that we can't have assertion on file descriptors; The reason for - this is that during mysql shutdown, another thread can close a file - we are working on. In this case we should just return read errors from - the file descriptior. -*/ - -#define DONT_MAP_VIO -#include - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_POLL -#include -#endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - -#if defined(__EMX__) -#define ioctlsocket ioctl -#endif /* defined(__EMX__) */ - -#if defined(MSDOS) || defined(__WIN__) -#ifdef __WIN__ -#undef errno -#undef EINTR -#undef EAGAIN -#define errno WSAGetLastError() -#define EINTR WSAEINTR -#define EAGAIN WSAEINPROGRESS -#endif /* __WIN__ */ -#define O_NONBLOCK 1 /* For emulation of fcntl() */ -#endif -#ifndef EWOULDBLOCK -#define EWOULDBLOCK EAGAIN -#endif - -#ifndef __WIN__ -#define HANDLE void * -#endif - -void vio_delete(st_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(st_vio *vio __attribute__((unused))) -{ - return errno; /* On Win32 this mapped to WSAGetLastError() */ -} - - -int vio_read(st_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 */ - r = read(vio->sd, buf, size); -#endif /* __WIN__ */ -#ifndef DBUG_OFF - if (r < 0) - { - DBUG_PRINT("error", ("Got error %d during read",errno)); - } -#endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); - DBUG_RETURN(r); -} - - -int vio_write(st_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)); -#ifdef __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); -#else - r = write(vio->sd, buf, size); -#endif /* __WIN__ */ -#ifndef DBUG_OFF - if (r < 0) - { - DBUG_PRINT("error", ("Got error on write: %d",errno)); - } -#endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); - DBUG_RETURN(r); -} - - -int vio_blocking(st_vio * vio, my_bool set_blocking_mode) -{ - int r=0; - DBUG_ENTER("vio_blocking"); - DBUG_PRINT("enter", ("set_blocking_mode: %d", (int) set_blocking_mode)); - -#if !defined(___WIN__) && !defined(__EMX__) -#if !defined(NO_FCNTL_NONBLOCK) - - if (vio->sd >= 0) - { - int old_fcntl=vio->fcntl_mode; - if (set_blocking_mode) - vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */ - else - vio->fcntl_mode |= O_NONBLOCK; /* set bit */ - if (old_fcntl != vio->fcntl_mode) - r = fcntl(vio->sd, F_SETFL, vio->fcntl_mode); - } -#endif /* !defined(NO_FCNTL_NONBLOCK) */ -#else /* !defined(__WIN__) && !defined(__EMX__) */ -#ifndef __EMX__ - if (vio->type != VIO_TYPE_NAMEDPIPE) -#endif - { - ulong arg; - int old_fcntl=vio->fcntl_mode; - if (set_blocking_mode) - { - arg = 0; - vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */ - } - else - { - arg = 1; - vio->fcntl_mode |= O_NONBLOCK; /* set bit */ - } - if (old_fcntl != vio->fcntl_mode) - r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg)); - } -#endif /* !defined(__WIN__) && !defined(__EMX__) */ - DBUG_RETURN(r); -} - -my_bool -vio_is_blocking(st_vio * vio) -{ - my_bool r; - DBUG_ENTER("vio_is_blocking"); - r = !(vio->fcntl_mode & O_NONBLOCK); - DBUG_PRINT("exit", ("%d", (int) r)); - DBUG_RETURN(r); -} - - -int vio_fastsend(st_vio * vio __attribute__((unused))) -{ - int r=0; - DBUG_ENTER("vio_fastsend"); - -#ifdef IPTOS_THROUGHPUT - { -#ifndef __EMX__ - int tos = IPTOS_THROUGHPUT; - if (!setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos))) -#endif /* !__EMX__ */ - { - int nodelay = 1; - if (setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, (void *) &nodelay, - sizeof(nodelay))) { - DBUG_PRINT("warning", - ("Couldn't set socket option for fast send")); - r= -1; - } - } - } -#endif /* IPTOS_THROUGHPUT */ - DBUG_PRINT("exit", ("%d", r)); - DBUG_RETURN(r); -} - -int vio_keepalive(st_vio* vio, my_bool set_keep_alive) -{ - int r=0; - uint opt = 0; - DBUG_ENTER("vio_keepalive"); - DBUG_PRINT("enter", ("sd=%d, set_keep_alive=%d", vio->sd, (int) - set_keep_alive)); - if (vio->type != VIO_TYPE_NAMEDPIPE) - { - if (set_keep_alive) - opt = 1; - r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, - sizeof(opt)); - } - DBUG_RETURN(r); -} - - -my_bool -vio_should_retry(st_vio * vio __attribute__((unused))) -{ - int en = errno; - return en == EAGAIN || en == EINTR || en == EWOULDBLOCK; -} - - -int vio_close(st_vio * vio) -{ - int r; - 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 if (vio->type != VIO_CLOSED) -#endif /* __WIN__ */ - { - r=0; - if (shutdown(vio->sd,2)) - r= -1; - if (closesocket(vio->sd)) - r= -1; - } - if (r) - { - DBUG_PRINT("error", ("close() failed, error: %d",errno)); - /* FIXME: error handling (not critical for MySQL) */ - } - vio->type= VIO_CLOSED; - vio->sd= -1; - DBUG_RETURN(r); -} - - -const char *vio_description(st_vio * vio) -{ - return vio->desc; -} - -enum enum_vio_type vio_type(st_vio* vio) -{ - return vio->type; -} - -my_socket vio_fd(st_vio* vio) -{ - return vio->sd; -} - - -my_bool vio_peer_addr(st_vio * vio, char *buf) -{ - DBUG_ENTER("vio_peer_addr"); - DBUG_PRINT("enter", ("sd=%d", vio->sd)); - if (vio->localhost) - { - strmov(buf,"127.0.0.1"); - } - else - { - size_socket addrLen = sizeof(struct sockaddr); - if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)), - &addrLen) != 0) - { - DBUG_PRINT("exit", ("getpeername, error: %d", errno)); - DBUG_RETURN(1); - } - /* FIXME */ -/* my_inet_ntoa(vio->remote.sin_addr,buf); */ - } - DBUG_PRINT("exit", ("addr=%s", buf)); - DBUG_RETURN(0); -} - - -void vio_in_addr(st_vio *vio, struct in_addr *in) -{ - DBUG_ENTER("vio_in_addr"); - if (vio->localhost) - bzero((char*) in, sizeof(*in)); /* This should never be executed */ - else - *in=vio->remote.sin_addr; - DBUG_VOID_RETURN; -} - - -/* Return 0 if there is data to be read */ - -my_bool vio_poll_read(st_vio *vio,uint timeout) -{ -#ifndef HAVE_POLL - return 0; -#else - struct pollfd fds; - int res; - DBUG_ENTER("vio_poll"); - fds.fd=vio->sd; - fds.events=POLLIN; - fds.revents=0; - if ((res=poll(&fds,1,(int) timeout*1000)) <= 0) - { - DBUG_RETURN(res < 0 ? 0 : 1); /* Don't return 1 on errors */ - } - DBUG_RETURN(fds.revents & POLLIN ? 0 : 1); -#endif -} - -- cgit v1.2.1