retry connect if interrupted by signals

The MySQL client libraries normally retry system calls when
interrupted by signals.  The lone exception I've found is in the
(infrequent) connection setup where it'll propagate the
connect(2) syscall error all the way back up to the caller.
Fortunately inspection of the MySQL client library reveals it
properly preserves the global "errno" variable even with
debugging enabled.

Note that the net.last_errno member does NOT correspond to the
system "errno".
This commit is contained in:
Eric Wong 2010-08-19 14:16:02 -07:00 committed by Brian Lopez
parent 8bfbfa2708
commit 8e81dcb053

View File

@ -1,5 +1,6 @@
#include <mysql2_ext.h>
#include <client.h>
#include <errno.h>
VALUE cMysql2Client;
extern VALUE mMysql2, cMysql2Error;
@ -96,10 +97,12 @@ static VALUE nogvl_connect(void *ptr) {
struct nogvl_connect_args *args = ptr;
MYSQL *client;
do {
client = mysql_real_connect(args->mysql, args->host,
args->user, args->passwd,
args->db, args->port, args->unix_socket,
args->client_flag);
} while (! client && errno == EINTR && (errno = 0) == 0);
return client ? Qtrue : Qfalse;
}