20
20
/* Various helper functions not intended to be part of a public API */
22
#include <drizzled/global.h>
23
23
#include "libdrizzle_priv.h"
27
const char _dig_vec_upper[] =
28
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
29
const char _dig_vec_lower[] =
30
"0123456789abcdefghijklmnopqrstuvwxyz";
32
27
const char *unknown_sqlstate= "HY000";
33
28
const char *not_error_sqlstate= "00000";
34
29
const char *cant_connect_sqlstate= "08001";
36
const char * sqlstate_get_unknown(void)
31
const char * drizzleclient_sqlstate_get_unknown(void)
38
33
return unknown_sqlstate;
41
const char * sqlstate_get_not_error(void)
36
const char * drizzleclient_sqlstate_get_not_error(void)
43
38
return not_error_sqlstate;
46
const char * sqlstate_get_cant_connect(void)
41
const char * drizzleclient_sqlstate_get_cant_connect(void)
48
43
return cant_connect_sqlstate;
47
Wait up to timeout seconds for a connection to be established.
49
We prefer to do this with poll() as there is no limitations with this.
50
If not, we will use select()
53
static int wait_for_data(int fd, int32_t timeout)
59
ufds.events= POLLIN | POLLPRI;
60
if (!(res= poll(&ufds, 1, (int) timeout*1000)))
65
if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)) || (ufds.revents & POLLHUP))
51
69
/****************************************************************************
52
A modified version of connect(). connect_with_timeout() allows you to specify
70
A modified version of connect(). drizzleclient_connect_with_timeout() allows you to specify
53
71
a timeout value, in seconds, that we should wait until we
54
72
derermine we can't connect to a particular host. If timeout is 0,
55
connect_with_timeout() will behave exactly like connect().
73
drizzleclient_connect_with_timeout() will behave exactly like connect().
57
75
Base version coded by Steve Bernacki, Jr. <steve@navinet.net>
58
76
*****************************************************************************/
60
int connect_with_timeout(int fd, const struct sockaddr *name, uint32_t namelen, int32_t timeout)
78
int drizzleclient_connect_with_timeout(int fd, const struct sockaddr *name, uint32_t namelen, int32_t timeout)
62
80
int flags, res, s_err;
88
106
return wait_for_data(fd, timeout);
92
Wait up to timeout seconds for a connection to be established.
94
We prefer to do this with poll() as there is no limitations with this.
95
If not, we will use select()
98
int wait_for_data(int fd, int32_t timeout)
104
ufds.events= POLLIN | POLLPRI;
105
if (!(res= poll(&ufds, 1, (int) timeout*1000)))
110
if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)) || (ufds.revents & POLLHUP))