diff options
author | unknown <monty@hundin.mysql.fi> | 2001-10-09 03:35:29 +0300 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2001-10-09 03:35:29 +0300 |
commit | 1c64f355b4e0bb7a709dd850857a9bb41b11d09c (patch) | |
tree | 07f2a0acc005ba2b7fb714ce60cb6f8417c6f60e | |
parent | 9417dc5c17bc0c35d04e20e600ce7804ec20e736 (diff) | |
download | mariadb-git-1c64f355b4e0bb7a709dd850857a9bb41b11d09c.tar.gz |
One should not only have to include my_net.h to work with sockets.
This wrapper noew will include all the necessary, system specific files,
which makes all normal source files much easier to write and maintain.
Portability fixes.
Docs/manual.texi:
Updated upgrading from 3.23 -> 4.0
client/mysqladmin.c:
Portability fixes
client/mysqlshow.c:
Portability fixes
extra/resolveip.c:
Portability fixes
include/my_global.h:
Portability fixes
include/my_net.h:
One should not only have to include my_net.h to work with sockets.
This wrapper noew will include all the necessary, system specific files,
which makes all normal source files much easier to write and maintain.
include/mysql_com.h:
Portability fixes
libmysql/net.c:
Portability fixes
libmysqld/lib_vio.c:
Portability fixes
mysql-test/r/drop.result:
Fix crashed tests
mysql-test/r/err000001.result:
Fix crashed tests
mysql-test/r/innodb.result:
Fix crashed tests
mysql-test/r/overflow.result:
Fix crashed tests
sql/net_serv.cc:
Use new my_net.h
vio/vio.c:
Use new my_net.h
vio/viosocket.c:
Use new my_net.h
vio/viossl.c:
Use new my_net.h
-rw-r--r-- | Docs/manual.texi | 8 | ||||
-rw-r--r-- | client/mysqladmin.c | 6 | ||||
-rw-r--r-- | client/mysqlshow.c | 2 | ||||
-rw-r--r-- | extra/resolveip.c | 9 | ||||
-rw-r--r-- | include/my_global.h | 1 | ||||
-rw-r--r-- | include/my_net.h | 49 | ||||
-rw-r--r-- | include/mysql_com.h | 2 | ||||
-rw-r--r-- | libmysql/net.c | 23 | ||||
-rw-r--r-- | libmysqld/lib_vio.c | 35 | ||||
-rw-r--r-- | mysql-test/r/drop.result | 4 | ||||
-rw-r--r-- | mysql-test/r/err000001.result | 2 | ||||
-rw-r--r-- | mysql-test/r/innodb.result | 2 | ||||
-rw-r--r-- | mysql-test/r/overflow.result | 2 | ||||
-rw-r--r-- | sql/net_serv.cc | 23 | ||||
-rw-r--r-- | vio/vio.c | 12 | ||||
-rw-r--r-- | vio/viosocket.c | 29 | ||||
-rw-r--r-- | vio/viossl.c | 38 |
17 files changed, 87 insertions, 160 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi index f651e5cdd78..f9f12d00d00 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -8903,7 +8903,13 @@ version 4.0; @item The old C API functions @code{mysql_drop_db}, @code{mysql_create_db} and @code{mysql_connect} are not supported anymore, unless one compiles -MySQL with @code{USE_OLD_FUNCTIONS}. +MySQL with @code{USE_OLD_FUNCTIONS}. Instead of doing this, one should +change the client to use the new 4.0 API. +@item +In the @code{MYSQL_FIELD} structure, @code{length} and @code{max_length} has +changed from @code{unsigned int} to @code{unsigned long}. This should not +cause any other problems than some warnings if you use these to +@code{printf()} type function. @item You should use @code{TRUNCATE TABLE} when you want to delete all rows from a table and you don't care of how many rows where deleted. diff --git a/client/mysqladmin.c b/client/mysqladmin.c index 6cc55faf626..7cddcfc8e04 100644 --- a/client/mysqladmin.c +++ b/client/mysqladmin.c @@ -928,7 +928,7 @@ static void print_header(MYSQL_RES *result) putchar('|'); while ((field = mysql_fetch_field(result))) { - printf(" %-*s|",field->max_length+1,field->name); + printf(" %-*s|",(int) field->max_length+1,field->name); } putchar('\n'); print_top(result); @@ -983,11 +983,11 @@ static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row) mysql_field_seek(result, 0); field = mysql_fetch_field(result); - printf("| %-*s|", field->max_length + 1, cur[0]); + printf("| %-*s|", (int) field->max_length + 1, cur[0]); field = mysql_fetch_field(result); tmp = cur[1] ? strtoull(cur[1], NULL, 0) : (ulonglong) 0; - printf(" %-*s|\n", field->max_length + 1, + printf(" %-*s|\n", (int) field->max_length + 1, llstr((tmp - last_values[row]), buff)); last_values[row] = tmp; } diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 9c682047c0e..5ac0d24821e 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -713,7 +713,7 @@ static void print_res_header(MYSQL_RES *result) putchar('|'); while ((field = mysql_fetch_field(result))) { - printf(" %-*s|",field->max_length+1,field->name); + printf(" %-*s|",(int) field->max_length+1,field->name); } putchar('\n'); print_res_top(result); diff --git a/extra/resolveip.c b/extra/resolveip.c index fbd9fe65523..9f59a2892f6 100644 --- a/extra/resolveip.c +++ b/extra/resolveip.c @@ -20,16 +20,11 @@ #define RESOLVE_VERSION "2.0" #include <my_global.h> -#include <sys/types.h> -#include <sys/socket.h> -#ifndef HAVE_BROKEN_NETINET_INCLUDES -#include <netinet/in.h> -#endif -#include <arpa/inet.h> -#include <netdb.h> #include <m_ctype.h> +#include <my_net.h> #include <my_sys.h> #include <m_string.h> +#include <netdb.h> #include <getopt.h> #if !defined(_AIX) && !defined(HAVE_UNIXWARE7_THREADS) && !defined(HAVE_UNIXWARE7_POSIX) && !defined(h_errno) diff --git a/include/my_global.h b/include/my_global.h index 50a7b7bcd40..5fc575f7ada 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -653,6 +653,7 @@ typedef off_t os_off_t; #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR #define SOCKET_EAGAIN WSAEINPROGRESS +#define SOCKET_EWOULDBLOCK WSAEINPROGRESS #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE #elif defined(OS2) diff --git a/include/my_net.h b/include/my_net.h index 6a8e98d685c..de1207bee36 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -15,14 +15,20 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -/* thread safe version of some common functions */ +/* + thread safe version of some common functions: + my_inet_ntoa -/* for thread safe my_inet_ntoa */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ + This file is also used to make handling of sockets and ioctl() + portable accross systems. -#if !defined(MSDOS) && !defined(__WIN__) && !defined(__BEOS__) +*/ + +#ifndef _my_net_h +#define _my_net_h +C_MODE_START + +#include <errno.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -32,10 +38,35 @@ extern "C" { #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#ifdef HAVE_POLL +#include <sys/poll.h> +#endif +#ifdef HAVE_SYS_IOCTL_H +#include <sys/ioctl.h> +#endif + +#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) +#include <netinet/in_systm.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#if !defined(alpha_linux_port) +#include <netinet/tcp.h> +#endif +#endif + +#if defined(__EMX__) +#include <sys/ioctl.h> +#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C))) +#undef HAVE_FCNTL +#endif /* defined(__EMX__) */ + +#if defined(MSDOS) || defined(__WIN__) +#define O_NONBLOCK 1 /* For emulation of fcntl() */ +#endif + +/* Thread safe or portable version of some functions */ void my_inet_ntoa(struct in_addr in, char *buf); -#ifdef __cplusplus -} +C_MODE_END #endif diff --git a/include/mysql_com.h b/include/mysql_com.h index a89425ae279..048b6b98918 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -203,7 +203,7 @@ typedef struct st_udf_init { my_bool maybe_null; /* 1 if function can return NULL */ unsigned int decimals; /* for real functions */ - unsigned int max_length; /* For string functions */ + unsigned long max_length; /* For string functions */ char *ptr; /* free pointer for function data */ my_bool const_item; /* 0 if result is independent of arguments */ } UDF_INIT; diff --git a/libmysql/net.c b/libmysql/net.c index 44e3dd14f80..5e002a0f63e 100644 --- a/libmysql/net.c +++ b/libmysql/net.c @@ -31,16 +31,16 @@ #include <winsock.h> #endif #include <my_global.h> -#include "mysql_embed.h" +#include <mysql.h> +#include <mysql_embed.h> #include <mysql_com.h> -#include <violite.h> +#include <mysqld_error.h> #include <my_sys.h> #include <m_string.h> -#include "mysql.h" -#include "mysqld_error.h" +#include <my_net.h> +#include <violite.h> #include <signal.h> #include <errno.h> -#include <sys/types.h> #ifdef MYSQL_SERVER ulong max_allowed_packet=65536; @@ -60,20 +60,9 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT; #endif ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */ -#if !defined(__WIN__) && !defined(MSDOS) -#include <sys/socket.h> -#else +#if defined(__WIN__) || defined(MSDOS) #undef MYSQL_SERVER /* Win32 can't handle interrupts */ #endif -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) -#include <netinet/in_systm.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#if !defined(alpha_linux_port) -#include <netinet/tcp.h> -#endif -#endif -#include "mysqld_error.h" #ifdef MYSQL_SERVER #include "my_pthread.h" #include "thr_alarm.h" diff --git a/libmysqld/lib_vio.c b/libmysqld/lib_vio.c index 37f77eaaad5..270b08ef51d 100644 --- a/libmysqld/lib_vio.c +++ b/libmysqld/lib_vio.c @@ -26,7 +26,7 @@ #include "mysql_embed.h" #include "mysql.h" -#ifndef HAVE_VIO /* is Vio suppored by the Vio lib ? */ +#ifndef HAVE_VIO /* is Vio enabled */ #include <errno.h> #include <my_sys.h> @@ -37,27 +37,6 @@ #include <dbug.h> #include <assert.h> -#if defined(__EMX__) -#include <sys/ioctl.h> -#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C))) -#undef HAVE_FCNTL -#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 @@ -72,14 +51,11 @@ struct st_vio struct sockaddr_in remote; /* Remote internet address */ enum enum_vio_type type; /* Type of connection */ char desc[30]; /* String description */ - /* #ifdef EMBEDDED_LIBRARY */ - /* void *dest_net; */ void *dest_thd; char *packets, **last_packet; char *where_in_packet, *end_of_packet; my_bool reading; MEM_ROOT root; - /* #endif */ }; /* Initialize the communication buffer */ @@ -90,7 +66,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) vio = (Vio *) my_malloc (sizeof(*vio),MYF(MY_WME|MY_ZEROFILL)); if (vio) { - init_alloc_root(&vio->root, 8192, 1024); + init_alloc_root(&vio->root, 8192, 8192); vio->root.min_malloc = sizeof(char *) + 4; vio->last_packet = &vio->packets; } @@ -126,7 +102,7 @@ void vio_reset(Vio *vio) int vio_errno(Vio *vio __attribute__((unused))) { - return errno; /* On Win32 this mapped to WSAGetLastError() */ + return socket_errno; /* On Win32 this mapped to WSAGetLastError() */ } int vio_read(Vio * vio, gptr buf, int size) @@ -198,8 +174,9 @@ int vio_keepalive(Vio* vio, my_bool set_keep_alive) my_bool vio_should_retry(Vio * vio __attribute__((unused))) { - int en = errno; - return en == EAGAIN || en == EINTR || en == EWOULDBLOCK; + int en = socket_errno; + return (en == SOCKET_EAGAIN || en == SOCKET_EINTR || + en == SOCKET_EWOULDBLOCK); } diff --git a/mysql-test/r/drop.result b/mysql-test/r/drop.result index e8bc7486369..7c1b7c5b60d 100644 --- a/mysql-test/r/drop.result +++ b/mysql-test/r/drop.result @@ -27,7 +27,7 @@ drop database foo; drop database if exists foo; flush tables with read lock; create database foo; -Can't execute the query because you have a conflicting read lock +Got one of the listed errors unlock tables; create database foo; show databases; @@ -37,7 +37,7 @@ mysql test flush tables with read lock; drop database foo; -Can't execute the query because you have a conflicting read lock +Got one of the listed errors unlock tables; drop database foo; show databases; diff --git a/mysql-test/r/err000001.result b/mysql-test/r/err000001.result index 2cfd34f068a..5afecc6d600 100644 --- a/mysql-test/r/err000001.result +++ b/mysql-test/r/err000001.result @@ -13,7 +13,7 @@ Unknown table 'not_existing_database' in field list select count(not_existing_database.t1.a) from t1; Unknown table 'not_existing_database.t1' in field list select count(not_existing_database.t1.a) from not_existing_database.t1; -Table 'not_existing_database.t1' doesn't exist +Got one of the listed errors select 1 from t1 order by 2; Unknown column '2' in 'order clause' select 1 from t1 group by 2; diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index c96ce4e5e33..596edb84705 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -48,7 +48,7 @@ id parent_id level 15 102 2 update t1 set id=id+1000; update t1 set id=1024 where id=1009; -Duplicate entry '1024' for key 1 +Got one of the listed errors select * from t1; id parent_id level 1001 100 0 diff --git a/mysql-test/r/overflow.result b/mysql-test/r/overflow.result index ac857513d01..a5fa7154833 100644 --- a/mysql-test/r/overflow.result +++ b/mysql-test/r/overflow.result @@ -1,2 +1,2 @@ drop database AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; -Incorrect database name 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +Got one of the listed errors diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 44e3dd14f80..5e002a0f63e 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -31,16 +31,16 @@ #include <winsock.h> #endif #include <my_global.h> -#include "mysql_embed.h" +#include <mysql.h> +#include <mysql_embed.h> #include <mysql_com.h> -#include <violite.h> +#include <mysqld_error.h> #include <my_sys.h> #include <m_string.h> -#include "mysql.h" -#include "mysqld_error.h" +#include <my_net.h> +#include <violite.h> #include <signal.h> #include <errno.h> -#include <sys/types.h> #ifdef MYSQL_SERVER ulong max_allowed_packet=65536; @@ -60,20 +60,9 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT; #endif ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */ -#if !defined(__WIN__) && !defined(MSDOS) -#include <sys/socket.h> -#else +#if defined(__WIN__) || defined(MSDOS) #undef MYSQL_SERVER /* Win32 can't handle interrupts */ #endif -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) -#include <netinet/in_systm.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#if !defined(alpha_linux_port) -#include <netinet/tcp.h> -#endif -#endif -#include "mysqld_error.h" #ifdef MYSQL_SERVER #include "my_pthread.h" #include "thr_alarm.h" diff --git a/vio/vio.c b/vio/vio.c index 95d318ba118..759f9416ddf 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -25,22 +25,10 @@ #include <my_global.h> #include <mysql_com.h> #include <violite.h> - #include <errno.h> -#include <assert.h> #include <my_sys.h> #include <my_net.h> #include <m_string.h> -#ifdef HAVE_POLL -#include <sys/poll.h> -#endif -#ifdef HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#endif - -#if defined(__EMX__) || defined(OS2) -#define ioctlsocket ioctl -#endif /* defined(__EMX__) */ /* * Helper to fill most of the Vio* with defaults. diff --git a/vio/viosocket.c b/vio/viosocket.c index aacfab42810..f6f62924b00 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -27,36 +27,10 @@ #include <mysql_com.h> #include <errno.h> -#include <assert.h> #include <violite.h> #include <my_sys.h> #include <my_net.h> #include <m_string.h> -#ifdef HAVE_POLL -#include <sys/poll.h> -#endif -#ifdef HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#endif - - -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) -#include <netinet/ip.h> -#if !defined(alpha_linux_port) -#include <netinet/tcp.h> -#endif -#endif - -#if defined(__EMX__) || defined(OS2) -#define ioctlsocket ioctl -#endif /* defined(__EMX__) */ - -#if defined(MSDOS) || defined(__WIN__) -#define O_NONBLOCK 1 /* For emulation of fcntl() */ -#endif -#ifndef EWOULDBLOCK -#define SOCKET_EWOULDBLOCK SOCKET_EAGAIN -#endif #ifndef __WIN__ #define HANDLE void * @@ -243,7 +217,8 @@ my_bool vio_should_retry(Vio * vio __attribute__((unused))) { int en = socket_errno; - return en == SOCKET_EAGAIN || en == SOCKET_EINTR || en == SOCKET_EWOULDBLOCK; + return (en == SOCKET_EAGAIN || en == SOCKET_EINTR || + en == SOCKET_EWOULDBLOCK); } diff --git a/vio/viossl.c b/vio/viossl.c index e80dc0ce807..e4f2d0a5c9f 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -34,31 +34,6 @@ #include <my_sys.h> #include <my_net.h> #include <m_string.h> -#ifdef HAVE_POLL -#include <sys/poll.h> -#endif -#ifdef HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#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 * @@ -83,7 +58,7 @@ report_errors() if (!any_ssl_error) { DBUG_PRINT("info", ("No OpenSSL errors.")); } - DBUG_PRINT("info", ("BTW, errno=%d", errno)); + DBUG_PRINT("info", ("BTW, errno=%d", scoket_errno)); DBUG_VOID_RETURN; } @@ -102,7 +77,7 @@ void vio_ssl_delete(Vio * vio) int vio_ssl_errno(Vio *vio __attribute__((unused))) { - return errno; /* On Win32 this mapped to WSAGetLastError() */ + return socket_errno; /* On Win32 this mapped to WSAGetLastError() */ } @@ -195,8 +170,9 @@ int vio_ssl_keepalive(Vio* vio, my_bool set_keep_alive) my_bool vio_ssl_should_retry(Vio * vio __attribute__((unused))) { - int en = errno; - return en == EAGAIN || en == EINTR || en == EWOULDBLOCK; + int en = socket_errno; + return (en == SOCKET_EAGAIN || en == SOCKET_EINTR || + en == SOCKET_EWOULDBLOCK); } @@ -217,7 +193,7 @@ int vio_ssl_close(Vio * vio) r= -1; if (r) { - DBUG_PRINT("error", ("close() failed, error: %d",errno)); + DBUG_PRINT("error", ("close() failed, error: %d",socket_errno)); report_errors(); /* FIXME: error handling (not critical for MySQL) */ } @@ -257,7 +233,7 @@ my_bool vio_ssl_peer_addr(Vio * vio, char *buf) if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)), &addrLen) != 0) { - DBUG_PRINT("exit", ("getpeername, error: %d", errno)); + DBUG_PRINT("exit", ("getpeername, error: %d", socket_errno)); DBUG_RETURN(1); } /* FIXME */ |