summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authormonty@narttu.mysql.fi <>2003-07-03 19:23:06 +0300
committermonty@narttu.mysql.fi <>2003-07-03 19:23:06 +0300
commitbe22700954f00691118f14e8755f573684167bc4 (patch)
tree763b9a64f7ae82fd4526acdc1cfff89969efca53 /sql
parent27f6a6c4d163d5932e5312fff5a351586f228175 (diff)
downloadmariadb-git-be22700954f00691118f14e8755f573684167bc4.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
Diffstat (limited to 'sql')
-rw-r--r--sql/mini_client.cc173
1 files changed, 116 insertions, 57 deletions
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