}
if (!IsAnyAddress(d_config.remote)) {
fd = SSocket(d_config.remote.sin4.sin_family, SOCK_DGRAM, 0);
- if (!IsAnyAddress(d_config.sourceAddr)) {
- SSetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 1);
- if (!d_config.sourceItfName.empty()) {
+
+ if (!d_config.sourceItfName.empty()) {
#ifdef SO_BINDTODEVICE
- int res = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, d_config.sourceItfName.c_str(), d_config.sourceItfName.length());
- if (res != 0) {
- infolog("Error setting up the interface on backend socket '%s': %s", d_config.remote.toStringWithPort(), stringerror());
- }
-#endif
+ int res = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, d_config.sourceItfName.c_str(), d_config.sourceItfName.length());
+ if (res != 0) {
+ infolog("Error setting up the interface on backend socket '%s': %s", d_config.remote.toStringWithPort(), stringerror());
}
+#endif
+ }
+ if (!IsAnyAddress(d_config.sourceAddr)) {
+ SSetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 1);
SBind(fd, d_config.sourceAddr);
}
try {
}
connected = true;
}
- catch(const std::runtime_error& error) {
+ catch (const std::runtime_error& error) {
infolog("Error connecting to new server with address %s: %s", d_config.remote.toStringWithPort(), error.what());
connected = false;
break;
Socket sock(ds->d_config.remote.sin4.sin_family, ds->doHealthcheckOverTCP() ? SOCK_STREAM : SOCK_DGRAM);
sock.setNonBlocking();
+ if (!ds->d_config.sourceItfName.empty()) {
+#ifdef SO_BINDTODEVICE
+ int res = setsockopt(sock.getHandle(), SOL_SOCKET, SO_BINDTODEVICE, ds->d_config.sourceItfName.c_str(), ds->d_config.sourceItfName.length());
+ if (res != 0 && g_verboseHealthChecks) {
+ infolog("Error setting SO_BINDTODEVICE on the health check socket for backend '%s': %s", ds->getNameWithAddr(), stringerror());
+ }
+#endif
+ }
+
if (!IsAnyAddress(ds->d_config.sourceAddr)) {
sock.setReuseAddr();
#ifdef IP_BIND_ADDRESS_NO_PORT
SSetsockopt(sock.getHandle(), SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1);
}
#endif
-
- if (!ds->d_config.sourceItfName.empty()) {
-#ifdef SO_BINDTODEVICE
- int res = setsockopt(sock.getHandle(), SOL_SOCKET, SO_BINDTODEVICE, ds->d_config.sourceItfName.c_str(), ds->d_config.sourceItfName.length());
- if (res != 0 && g_verboseHealthChecks) {
- infolog("Error setting SO_BINDTODEVICE on the health check socket for backend '%s': %s", ds->getNameWithAddr(), stringerror());
- }
-#endif
- }
sock.bind(ds->d_config.sourceAddr);
}
auto socket = std::make_unique<Socket>(d_ds->d_config.remote.sin4.sin_family, SOCK_STREAM, 0);
DEBUGLOG("result of socket() is "<<socket->getHandle());
+#ifdef SO_BINDTODEVICE
+ if (!d_ds->d_config.sourceItfName.empty()) {
+ int res = setsockopt(socket->getHandle(), SOL_SOCKET, SO_BINDTODEVICE, d_ds->d_config.sourceItfName.c_str(), d_ds->d_config.sourceItfName.length());
+ if (res != 0) {
+ vinfolog("Error setting up the interface on backend TCP socket '%s': %s", d_ds->getNameWithAddr(), stringerror());
+ }
+ }
+#endif
+
if (!IsAnyAddress(d_ds->d_config.sourceAddr)) {
SSetsockopt(socket->getHandle(), SOL_SOCKET, SO_REUSEADDR, 1);
#ifdef IP_BIND_ADDRESS_NO_PORT
if (d_ds->d_config.ipBindAddrNoPort) {
SSetsockopt(socket->getHandle(), SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1);
}
-#endif
-#ifdef SO_BINDTODEVICE
- if (!d_ds->d_config.sourceItfName.empty()) {
- int res = setsockopt(socket->getHandle(), SOL_SOCKET, SO_BINDTODEVICE, d_ds->d_config.sourceItfName.c_str(), d_ds->d_config.sourceItfName.length());
- if (res != 0) {
- vinfolog("Error setting up the interface on backend TCP socket '%s': %s", d_ds->getNameWithAddr(), stringerror());
- }
- }
#endif
socket->bind(d_ds->d_config.sourceAddr, false);
}
+
socket->setNonBlocking();
gettimeofday(&d_connectionStartTime, nullptr);