summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: af19c69)
raw | patch | inline | side by side (parent: af19c69)
author | Florian Forster <octo@huhu.verplant.org> | |
Mon, 20 Apr 2009 13:02:12 +0000 (15:02 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 20 Apr 2009 13:08:27 +0000 (15:08 +0200) |
src/memcached.c | patch | blob | history |
diff --git a/src/memcached.c b/src/memcached.c
index b9c3cb0afd286c03b8d5e86dad4f7d11b2fdb43a..759ef512b7cbc8ccc2da7ed268f96b8a2857e1a5 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
int i = 0;
if (memcached_socket != NULL) {
-
struct sockaddr_un serv_addr;
- memset(&serv_addr, '\0', sizeof (serv_addr));
+ memset (&serv_addr, 0, sizeof (serv_addr));
serv_addr.sun_family = AF_UNIX;
- strncpy(serv_addr.sun_path, memcached_socket, sizeof (serv_addr.sun_path));
+ sstrncpy (serv_addr.sun_path, memcached_socket, sizeof (serv_addr.sun_path));
/* create our socket descriptor */
- if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ fd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
char errbuf[1024];
- ERROR ("memcached: unix socket: %s", sstrerror (errno, errbuf, sizeof (errbuf)));
+ ERROR ("memcached: unix socket: %s", sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return -1;
}
/* connect to the memcached daemon */
- if (connect (fd, (struct sockaddr *) &serv_addr, SUN_LEN(&serv_addr))) {
- shutdown(fd, SHUT_RDWR);
- close(fd);
+ status = (ssize_t) connect (fd, (struct sockaddr *) &serv_addr,
+ SUN_LEN (&serv_addr));
+ if (status != 0) {
+ shutdown (fd, SHUT_RDWR);
+ close (fd);
fd = -1;
}
-
- } else {
-
+ }
+ else { /* if (memcached_socket == NULL) */
const char *host;
const char *port;
fd = -1;
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
/* create our socket descriptor */
- if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0) {
+ fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
+ if (fd < 0) {
char errbuf[1024];
ERROR ("memcached: socket: %s", sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
/* connect to the memcached daemon */
- if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen)) {
- shutdown(fd, SHUT_RDWR);
- close(fd);
+ status = (ssize_t) connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen);
+ if (status != 0) {
+ shutdown (fd, SHUT_RDWR);
+ close (fd);
fd = -1;
continue;
}