From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci common/ClientSocket.cpp common/Soc ...
Date: 21 Mar 2007 22:51:23 -0000 [thread overview]
Message-ID: <20070321225123.26535.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-03-21 22:51:21
Modified files:
ricci/common : ClientSocket.cpp Socket.cpp
ricci/ricci : Ricci.cpp
Log message:
- Cleanup for the socket hang patch
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/ClientSocket.cpp.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Socket.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/ricci/Ricci.cpp.diff?cvsroot=cluster&r1=1.23&r2=1.24
--- conga/ricci/common/ClientSocket.cpp 2007/03/21 20:12:58 1.5
+++ conga/ricci/common/ClientSocket.cpp 2007/03/21 22:51:20 1.6
@@ -23,6 +23,7 @@
#include "Socket.h"
#include "Logger.h"
+#include "Time.h"
#include <unistd.h>
#include <errno.h>
@@ -73,11 +74,11 @@
{
_sock = socket(PF_INET, SOCK_STREAM, 0);
if (_sock == -1)
- throw String("ClientSocket(hostname, port): socket() failed");
+ throw String("ClientSocket(hostname, port, timeout): socket() failed");
nonblocking(true);
- char hostbuf[2048];
+ char hostbuf[4096];
struct hostent hostent_result;
struct hostent *ent = NULL;
int ret = 0;
@@ -85,7 +86,7 @@
if (gethostbyname2_r(hostname.c_str(), AF_INET, &hostent_result,
hostbuf, sizeof(hostbuf),
&ent, &ret) || !ent)
- throw String("ClientSocket(hostname, port): gethostbyname() failed");
+ throw String("ClientSocket(hostname, port, timeout): gethostbyname() failed");
char** addrs = ent->h_addr_list;
for (int i=0; addrs[i]; i++) {
@@ -96,15 +97,29 @@
ret = connect(_sock, (struct sockaddr*) &addr_in, sizeof(addr_in));
if (ret != -1 || errno != EINPROGRESS)
- throw String("ClientSocket(hostname, port): connect() failed");
- bool can_read, can_write;
- poll(can_read, can_write, timeout_ms);
- if (can_write && !can_read) {
- _addr = addr_in.sin_addr.s_addr;
- return;
- }
+ continue;
+
+ unsigned int end = time_mil() + timeout_ms;
+ do {
+ bool can_read = false;
+ bool can_write = true;
+ poll(can_read, can_write, timeout_ms);
+ if (can_write && can_read) {
+ /* an error occurred */
+ throw String("ClientSocket(hostname, port, timeout): connect() failed");
+ }
+
+ if (can_write && !can_read) {
+ _addr = addr_in.sin_addr.s_addr;
+ return;
+ }
+
+ } while (time_mil() < end);
+
+ throw String("ClientSocket(hostname, port, timeout): connect() timed out");
}
- throw String("ClientSocket(hostname, port): connect() failed");
+
+ throw String("ClientSocket(hostname, port, timeout): connect() failed");
}
ClientSocket::ClientSocket(const String& hostname, unsigned short port) :
@@ -114,17 +129,14 @@
if (_sock == -1)
throw String("ClientSocket(hostname, port): socket() failed");
- char hostbuf[2048];
+ char hostbuf[4096];
struct hostent hostent_result;
struct hostent *ent = NULL;
int ret = 0;
if (gethostbyname2_r(hostname.c_str(), AF_INET, &hostent_result,
hostbuf, sizeof(hostbuf),
- &ent, &ret))
- throw String("ClientSocket(hostname, port): gethostbyname() failed");
-
- if (!ent)
+ &ent, &ret) || !ent)
throw String("ClientSocket(hostname, port): gethostbyname() failed");
char** addrs = ent->h_addr_list;
@@ -168,17 +180,14 @@
bool
ClientSocket::connected_to(const String& hostname)
{
- char hostbuf[2048];
+ char hostbuf[4096];
struct hostent hostent_result;
struct hostent *ent = NULL;
int ret = 0;
if (gethostbyname2_r(hostname.c_str(), AF_INET, &hostent_result,
hostbuf, sizeof(hostbuf),
- &ent, &ret))
- return false;
-
- if (!ent)
+ &ent, &ret) || !ent)
return false;
char** addrs = ent->h_addr_list;
--- conga/ricci/common/Socket.cpp 2007/03/21 20:12:58 1.4
+++ conga/ricci/common/Socket.cpp 2007/03/21 22:51:20 1.5
@@ -189,18 +189,16 @@
{
char buff[INET_ADDRSTRLEN+1];
std::vector<String> addrs;
- char hostbuf[2048];
+ char hostbuf[4096];
struct hostent hostent_result;
struct hostent *ent;
int ret;
if (gethostbyname2_r(hostname.c_str(), AF_INET, &hostent_result,
hostbuf, sizeof(hostbuf),
- &ent, &ret))
+ &ent, &ret) || !ent)
return addrs;
- if (!ent)
- return addrs;
char** addrs_b = ent->h_addr_list;
for (int i=0; addrs_b[i]; i++) {
struct in_addr addr;
--- conga/ricci/ricci/Ricci.cpp 2007/03/21 20:12:58 1.23
+++ conga/ricci/ricci/Ricci.cpp 2007/03/21 22:51:21 1.24
@@ -467,7 +467,7 @@
if (gethostname(name, sizeof(name)))
return "";
- char hostbuf[2048];
+ char hostbuf[4096];
struct hostent hostent_result;
struct hostent *ent = NULL;
int ret = 0;
reply other threads:[~2007-03-21 22:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070321225123.26535.qmail@sourceware.org \
--to=rmccabe@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).