Merge branch 'development' into LTS_development
This commit is contained in:
commit
f90f261116
4 changed files with 42 additions and 24 deletions
|
@ -467,7 +467,7 @@ void Util::Config::activate() {
|
||||||
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
|
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
|
||||||
/// signal, and ignores all other signals.
|
/// signal, and ignores all other signals.
|
||||||
void Util::Config::signal_handler(int signum, siginfo_t * sigInfo, void * ignore) {
|
void Util::Config::signal_handler(int signum, siginfo_t * sigInfo, void * ignore) {
|
||||||
HIGH_MSG("Received signal %d from process %d", signum, sigInfo->si_pid);
|
HIGH_MSG("Received signal %s (%d) from process %d", strsignal(signum), signum, sigInfo->si_pid);
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
case SIGINT: //these three signals will set is_active to false.
|
case SIGINT: //these three signals will set is_active to false.
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
|
|
|
@ -354,7 +354,7 @@ namespace IPC {
|
||||||
} while (i < 10 && !handle && autoBackoff);
|
} while (i < 10 && !handle && autoBackoff);
|
||||||
}
|
}
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
FAIL_MSG("%s for page %s failed with error code %u", (master ? "CreateFileMapping" : "OpenFileMapping"), name.c_str(), GetLastError());
|
MEDIUM_MSG("%s for page %s failed with error code %u", (master ? "CreateFileMapping" : "OpenFileMapping"), name.c_str(), GetLastError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mapped = (char *)MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
mapped = (char *)MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||||
|
|
|
@ -971,9 +971,11 @@ int Socket::Server::getSocket() {
|
||||||
/// If both fail, prints an DLVL_FAIL debug message.
|
/// If both fail, prints an DLVL_FAIL debug message.
|
||||||
/// \param nonblock Whether the socket should be nonblocking.
|
/// \param nonblock Whether the socket should be nonblocking.
|
||||||
Socket::UDPConnection::UDPConnection(bool nonblock) {
|
Socket::UDPConnection::UDPConnection(bool nonblock) {
|
||||||
|
isIPv6 = true;
|
||||||
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
isIPv6 = false;
|
||||||
}
|
}
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
DEBUG_MSG(DLVL_FAIL, "Could not create UDP socket: %s", strerror(errno));
|
DEBUG_MSG(DLVL_FAIL, "Could not create UDP socket: %s", strerror(errno));
|
||||||
|
@ -993,9 +995,17 @@ Socket::UDPConnection::UDPConnection(bool nonblock) {
|
||||||
/// Copies a UDP socket, re-allocating local copies of any needed structures.
|
/// Copies a UDP socket, re-allocating local copies of any needed structures.
|
||||||
/// The data/data_size/data_len variables are *not* copied over.
|
/// The data/data_size/data_len variables are *not* copied over.
|
||||||
Socket::UDPConnection::UDPConnection(const UDPConnection & o) {
|
Socket::UDPConnection::UDPConnection(const UDPConnection & o) {
|
||||||
|
isIPv6 = true;
|
||||||
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
isIPv6 = false;
|
||||||
|
}else{
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
// Under windows, turn IPv6-only mode off.
|
||||||
|
int on = 0;
|
||||||
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
DEBUG_MSG(DLVL_FAIL, "Could not create UDP socket: %s", strerror(errno));
|
DEBUG_MSG(DLVL_FAIL, "Could not create UDP socket: %s", strerror(errno));
|
||||||
|
@ -1134,30 +1144,37 @@ void Socket::UDPConnection::SendNow(const char * sdata, size_t len) {
|
||||||
/// If that fails too, gives up and returns zero.
|
/// If that fails too, gives up and returns zero.
|
||||||
/// Prints a debug message at DLVL_FAIL level if binding failed.
|
/// Prints a debug message at DLVL_FAIL level if binding failed.
|
||||||
/// \return Actually bound port number, or zero on error.
|
/// \return Actually bound port number, or zero on error.
|
||||||
int Socket::UDPConnection::bind(int port) {
|
int Socket::UDPConnection::bind(int port, std::string iface) {
|
||||||
struct sockaddr_in6 s6;
|
if (isIPv6){
|
||||||
s6.sin6_family = AF_INET6;
|
struct sockaddr_in6 s6;
|
||||||
s6.sin6_addr = in6addr_any;
|
memset(&s6, 0, sizeof(s6));
|
||||||
if (port) {
|
s6.sin6_family = AF_INET6;
|
||||||
|
if (iface == "0.0.0.0" || iface.length() == 0) {
|
||||||
|
s6.sin6_addr = in6addr_any;
|
||||||
|
} else {
|
||||||
|
inet_pton(AF_INET6, iface.c_str(), &s6.sin6_addr);
|
||||||
|
}
|
||||||
s6.sin6_port = htons(port);
|
s6.sin6_port = htons(port);
|
||||||
}
|
int r = ::bind(sock, (sockaddr *)&s6, sizeof(s6));
|
||||||
int r = ::bind(sock, (sockaddr *)&s6, sizeof(s6));
|
if (r == 0) {
|
||||||
if (r == 0) {
|
return ntohs(s6.sin6_port);
|
||||||
return ntohs(s6.sin6_port);
|
}
|
||||||
}
|
}else{
|
||||||
|
struct sockaddr_in s4;
|
||||||
struct sockaddr_in s4;
|
memset(&s4, 0, sizeof(s4));
|
||||||
s4.sin_family = AF_INET;
|
s4.sin_family = AF_INET;
|
||||||
s4.sin_addr.s_addr = INADDR_ANY;
|
if (iface == "0.0.0.0" || iface.length() == 0) {
|
||||||
if (port) {
|
s4.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
} else {
|
||||||
|
inet_pton(AF_INET, iface.c_str(), &s4.sin_addr);
|
||||||
|
}
|
||||||
s4.sin_port = htons(port);
|
s4.sin_port = htons(port);
|
||||||
|
int r = ::bind(sock, (sockaddr *)&s4, sizeof(s4));
|
||||||
|
if (r == 0) {
|
||||||
|
return ntohs(s4.sin_port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
r = ::bind(sock, (sockaddr *)&s4, sizeof(s4));
|
DEBUG_MSG(DLVL_FAIL, "Could not bind %s UDP socket to port %d: %s", isIPv6?"IPv6":"IPv4", port, strerror(errno));
|
||||||
if (r == 0) {
|
|
||||||
return ntohs(s4.sin_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG_MSG(DLVL_FAIL, "Could not bind UDP socket to port %d", port);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@ namespace Socket {
|
||||||
unsigned int up;///< Amount of bytes transferred up.
|
unsigned int up;///< Amount of bytes transferred up.
|
||||||
unsigned int down;///< Amount of bytes transferred down.
|
unsigned int down;///< Amount of bytes transferred down.
|
||||||
unsigned int data_size;///< The size in bytes of the allocated space in the data pointer.
|
unsigned int data_size;///< The size in bytes of the allocated space in the data pointer.
|
||||||
|
bool isIPv6;//<<< True if IPv6 socket, false otherwise.
|
||||||
public:
|
public:
|
||||||
char * data;///< Holds the last received packet.
|
char * data;///< Holds the last received packet.
|
||||||
unsigned int data_len; ///< The size in bytes of the last received packet.
|
unsigned int data_len; ///< The size in bytes of the last received packet.
|
||||||
|
@ -136,7 +137,7 @@ namespace Socket {
|
||||||
UDPConnection(bool nonblock = false);
|
UDPConnection(bool nonblock = false);
|
||||||
~UDPConnection();
|
~UDPConnection();
|
||||||
int getSock();
|
int getSock();
|
||||||
int bind(int port);
|
int bind(int port, std::string iface = "");
|
||||||
void setBlocking(bool blocking);
|
void setBlocking(bool blocking);
|
||||||
void SetDestination(std::string hostname, uint32_t port);
|
void SetDestination(std::string hostname, uint32_t port);
|
||||||
void GetDestination(std::string & hostname, uint32_t & port);
|
void GetDestination(std::string & hostname, uint32_t & port);
|
||||||
|
|
Loading…
Add table
Reference in a new issue