diff options
author | unknown <monty@narttu.mysql.fi> | 2003-07-03 19:23:06 +0300 |
---|---|---|
committer | unknown <monty@narttu.mysql.fi> | 2003-07-03 19:23:06 +0300 |
commit | 5179b54113ce70dedb237c3c7dd262d59c06fe73 (patch) | |
tree | 763b9a64f7ae82fd4526acdc1cfff89969efca53 | |
parent | 27a96b738956da9627016cf977e31ab8aaef6ad2 (diff) | |
download | mariadb-git-5179b54113ce70dedb237c3c7dd262d59c06fe73.tar.gz |
Fix for UNIXWARE 7
Remove unaligned warnings on Ia64 from client library when using --host
Fix for replication when using many file descriptors
include/my_global.h:
Fix for UNIXWARE 7
libmysql/libmysql.c:
Portability fix (removes unaligned warnings on Ia64)
mysql-test/r/symlink.result:
Updated results
sql/mini_client.cc:
Ported connect timeout code from libmysql.c
-rw-r--r-- | include/my_global.h | 8 | ||||
-rw-r--r-- | libmysql/libmysql.c | 16 | ||||
-rw-r--r-- | mysql-test/r/symlink.result | 9 | ||||
-rw-r--r-- | sql/mini_client.cc | 173 |
4 files changed, 143 insertions, 63 deletions
diff --git a/include/my_global.h b/include/my_global.h index 673e5a22868..5ad12fc1f15 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -43,6 +43,10 @@ #define HAVE_ERRNO_AS_DEFINE #endif /* __CYGWIN__ */ +#if defined(i386) && !defined(__i386__) +#define __i386__ +#endif + /* Macros to make switching between C and C++ mode easier */ #ifdef __cplusplus #define C_MODE_START extern "C" { @@ -145,6 +149,10 @@ double my_ulonglong2double(unsigned long long A); C_MODE_END #endif /* _AIX */ +#ifdef UNIXWARE_7 +#define pthread_attr_setstacksize(A,B) /* setting stack breaks things */ +#endif + #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */ #undef HAVE_SNPRINTF #endif diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 3c8ac9f3387..aa169335dfb 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1596,6 +1596,18 @@ mysql_connect(MYSQL *mysql,const char *host, /* + The following union is used to force a struct to be double allgined. + This is to avoid warings with gethostname_r() on Linux itanium systems +*/ + +typedef union +{ + double tmp; + char buff[GETHOSTBYNAME_BUFF_SIZE]; +} gethostbyname_buff; + + +/* Note that the mysql argument must be initialized with mysql_init() before calling mysql_real_connect ! */ @@ -1766,8 +1778,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, { int tmp_errno; struct hostent tmp_hostent,*hp; - char buff2[GETHOSTBYNAME_BUFF_SIZE]; - hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), + gethostbyname_buff buff2; + hp = my_gethostbyname_r(host,&tmp_hostent,buff2.buff,sizeof(buff2), &tmp_errno); if (!hp) { diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index 5626bc0fe11..ab699ac4c4e 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -1,4 +1,5 @@ drop table if exists t1,t2,t7,t8,t9; +drop database if exists mysqltest; create table t1 (a int not null auto_increment, b char(16) not null, primary key (a)); create table t2 (a int not null auto_increment, b char(16) not null, primary key (a)); insert into t1 (b) values ("test"),("test1"),("test2"),("test3"); @@ -49,11 +50,11 @@ Got one of the listed errors Got one of the listed errors Got one of the listed errors Got one of the listed errors -alter table t9 rename test_mysqltest.t9; -select count(*) from test_mysqltest.t9; +alter table t9 rename mysqltest.t9; +select count(*) from mysqltest.t9; count(*) 16724 -show create table test_mysqltest.t9; +show create table mysqltest.t9; Table Create Table t9 CREATE TABLE `t9` ( `a` int(11) NOT NULL auto_increment, @@ -62,4 +63,4 @@ t9 CREATE TABLE `t9` ( `d` int(11) NOT NULL default '0', PRIMARY KEY (`a`) ) TYPE=MyISAM -drop database test_mysqltest; +drop database mysqltest; diff --git a/sql/mini_client.cc b/sql/mini_client.cc index 6489685c923..1b625a81b0c 100644 --- a/sql/mini_client.cc +++ b/sql/mini_client.cc @@ -83,7 +83,9 @@ static int mc_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths); static MYSQL_DATA *mc_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); - +#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__)) +static int wait_for_data(my_socket fd, uint timeout); +#endif #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_LOCAL_FILES) @@ -232,93 +234,150 @@ static void mc_free_old_query(MYSQL *mysql) /**************************************************************************** -* A modified version of connect(). mc_sock_connect() allows you to specify -* a timeout value, in seconds, that we should wait until we -* derermine we can't connect to a particular host. If timeout is 0, -* mc_sock_connect() will behave exactly like connect(). -* -* Base version coded by Steve Bernacki, Jr. <steve@navinet.net> + A modified version of connect(). my_connect() allows you to specify + a timeout value, in seconds, that we should wait until we + derermine we can't connect to a particular host. If timeout is 0, + my_connect() will behave exactly like connect(). + + Base version coded by Steve Bernacki, Jr. <steve@navinet.net> *****************************************************************************/ -static int mc_sock_connect(my_socket s, const struct sockaddr *name, - uint namelen, uint to) +static int mc_sock_connect(my_socket fd, const struct sockaddr *name, + uint namelen, uint timeout) { #if defined(__WIN__) || defined(OS2) || defined(__NETWARE__) - return connect(s, (struct sockaddr*) name, namelen); + return connect(fd, (struct sockaddr*) name, namelen); #else int flags, res, s_err; - SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); - fd_set sfds; - struct timeval tv; - /* If they passed us a timeout of zero, we should behave - * exactly like the normal connect() call does. - */ + /* + If they passed us a timeout of zero, we should behave + exactly like the normal connect() call does. + */ - if (to == 0) - return connect(s, (struct sockaddr*) name, namelen); + if (timeout == 0) + return connect(fd, (struct sockaddr*) name, namelen); - flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */ + flags = fcntl(fd, F_GETFL, 0); /* Set socket to not block */ #ifdef O_NONBLOCK - fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ + fcntl(fd, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ #endif - res = connect(s, (struct sockaddr*) name, namelen); - s_err = errno; /* Save the error... */ - fcntl(s, F_SETFL, flags); + res= connect(fd, (struct sockaddr*) name, namelen); + s_err= errno; /* Save the error... */ + fcntl(fd, F_SETFL, flags); if ((res != 0) && (s_err != EINPROGRESS)) { - errno = s_err; /* Restore it */ + errno= s_err; /* Restore it */ return(-1); } if (res == 0) /* Connected quickly! */ return(0); + return wait_for_data(fd, timeout); +#endif +} - /* Otherwise, our connection is "in progress." We can use - * the select() call to wait up to a specified period of time - * for the connection to suceed. If select() returns 0 - * (after waiting howevermany seconds), our socket never became - * writable (host is probably unreachable.) Otherwise, if - * select() returns 1, then one of two conditions exist: - * - * 1. An error occured. We use getsockopt() to check for this. - * 2. The connection was set up sucessfully: getsockopt() will - * return 0 as an error. - * - * Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> - * who posted this method of timing out a connect() in - * comp.unix.programmer on August 15th, 1997. - */ - FD_ZERO(&sfds); - FD_SET(s, &sfds); - tv.tv_sec = (long) to; - tv.tv_usec = 0; -#ifdef HPUX10 - res = select(s+1, NULL, (int*) &sfds, NULL, &tv); +/* + Wait up to timeout seconds for a connection to be established. + + We prefer to do this with poll() as there is no limitations with this. + If not, we will use select() +*/ + +#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__)) + +static int wait_for_data(my_socket fd, uint timeout) +{ +#ifdef HAVE_POLL + struct pollfd ufds; + int res; + + ufds.fd= fd; + ufds.events= POLLIN | POLLPRI; + if (!(res= poll(&ufds, 1, (int) timeout*1000))) + { + errno= EINTR; + return -1; + } + if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI))) + return -1; + return 0; #else - res = select(s+1, NULL, &sfds, NULL, &tv); -#endif /* HPUX10 */ - if (res <= 0) /* Never became writable */ - return(-1); + SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint); + fd_set sfds; + struct timeval tv; + time_t start_time, now_time; + int res, s_err; - /* select() returned something more interesting than zero, let's - * see if we have any errors. If the next two statements pass, - * we've got an open socket! + if (fd >= FD_SETSIZE) /* Check if wrong error */ + return 0; /* Can't use timeout */ + + /* + Our connection is "in progress." We can use the select() call to wait + up to a specified period of time for the connection to suceed. + If select() returns 0 (after waiting howevermany seconds), our socket + never became writable (host is probably unreachable.) Otherwise, if + select() returns 1, then one of two conditions exist: + + 1. An error occured. We use getsockopt() to check for this. + 2. The connection was set up sucessfully: getsockopt() will + return 0 as an error. + + Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> + who posted this method of timing out a connect() in + comp.unix.programmer on August 15th, 1997. + */ + + FD_ZERO(&sfds); + FD_SET(fd, &sfds); + /* + select could be interrupted by a signal, and if it is, + the timeout should be adjusted and the select restarted + to work around OSes that don't restart select and + implementations of select that don't adjust tv upon + failure to reflect the time remaining */ + start_time = time(NULL); + for (;;) + { + tv.tv_sec = (long) timeout; + tv.tv_usec = 0; +#if defined(HPUX10) && defined(THREAD) + if ((res = select(fd+1, NULL, (int*) &sfds, NULL, &tv)) > 0) + break; +#else + if ((res = select(fd+1, NULL, &sfds, NULL, &tv)) > 0) + break; +#endif + if (res == 0) /* timeout */ + return -1; + now_time=time(NULL); + timeout-= (uint) (now_time - start_time); + if (errno != EINTR || (int) timeout <= 0) + return -1; + } + + /* + select() returned something more interesting than zero, let's + see if we have any errors. If the next two statements pass, + we've got an open socket! + */ s_err=0; - if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) return(-1); if (s_err) - { // getsockopt() could succeed + { /* getsockopt could succeed */ errno = s_err; - return(-1); // but return an error... + return(-1); /* but return an error... */ } - return(0); /* It's all good! */ -#endif + return (0); /* ok */ +#endif /* HAVE_POLL */ } +#endif /* defined(__WIN__) || defined(OS2) || defined(__NETWARE__) */ + /***************************************************************************** ** read a packet from server. Give error message if socket was down |