~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle_priv.c

  • Committer: Monty Taylor
  • Date: 2009-01-09 07:02:24 UTC
  • mto: (779.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 784.
  • Revision ID: mordred@inaugust.com-20090109070224-prwl5p52mfql3zfw
Split out readline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
const char  *not_error_sqlstate= "00000";
29
29
const char  *cant_connect_sqlstate= "08001";
30
30
 
31
 
const char * drizzleclient_sqlstate_get_unknown(void)
 
31
const char * sqlstate_get_unknown(void)
32
32
{
33
33
  return unknown_sqlstate;
34
34
}
35
35
 
36
 
const char * drizzleclient_sqlstate_get_not_error(void)
 
36
const char * sqlstate_get_not_error(void)
37
37
{
38
38
  return not_error_sqlstate;
39
39
}
40
40
 
41
 
const char * drizzleclient_sqlstate_get_cant_connect(void)
 
41
const char * sqlstate_get_cant_connect(void)
42
42
{
43
43
  return cant_connect_sqlstate;
44
44
}
45
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
 
}
69
46
/****************************************************************************
70
 
  A modified version of connect().  drizzleclient_connect_with_timeout() allows you to specify
 
47
  A modified version of connect().  connect_with_timeout() allows you to specify
71
48
  a timeout value, in seconds, that we should wait until we
72
49
  derermine we can't connect to a particular host.  If timeout is 0,
73
 
  drizzleclient_connect_with_timeout() will behave exactly like connect().
 
50
  connect_with_timeout() will behave exactly like connect().
74
51
 
75
52
  Base version coded by Steve Bernacki, Jr. <steve@navinet.net>
76
53
*****************************************************************************/
77
54
 
78
 
int drizzleclient_connect_with_timeout(int fd, const struct sockaddr *name, uint32_t namelen, int32_t timeout)
 
55
int connect_with_timeout(int fd, const struct sockaddr *name, uint32_t namelen, int32_t timeout)
79
56
{
80
57
  int flags, res, s_err;
81
58
 
106
83
  return wait_for_data(fd, timeout);
107
84
}
108
85
 
 
86
/*
 
87
  Wait up to timeout seconds for a connection to be established.
 
88
 
 
89
  We prefer to do this with poll() as there is no limitations with this.
 
90
  If not, we will use select()
 
91
*/
 
92
 
 
93
int wait_for_data(int fd, int32_t timeout)
 
94
{
 
95
  struct pollfd ufds;
 
96
  int res;
 
97
 
 
98
  ufds.fd= fd;
 
99
  ufds.events= POLLIN | POLLPRI;
 
100
  if (!(res= poll(&ufds, 1, (int) timeout*1000)))
 
101
  {
 
102
    errno= EINTR;
 
103
    return -1;
 
104
  }
 
105
  if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)) || (ufds.revents & POLLHUP))
 
106
    return -1;
 
107
  return 0;
 
108
}