[Cluster-devel] conga luci/conga_ssl/conga_ssl_lib.cpp ricci/c ...
rmccabe at sourceware.org
rmccabe at sourceware.org
Wed Mar 21 20:12:59 UTC 2007
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-03-21 20:12:58
Modified files:
luci/conga_ssl : conga_ssl_lib.cpp
ricci/common : ClientSocket.cpp Socket.cpp Time.cpp
ricci/include : Socket.h
ricci/ricci : Ricci.cpp
Log message:
- Make the socket connection in the python SSL bindings non-blocking
- This fixes a bug that could hang the luci server for around 5 minutes at a time
- Use gethostbyname_r instead of gethostbyname
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/conga_ssl/conga_ssl_lib.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/ClientSocket.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Socket.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Time.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Socket.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/ricci/Ricci.cpp.diff?cvsroot=cluster&r1=1.22&r2=1.23
--- conga/luci/conga_ssl/conga_ssl_lib.cpp 2006/12/21 21:32:00 1.2
+++ conga/luci/conga_ssl/conga_ssl_lib.cpp 2007/03/21 20:12:57 1.3
@@ -133,7 +133,7 @@
counting_auto_ptr<SSLClient> ss;
{
PythonThreadsAllower all;
- ClientSocket sock(hostname, port);
+ ClientSocket sock(hostname, port, timeout * 1000);
ss = counting_auto_ptr<SSLClient>(new SSLClient(sock));
ss->connect(timeout * 1000);
}
--- conga/ricci/common/ClientSocket.cpp 2006/08/10 22:53:07 1.4
+++ conga/ricci/common/ClientSocket.cpp 2007/03/21 20:12:58 1.5
@@ -1,5 +1,5 @@
/*
- Copyright Red Hat, Inc. 2005
+ Copyright Red Hat, Inc. 2005-2007
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -66,6 +66,47 @@
// log(msg, LogSocket);
}
+ClientSocket::ClientSocket(const String& hostname,
+ unsigned short port,
+ unsigned int timeout_ms) :
+ Socket(-1)
+{
+ _sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (_sock == -1)
+ throw String("ClientSocket(hostname, port): socket() failed");
+
+ nonblocking(true);
+
+ char hostbuf[2048];
+ 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) || !ent)
+ throw String("ClientSocket(hostname, port): gethostbyname() failed");
+
+ char** addrs = ent->h_addr_list;
+ for (int i=0; addrs[i]; i++) {
+ struct sockaddr_in addr_in;
+ addr_in.sin_family = AF_INET;
+ addr_in.sin_port = htons(port);
+ addr_in.sin_addr.s_addr = *((u_int32_t*) addrs[i]);
+
+ 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;
+ }
+ }
+ throw String("ClientSocket(hostname, port): connect() failed");
+}
+
ClientSocket::ClientSocket(const String& hostname, unsigned short port) :
Socket(-1)
{
@@ -73,7 +114,16 @@
if (_sock == -1)
throw String("ClientSocket(hostname, port): socket() failed");
- struct hostent* ent = gethostbyname2(hostname.c_str(), AF_INET);
+ char hostbuf[2048];
+ 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)
throw String("ClientSocket(hostname, port): gethostbyname() failed");
@@ -118,7 +168,16 @@
bool
ClientSocket::connected_to(const String& hostname)
{
- struct hostent* ent = gethostbyname2(hostname.c_str(), AF_INET);
+ char hostbuf[2048];
+ 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)
return false;
--- conga/ricci/common/Socket.cpp 2006/08/10 22:53:07 1.3
+++ conga/ricci/common/Socket.cpp 2007/03/21 20:12:58 1.4
@@ -1,5 +1,5 @@
/*
- Copyright Red Hat, Inc. 2005
+ Copyright Red Hat, Inc. 2005-2007
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -189,7 +189,16 @@
{
char buff[INET_ADDRSTRLEN+1];
std::vector<String> addrs;
- struct hostent* ent = gethostbyname2(hostname.c_str(), AF_INET);
+ char hostbuf[2048];
+ struct hostent hostent_result;
+ struct hostent *ent;
+ int ret;
+
+ if (gethostbyname2_r(hostname.c_str(), AF_INET, &hostent_result,
+ hostbuf, sizeof(hostbuf),
+ &ent, &ret))
+ return addrs;
+
if (!ent)
return addrs;
char** addrs_b = ent->h_addr_list;
--- conga/ricci/common/Time.cpp 2006/08/10 22:53:07 1.4
+++ conga/ricci/common/Time.cpp 2007/03/21 20:12:58 1.5
@@ -1,5 +1,5 @@
/*
- Copyright Red Hat, Inc. 2005
+ Copyright Red Hat, Inc. 2005-2007
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -31,8 +31,7 @@
time_sec()
{
struct timeval t;
- struct timezone z;
- gettimeofday(&t, &z);
+ gettimeofday(&t, NULL);
return t.tv_sec;
}
@@ -40,8 +39,7 @@
time_mil()
{
struct timeval t;
- struct timezone z;
- gettimeofday(&t, &z);
+ gettimeofday(&t, NULL);
return t.tv_sec*1000 + t.tv_usec/1000;
}
--- conga/ricci/include/Socket.h 2006/08/10 22:53:07 1.3
+++ conga/ricci/include/Socket.h 2007/03/21 20:12:58 1.4
@@ -74,6 +74,7 @@
ClientSocket();
ClientSocket(const String& sock_path); // UNIX socket
ClientSocket(const String& hostname, unsigned short port); // TCP socket
+ ClientSocket(const String& hostname, unsigned short port, unsigned int to_ms);
ClientSocket(const ClientSocket&);
ClientSocket& operator= (const ClientSocket&);
virtual ~ClientSocket();
--- conga/ricci/ricci/Ricci.cpp 2007/01/04 00:19:49 1.22
+++ conga/ricci/ricci/Ricci.cpp 2007/03/21 20:12:58 1.23
@@ -466,11 +466,18 @@
char name[1024];
if (gethostname(name, sizeof(name)))
return "";
- struct hostent *ent = gethostbyname(name);
- if (ent)
- return String(ent->h_name);
- else
+
+ char hostbuf[2048];
+ struct hostent hostent_result;
+ struct hostent *ent = NULL;
+ int ret = 0;
+
+ if (gethostbyname_r(name, &hostent_result,
+ hostbuf, sizeof(hostbuf),
+ &ent, &ret) || !ent)
return name;
+
+ return String(ent->h_name);
}
pair<String, String>
More information about the Cluster-devel
mailing list