~ubuntu-branches/ubuntu/hardy/mysql-dfsg-5.0/hardy-updates

« back to all changes in this revision

Viewing changes to ndb/src/common/util/SocketClient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-04-02 16:10:53 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070402161053-zkil9hjq9k5p1uzv
Tags: 5.0.37-0ubuntu1
* New upstream bugfix release.
  - Fixes replication failure with auto-increment and on duplicate key
    update, a regression introduced into 5.0.24. (LP: #95821)
* debian/control: Set Ubuntu maintainer.
* debian/rules: Change comments from 'Debian etch' to 'Ubuntu 7.04'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; either version 2 of the License, or
6
 
   (at your option) any later version.
 
5
   the Free Software Foundation; version 2 of the License.
7
6
 
8
7
   This program is distributed in the hope that it will be useful,
9
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
27
26
  m_port= port;
28
27
  m_server_name= server_name ? strdup(server_name) : 0;
29
28
  m_sockfd= NDB_INVALID_SOCKET;
 
29
  m_connect_timeout_sec= 0;
30
30
}
31
31
 
32
32
SocketClient::~SocketClient()
59
59
  if (m_sockfd == NDB_INVALID_SOCKET) {
60
60
    return false;
61
61
  }
62
 
  
 
62
 
63
63
  DBUG_PRINT("info",("NDB_SOCKET: %d", m_sockfd));
64
64
 
65
65
  return true;
105
105
NDB_SOCKET_TYPE
106
106
SocketClient::connect(const char *toaddress, unsigned short toport)
107
107
{
 
108
  fd_set rset, wset;
 
109
  struct timeval tval;
 
110
  int r;
 
111
  bool use_timeout;
 
112
  SOCKOPT_OPTLEN_TYPE len;
 
113
  int flags;
 
114
 
108
115
  if (m_sockfd == NDB_INVALID_SOCKET)
109
116
  {
110
117
    if (!init()) {
128
135
    if (Ndb_getInAddr(&m_servaddr.sin_addr, m_server_name))
129
136
      return NDB_INVALID_SOCKET;
130
137
  }
131
 
  
132
 
  const int r = ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
133
 
  if (r == -1) {
134
 
    NDB_CLOSE_SOCKET(m_sockfd);
135
 
    m_sockfd= NDB_INVALID_SOCKET;
136
 
    return NDB_INVALID_SOCKET;
137
 
  }
 
138
 
 
139
  flags= fcntl(m_sockfd, F_GETFL, 0);
 
140
  fcntl(m_sockfd, F_SETFL, flags | O_NONBLOCK);
 
141
 
 
142
  r= ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
 
143
 
 
144
  if (r == 0)
 
145
    goto done; // connected immediately.
 
146
 
 
147
  if (r < 0 && (errno != EINPROGRESS)) {
 
148
    NDB_CLOSE_SOCKET(m_sockfd);
 
149
    m_sockfd= NDB_INVALID_SOCKET;
 
150
    return NDB_INVALID_SOCKET;
 
151
  }
 
152
 
 
153
  FD_ZERO(&rset);
 
154
  FD_SET(m_sockfd, &rset);
 
155
  wset= rset;
 
156
  tval.tv_sec= m_connect_timeout_sec;
 
157
  tval.tv_usec= 0;
 
158
  use_timeout= m_connect_timeout_sec;
 
159
 
 
160
  if ((r= select(m_sockfd+1, &rset, &wset, NULL,
 
161
                 use_timeout? &tval : NULL)) == 0)
 
162
  {
 
163
    NDB_CLOSE_SOCKET(m_sockfd);
 
164
    m_sockfd= NDB_INVALID_SOCKET;
 
165
    return NDB_INVALID_SOCKET;
 
166
  }
 
167
 
 
168
  if (FD_ISSET(m_sockfd, &rset) || FD_ISSET(m_sockfd, &wset))
 
169
  {
 
170
    len= sizeof(r);
 
171
    if (getsockopt(m_sockfd, SOL_SOCKET, SO_ERROR, &r, &len) < 0 || r)
 
172
    {
 
173
      // Solaris got an error... different than others
 
174
      NDB_CLOSE_SOCKET(m_sockfd);
 
175
      m_sockfd= NDB_INVALID_SOCKET;
 
176
      return NDB_INVALID_SOCKET;
 
177
    }
 
178
  }
 
179
  else
 
180
  {
 
181
    // select error, probably m_sockfd not set.
 
182
    NDB_CLOSE_SOCKET(m_sockfd);
 
183
    m_sockfd= NDB_INVALID_SOCKET;
 
184
    return NDB_INVALID_SOCKET;
 
185
  }
 
186
 
 
187
done:
 
188
  fcntl(m_sockfd, F_SETFL, flags);
138
189
 
139
190
  if (m_auth) {
140
191
    if (!m_auth->client_authenticate(m_sockfd))