projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge in all current libmemcached work, plus restore older, working,
[awesomized/libmemcached]
/
libmemcached
/
connect.c
diff --git
a/libmemcached/connect.c
b/libmemcached/connect.c
index 75d174b459e3418839a251a9dd2fa14483088d19..9f17f0c3f26d971c49e15d95bbe26cb0349577d9 100644
(file)
--- a/
libmemcached/connect.c
+++ b/
libmemcached/connect.c
@@
-9,7
+9,8
@@
*
*/
*
*/
-#include "common.h"
+#include <libmemcached/common.h>
+#include <assert.h>
#include <sys/time.h>
#include <time.h>
#include <sys/time.h>
#include <time.h>
@@
-19,16
+20,12
@@
static memcached_return_t connect_poll(memcached_server_st *ptr)
fds[0].fd = ptr->fd;
fds[0].events = POLLOUT;
fds[0].fd = ptr->fd;
fds[0].events = POLLOUT;
- int timeout= ptr->root->connect_timeout;
- if (ptr->root->flags.no_block == true)
- timeout= -1;
-
int error;
size_t loop_max= 5;
while (--loop_max) // Should only loop on cases of ERESTART or EINTR
{
int error;
size_t loop_max= 5;
while (--loop_max) // Should only loop on cases of ERESTART or EINTR
{
- error= poll(fds, 1, timeout);
+ error= poll(fds, 1,
ptr->root->connect_
timeout);
switch (error)
{
switch (error)
{
@@
-90,10
+87,16
@@
static memcached_return_t connect_poll(memcached_server_st *ptr)
static memcached_return_t set_hostinfo(memcached_server_st *server)
{
static memcached_return_t set_hostinfo(memcached_server_st *server)
{
- struct addrinfo *ai;
struct addrinfo hints;
char str_port[NI_MAXSERV];
struct addrinfo hints;
char str_port[NI_MAXSERV];
- uint32_t counter= 5;
+
+ assert(! server->address_info); // We cover the case where a programming mistake has been made.
+ if (server->address_info)
+ {
+ freeaddrinfo(server->address_info);
+ server->address_info= NULL;
+ server->address_info_next= NULL;
+ }
int length= snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port);
if (length >= NI_MAXSERV || length < 0)
int length= snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port);
if (length >= NI_MAXSERV || length < 0)
@@
-101,7
+104,9
@@
static memcached_return_t set_hostinfo(memcached_server_st *server)
memset(&hints, 0, sizeof(hints));
memset(&hints, 0, sizeof(hints));
- // hints.ai_family= AF_INET;
+#if 0
+ hints.ai_family= AF_INET;
+#endif
if (server->type == MEMCACHED_CONNECTION_UDP)
{
hints.ai_protocol= IPPROTO_UDP;
if (server->type == MEMCACHED_CONNECTION_UDP)
{
hints.ai_protocol= IPPROTO_UDP;
@@
-113,9
+118,10
@@
static memcached_return_t set_hostinfo(memcached_server_st *server)
hints.ai_protocol= IPPROTO_TCP;
}
hints.ai_protocol= IPPROTO_TCP;
}
+ uint32_t counter= 5;
while (--counter)
{
while (--counter)
{
- int e= getaddrinfo(server->hostname, str_port, &hints, &
ai
);
+ int e= getaddrinfo(server->hostname, str_port, &hints, &
server->address_info
);
if (e == 0)
{
if (e == 0)
{
@@
-141,12
+147,7
@@
static memcached_return_t set_hostinfo(memcached_server_st *server)
}
}
}
}
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- }
- server->address_info= ai;
+ server->address_info_next= server->address_info;
return MEMCACHED_SUCCESS;
}
return MEMCACHED_SUCCESS;
}
@@
-339,7
+340,7
@@
static memcached_return_t unix_socket_connect(memcached_server_st *ptr)
memset(&servAddr, 0, sizeof (struct sockaddr_un));
servAddr.sun_family= AF_UNIX;
memset(&servAddr, 0, sizeof (struct sockaddr_un));
servAddr.sun_family= AF_UNIX;
- str
cpy(servAddr.sun_path, ptr->hostname
); /* Copy filename */
+ str
ncpy(servAddr.sun_path, ptr->hostname, sizeof(servAddr.sun_path)
); /* Copy filename */
test_connect:
if (connect(ptr->fd,
test_connect:
if (connect(ptr->fd,
@@
-374,34
+375,29
@@
static memcached_return_t network_connect(memcached_server_st *ptr)
{
bool timeout_error_occured= false;
{
bool timeout_error_occured= false;
-
WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET);
WATCHPOINT_ASSERT(ptr->cursor_active == 0);
WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET);
WATCHPOINT_ASSERT(ptr->cursor_active == 0);
- if (! ptr->
options.sockaddr_inited || (!(ptr->root->flags.use_cache_lookups))
)
+ if (! ptr->
address_info
)
{
{
- memcached_return_t rc;
-
- rc= set_hostinfo(ptr);
+ memcached_return_t rc= set_hostinfo(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
if (rc != MEMCACHED_SUCCESS)
return rc;
- ptr->options.sockaddr_inited= true;
}
}
- struct addrinfo *use= ptr->address_info;
/* Create the socket */
/* Create the socket */
- while (
use != NULL
)
+ while (
ptr->address_info_next && ptr->fd == INVALID_SOCKET
)
{
/* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */
{
/* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */
- if (ptr->type == MEMCACHED_CONNECTION_UDP &&
use
->ai_family != AF_INET)
+ if (ptr->type == MEMCACHED_CONNECTION_UDP &&
ptr->address_info_next
->ai_family != AF_INET)
{
{
-
use= use
->ai_next;
+
ptr->address_info_next= ptr->address_info_next
->ai_next;
continue;
}
continue;
}
- if ((ptr->fd= socket(
use
->ai_family,
-
use
->ai_socktype,
-
use
->ai_protocol)) < 0)
+ if ((ptr->fd= socket(
ptr->address_info_next
->ai_family,
+
ptr->address_info_next
->ai_socktype,
+
ptr->address_info_next
->ai_protocol)) < 0)
{
ptr->cached_errno= get_socket_errno();
WATCHPOINT_ERRNO(get_socket_errno());
{
ptr->cached_errno= get_socket_errno();
WATCHPOINT_ERRNO(get_socket_errno());
@@
-411,40
+407,43
@@
static memcached_return_t network_connect(memcached_server_st *ptr)
(void)set_socket_options(ptr);
/* connect to server */
(void)set_socket_options(ptr);
/* connect to server */
- if ((connect(ptr->fd,
use->ai_addr, use
->ai_addrlen) != SOCKET_ERROR))
+ if ((connect(ptr->fd,
ptr->address_info_next->ai_addr, ptr->address_info_next
->ai_addrlen) != SOCKET_ERROR))
{
break; // Success
}
/* An error occurred */
ptr->cached_errno= get_socket_errno();
{
break; // Success
}
/* An error occurred */
ptr->cached_errno= get_socket_errno();
- if (ptr->cached_errno == EWOULDBLOCK ||
- ptr->cached_errno == EINPROGRESS || /* nonblocking mode - first return, */
- ptr->cached_errno == EALREADY) /* nonblocking mode - subsequent returns */
+ switch (ptr->cached_errno)
{
{
- memcached_return_t rc;
- rc= connect_poll(ptr);
+ case EWOULDBLOCK:
+ case EINPROGRESS: // nonblocking mode - first return
+ case EALREADY: // nonblocking mode - subsequent returns
+ {
+ memcached_return_t rc;
+ rc= connect_poll(ptr);
- if (rc == MEMCACHED_TIMEOUT)
- timeout_error_occured= true;
+
if (rc == MEMCACHED_TIMEOUT)
+
timeout_error_occured= true;
- if (rc == MEMCACHED_SUCCESS)
- break;
- }
- else if (get_socket_errno() == EISCONN) /* we are connected :-) */
- {
+
if (rc == MEMCACHED_SUCCESS)
+
break;
+
}
+
+ case EISCONN: // we are connected :-)
break;
break;
- }
- else if (get_socket_errno() == EINTR) // Special case, we retry ai_addr
- {
+
+ case EINTR: // Special case, we retry ai_addr
(void)closesocket(ptr->fd);
ptr->fd= INVALID_SOCKET;
continue;
(void)closesocket(ptr->fd);
ptr->fd= INVALID_SOCKET;
continue;
- }
- (void)closesocket(ptr->fd);
- ptr->fd= INVALID_SOCKET;
- use= use->ai_next;
+ default:
+ (void)closesocket(ptr->fd);
+ ptr->fd= INVALID_SOCKET;
+ ptr->address_info_next= ptr->address_info_next->ai_next;
+ break;
+ }
}
if (ptr->fd == INVALID_SOCKET)
}
if (ptr->fd == INVALID_SOCKET)