dnssecinfra.cc \
dnswriter.cc dnswriter.hh \
gss_context.cc gss_context.hh \
+ iputils.cc \
logger.cc \
misc.cc misc.hh \
nsecrecords.cc \
dnssecinfra.cc \
dnswriter.cc dnswriter.hh \
gss_context.cc gss_context.hh \
+ iputils.cc \
logger.cc \
misc.cc misc.hh \
nsec3dig.cc \
throw runtime_error(fmt.str());
}
+static void NetworkErr(const boost::format& fmt)
+{
+ throw NetworkError(fmt.str());
+}
int SSocket(int family, int type, int flags)
{
savederrno = 0;
socklen_t errlen = sizeof(savederrno);
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&savederrno, &errlen) == 0) {
- RuntimeError(boost::format("connecting to %s failed: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
+ NetworkErr(boost::format("connecting to %s failed: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
}
else {
- RuntimeError(boost::format("connecting to %s failed") % remote.toStringWithPort());
+ NetworkErr(boost::format("connecting to %s failed") % remote.toStringWithPort());
}
}
if (disconnected) {
- RuntimeError(boost::format("%s closed the connection") % remote.toStringWithPort());
+ NetworkErr(boost::format("%s closed the connection") % remote.toStringWithPort());
}
return 0;
}
else if (res == 0) {
- RuntimeError(boost::format("timeout while connecting to %s") % remote.toStringWithPort());
+ NetworkErr(boost::format("timeout while connecting to %s") % remote.toStringWithPort());
} else if (res < 0) {
savederrno = errno;
- RuntimeError(boost::format("waiting to connect to %s: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
+ NetworkErr(boost::format("waiting to connect to %s: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
}
}
else {
- RuntimeError(boost::format("connecting to %s: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
+ NetworkErr(boost::format("connecting to %s: %s") % remote.toStringWithPort() % string(strerror(savederrno)));
}
}
}
};
+class NetworkError : public runtime_error
+{
+public:
+ NetworkError(const string& why="Network Error") : runtime_error(why.c_str())
+ {}
+ NetworkError(const char *why="Network Error") : runtime_error(why)
+ {}
+};
int SSocket(int family, int type, int flags);
int SConnect(int sockfd, const ComboAddress& remote);
#include "namespaces.hh"
-class NetworkError : public runtime_error
-{
-public:
- NetworkError(const string& why="Network Error") : runtime_error(why.c_str())
- {}
- NetworkError(const char *why="Network Error") : runtime_error(why)
- {}
-};
-
-
typedef int ProtocolType; //!< Supported protocol types
//! Representation of a Socket and many of the Berkeley functions available
//! Connect the socket to a specified endpoint
void connect(const ComboAddress &ep, int timeout=0)
{
- if(::connect(d_socket,(struct sockaddr *)&ep, ep.getSocklen()) < 0) {
- if(errno == EINPROGRESS) {
- if (timeout > 0) {
- /* if a timeout is provided, we wait until the connection has been established */
- int res = waitForRWData(d_socket, false, timeout, 0);
- if (res == 0) {
- throw NetworkError("timeout while connecting to "+ep.toStringWithPort());
- } else if (res < 0) {
- throw NetworkError("while waiting to connect to "+ep.toStringWithPort()+": "+string(strerror(errno)));
- }
- }
- }
- else {
- throw NetworkError("While connecting to "+ep.toStringWithPort()+": "+string(strerror(errno)));
- }
- }
+ SConnectWithTimeout(d_socket, ep, timeout);
}