~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/libdrizzle_priv.c

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
/* Various helper functions not intended to be part of a public API */
21
21
 
22
 
#include "config.h"
 
22
#include <drizzled/global.h>
23
23
#include "libdrizzle_priv.h"
24
24
#include <poll.h>
25
25
#include <fcntl.h>
26
26
 
27
 
const char _dig_vec_upper[] =
28
 
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
29
 
const char _dig_vec_lower[] =
30
 
  "0123456789abcdefghijklmnopqrstuvwxyz";
31
 
 
32
27
const char  *unknown_sqlstate= "HY000";
33
28
const char  *not_error_sqlstate= "00000";
34
29
const char  *cant_connect_sqlstate= "08001";
35
30
 
36
 
const char * sqlstate_get_unknown(void)
 
31
const char * drizzleclient_sqlstate_get_unknown(void)
37
32
{
38
33
  return unknown_sqlstate;
39
34
}
40
35
 
41
 
const char * sqlstate_get_not_error(void)
 
36
const char * drizzleclient_sqlstate_get_not_error(void)
42
37
{
43
38
  return not_error_sqlstate;
44
39
}
45
40
 
46
 
const char * sqlstate_get_cant_connect(void)
 
41
const char * drizzleclient_sqlstate_get_cant_connect(void)
47
42
{
48
43
  return cant_connect_sqlstate;
49
44
}
50
45
 
 
46
/*
 
47
  Wait up to timeout seconds for a connection to be established.
 
48
 
 
49
  We prefer to do this with poll() as there is no limitations with this.
 
50
  If not, we will use select()
 
51
*/
 
52
 
 
53
static int wait_for_data(int fd, int32_t timeout)
 
54
{
 
55
  struct pollfd ufds;
 
56
  int res;
 
57
 
 
58
  ufds.fd= fd;
 
59
  ufds.events= POLLIN | POLLPRI;
 
60
  if (!(res= poll(&ufds, 1, (int) timeout*1000)))
 
61
  {
 
62
    errno= EINTR;
 
63
    return -1;
 
64
  }
 
65
  if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)) || (ufds.revents & POLLHUP))
 
66
    return -1;
 
67
  return 0;
 
68
}
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().
56
74
 
57
75
  Base version coded by Steve Bernacki, Jr. <steve@navinet.net>
58
76
*****************************************************************************/
59
77
 
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)
61
79
{
62
80
  int flags, res, s_err;
63
81
 
88
106
  return wait_for_data(fd, timeout);
89
107
}
90
108
 
91
 
/*
92
 
  Wait up to timeout seconds for a connection to be established.
93
 
 
94
 
  We prefer to do this with poll() as there is no limitations with this.
95
 
  If not, we will use select()
96
 
*/
97
 
 
98
 
int wait_for_data(int fd, int32_t timeout)
99
 
{
100
 
  struct pollfd ufds;
101
 
  int res;
102
 
 
103
 
  ufds.fd= fd;
104
 
  ufds.events= POLLIN | POLLPRI;
105
 
  if (!(res= poll(&ufds, 1, (int) timeout*1000)))
106
 
  {
107
 
    errno= EINTR;
108
 
    return -1;
109
 
  }
110
 
  if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)) || (ufds.revents & POLLHUP))
111
 
    return -1;
112
 
  return 0;
113
 
}