summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2017-04-19 13:19:59 +0000
committerHaavard <havardpe@yahoo-inc.com>2017-04-19 13:19:59 +0000
commit761a941d3a6eff29041de74ef4d5a562aaf16c0a (patch)
treeae77e6d57838fce512ba7e991d2e67882109fee5
parent934767f4381ee8bba5724314286f184988960faa (diff)
remove FastOS_Socket::getHostName
-rw-r--r--fastos/src/tests/sockettest.cpp68
-rw-r--r--fastos/src/vespa/fastos/unix_socket.cpp29
-rw-r--r--fastos/src/vespa/fastos/unix_socket.h2
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/index/dummyfileheadercontext.cpp3
-rw-r--r--storage/src/vespa/storage/storageserver/fnetlistener.cpp3
6 files changed, 7 insertions, 101 deletions
diff --git a/fastos/src/tests/sockettest.cpp b/fastos/src/tests/sockettest.cpp
index 9a655548d97..c356ddfc93f 100644
--- a/fastos/src/tests/sockettest.cpp
+++ b/fastos/src/tests/sockettest.cpp
@@ -654,9 +654,6 @@ public:
// Fallback to localhost if we can't get the hostname
std::string strictBindHost("localhost");
- std::string hostName = FastOS_Socket::getHostName();
- if(!hostName.empty())
- strictBindHost = hostName;
FastOS_ServerSocket *serverSocket =
new FastOS_ServerSocket(18333, 5, NULL, strictBindHost.c_str());
@@ -812,68 +809,6 @@ public:
PrintSeparator();
}
- void HostNameTest ()
- {
- std::string errorMessage;
- std::string hostName;
-
- TestHeader("Hostname Test");
-
- hostName = FastOS_Socket::getHostName(&errorMessage);
-
- if(!hostName.empty())
- {
- Progress(true, "Got hostname: [%s]", hostName.c_str());
-
-
- }
- else
- {
- Progress(false, "Error getting hostname:\n%s", errorMessage.c_str());
- }
-
- PrintSeparator();
- }
-
- void HostAddressTest (bool testWithFailure)
- {
- std::string errorMessage;
-
- if (!testWithFailure)
- {
- TestHeader("Hostaddress Test");
- }
- else
- {
- TestHeader("Provoked Hostaddress Failure Test");
- }
-
- std::string hostName;
-
- hostName = FastOS_Socket::getHostName(&errorMessage);
-
- if (!hostName.empty())
- {
- if (testWithFailure)
- {
- Progress(true, "Got FQ Hostname: [%s], but will use ZZZZ instead",
- hostName.c_str());
- hostName = "ZZZZ";
- }
- else
- {
- Progress(true, "Got FQ Hostname: [%s]",
- hostName.c_str());
- }
- }
- else
- {
- Progress(false, "Error getting hostname:\n%s", errorMessage.c_str());
- }
-
- PrintSeparator();
- }
-
int Main () override
{
printf("This test should be run in the 'test/workarea' directory.\n\n");
@@ -892,9 +827,6 @@ public:
}
}
- HostNameTest();
- HostAddressTest(false);
- HostAddressTest(true);
HttpClientTest();
ClientServerTest();
StrictBindTest();
diff --git a/fastos/src/vespa/fastos/unix_socket.cpp b/fastos/src/vespa/fastos/unix_socket.cpp
index a6cce42bfad..7f08a8dd9a3 100644
--- a/fastos/src/vespa/fastos/unix_socket.cpp
+++ b/fastos/src/vespa/fastos/unix_socket.cpp
@@ -84,34 +84,6 @@ ssize_t FastOS_UNIX_Socket::Read (void *readBuffer, size_t bufferSize)
std::string
-FastOS_UNIX_Socket::getHostName(std::string * errorMsg)
-{
- char buffer[MAXHOSTNAMELEN];
- if (gethostname(buffer, sizeof(buffer)) < 0) {
- if (errorMsg != NULL) {
- int errnoCopy = errno;
- // Malloc calculations here are not 100% correct (does not compensate
- // for printf codes). Allocating a few extra bytes isn't farmful though.
- const char errorUname[]="Failed to use gethostname() to get host name: %s";
- char errorBuf[100];
- const char *errorString = strerror_r(errnoCopy, errorBuf, sizeof(errorBuf));
- char *errorMsgC = static_cast<char *>
- (malloc(strlen(errorUname) +
- strlen(errorString) + 1));
- sprintf(errorMsgC, errorUname, errorString);
- *errorMsg = errorMsgC;
- free(errorMsgC);
- }
- } else {
- buffer[sizeof(buffer) - 1] = '\0';
- return std::string(buffer);
- }
-
- return std::string();
-}
-
-
-std::string
FastOS_UNIX_Socket::getErrorString(int error)
{
char errorBuf[100];
@@ -119,6 +91,7 @@ FastOS_UNIX_Socket::getErrorString(int error)
return std::string(errorString);
}
+
bool FastOS_SocketEventObjects::Init (FastOS_SocketEvent *event)
{
(void)event;
diff --git a/fastos/src/vespa/fastos/unix_socket.h b/fastos/src/vespa/fastos/unix_socket.h
index 9905e00f9cf..9626ac41716 100644
--- a/fastos/src/vespa/fastos/unix_socket.h
+++ b/fastos/src/vespa/fastos/unix_socket.h
@@ -15,8 +15,6 @@ public:
ssize_t Read (void *readBuffer, size_t bufferSize) override;
ssize_t Write (const void *writeBuffer, size_t bufferSize) override;
- static std::string getHostName(std::string *errorMsg);
- static std::string getHostName() { return getHostName(nullptr); }
static int GetLastError () { return errno; }
static std::string getErrorString(int error);
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp
index 6c76cbb9753..059679ba2b4 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp
@@ -30,6 +30,7 @@
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/util/closuretask.h>
+#include <vespa/vespalib/util/host_name.h>
#include <vespa/vespalib/util/random.h>
#include <vespa/searchcore/proton/common/hw_info_sampler.h>
#include <vespa/searchcore/proton/reference/document_db_reference_registry.h>
@@ -100,7 +101,7 @@ Proton::ProtonFileHeaderContext::ProtonFileHeaderContext(const Proton &proton_,
_cluster(),
_pid(getpid())
{
- _hostName = FastOS_Socket::getHostName();
+ _hostName = vespalib::HostName::get();
assert(!_hostName.empty());
}
diff --git a/searchlib/src/vespa/searchlib/index/dummyfileheadercontext.cpp b/searchlib/src/vespa/searchlib/index/dummyfileheadercontext.cpp
index 2228a19a1e7..53673cac9cc 100644
--- a/searchlib/src/vespa/searchlib/index/dummyfileheadercontext.cpp
+++ b/searchlib/src/vespa/searchlib/index/dummyfileheadercontext.cpp
@@ -6,6 +6,7 @@ LOG_SETUP(".index.dummyfileheadercontext");
#include "dummyfileheadercontext.h"
#include <vespa/vespalib/data/fileheader.h>
#include <vespa/searchlib/util/fileheadertk.h>
+#include <vespa/vespalib/util/host_name.h>
namespace search
{
@@ -21,7 +22,7 @@ DummyFileHeaderContext::DummyFileHeaderContext(void)
_hostName(),
_pid(getpid())
{
- _hostName = FastOS_Socket::getHostName();
+ _hostName = vespalib::HostName::get();
assert(!_hostName.empty());
}
diff --git a/storage/src/vespa/storage/storageserver/fnetlistener.cpp b/storage/src/vespa/storage/storageserver/fnetlistener.cpp
index e36eb8a3e79..df227ce5292 100644
--- a/storage/src/vespa/storage/storageserver/fnetlistener.cpp
+++ b/storage/src/vespa/storage/storageserver/fnetlistener.cpp
@@ -4,6 +4,7 @@
#include "rpcrequestwrapper.h"
#include <vespa/storageapi/message/state.h>
#include <vespa/vespalib/util/exceptions.h>
+#include <vespa/vespalib/util/host_name.h>
#include <vespa/log/log.h>
@@ -114,7 +115,7 @@ FNetListener::RPC_getCurrentTime(FRT_RPCRequest *req)
clock_gettime(CLOCK_REALTIME, &t);
req->GetReturn()->AddInt64(t.tv_sec);
req->GetReturn()->AddInt32(t.tv_nsec);
- vespalib::string hostname = FastOS_Socket::getHostName();
+ vespalib::string hostname = vespalib::HostName::get();
req->GetReturn()->AddString(hostname.c_str());
// all handled, will return immediately
return;