mirror of
https://github.com/glest/glest-source.git
synced 2025-08-10 18:34:05 +02:00
attempt to fix crash of irc client on exit
This commit is contained in:
@@ -58,6 +58,8 @@ protected:
|
|||||||
static const char *globalCacheContainerName;
|
static const char *globalCacheContainerName;
|
||||||
|
|
||||||
std::vector<string> argv;
|
std::vector<string> argv;
|
||||||
|
|
||||||
|
Mutex mutexIRCSession;
|
||||||
irc_session_t *ircSession;
|
irc_session_t *ircSession;
|
||||||
|
|
||||||
string execute_cmd_onconnect;
|
string execute_cmd_onconnect;
|
||||||
@@ -79,6 +81,8 @@ protected:
|
|||||||
|
|
||||||
bool wantToLeaveChannel;
|
bool wantToLeaveChannel;
|
||||||
|
|
||||||
|
int irc_run_session(irc_session_t * session);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IRCThread(const std::vector<string> &argv,IRCCallbackInterface *callbackObj);
|
IRCThread(const std::vector<string> &argv,IRCCallbackInterface *callbackObj);
|
||||||
|
@@ -50,6 +50,20 @@ using namespace Shared::PlatformCommon;
|
|||||||
|
|
||||||
namespace Shared { namespace Platform {
|
namespace Shared { namespace Platform {
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#define PLATFORM_SOCKET_TRY_AGAIN WSAEWOULDBLOCK
|
||||||
|
#define PLATFORM_SOCKET_INPROGRESS WSAEINPROGRESS
|
||||||
|
#define PLATFORM_SOCKET_INTERRUPTED WSAEWOULDBLOCK
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define PLATFORM_SOCKET_TRY_AGAIN EAGAIN
|
||||||
|
#define PLATFORM_SOCKET_INPROGRESS EINPROGRESS
|
||||||
|
#define PLATFORM_SOCKET_INTERRUPTED EINTR
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// The callback Interface used by the UPNP discovery process
|
// The callback Interface used by the UPNP discovery process
|
||||||
class FTPClientValidationInterface {
|
class FTPClientValidationInterface {
|
||||||
public:
|
public:
|
||||||
@@ -137,6 +151,10 @@ public:
|
|||||||
Socket();
|
Socket();
|
||||||
virtual ~Socket();
|
virtual ~Socket();
|
||||||
|
|
||||||
|
static int getLastSocketError();
|
||||||
|
static const char * getLastSocketErrorText(int *errNumber=NULL);
|
||||||
|
static string getLastSocketErrorFormattedText(int *errNumber=NULL);
|
||||||
|
|
||||||
static bool disableNagle;
|
static bool disableNagle;
|
||||||
static int DEFAULT_SOCKET_SENDBUF_SIZE;
|
static int DEFAULT_SOCKET_SENDBUF_SIZE;
|
||||||
static int DEFAULT_SOCKET_RECVBUF_SIZE;
|
static int DEFAULT_SOCKET_RECVBUF_SIZE;
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "ircclient.h"
|
#include "ircclient.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "cache_manager.h"
|
#include "cache_manager.h"
|
||||||
|
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
@@ -475,11 +476,18 @@ IRCThread::IRCThread(const std::vector<string> &argv, IRCCallbackInterface *call
|
|||||||
|
|
||||||
void IRCThread::disconnect() {
|
void IRCThread::disconnect() {
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
if(ircSession != NULL) {
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(validSession == true) {
|
||||||
setCallbackObj(NULL);
|
setCallbackObj(NULL);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n");
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
irc_disconnect(ircSession);
|
irc_disconnect(ircSession);
|
||||||
|
safeMutex1.ReleaseLock();
|
||||||
|
|
||||||
BaseThread::signalQuit();
|
BaseThread::signalQuit();
|
||||||
hasJoinedChannel = false;
|
hasJoinedChannel = false;
|
||||||
@@ -493,11 +501,18 @@ void IRCThread::signalQuit() {
|
|||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: signalQuit [%p]\n",ircSession);
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: signalQuit [%p]\n",ircSession);
|
||||||
|
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
if(ircSession != NULL) {
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(validSession == true) {
|
||||||
setCallbackObj(NULL);
|
setCallbackObj(NULL);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n");
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
irc_cmd_quit(ircSession, "MG Bot is closing!");
|
irc_cmd_quit(ircSession, "MG Bot is closing!");
|
||||||
|
safeMutex1.ReleaseLock();
|
||||||
|
|
||||||
BaseThread::signalQuit();
|
BaseThread::signalQuit();
|
||||||
hasJoinedChannel = false;
|
hasJoinedChannel = false;
|
||||||
@@ -515,11 +530,17 @@ bool IRCThread::shutdownAndWait() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IRCThread::SendIRCCmdMessage(string target, string msg) {
|
void IRCThread::SendIRCCmdMessage(string target, string msg) {
|
||||||
if(ircSession != NULL && hasJoinedChannel == true) {
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(validSession == true && hasJoinedChannel == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str());
|
||||||
|
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
int ret = irc_cmd_msg (ircSession, target.c_str(), msg.c_str());
|
int ret = irc_cmd_msg (ircSession, target.c_str(), msg.c_str());
|
||||||
|
safeMutex1.ReleaseLock();
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str(),ret);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str(),ret);
|
||||||
#endif
|
#endif
|
||||||
@@ -528,11 +549,19 @@ void IRCThread::SendIRCCmdMessage(string target, string msg) {
|
|||||||
|
|
||||||
std::vector<string> IRCThread::GetIRCConnectedNickList(string target, bool waitForCompletion) {
|
std::vector<string> IRCThread::GetIRCConnectedNickList(string target, bool waitForCompletion) {
|
||||||
eventDataDone = false;
|
eventDataDone = false;
|
||||||
if(ircSession != NULL && hasJoinedChannel == true) {
|
|
||||||
|
MutexSafeWrapper safeMutexSession(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
safeMutexSession.ReleaseLock();
|
||||||
|
|
||||||
|
if(validSession == true && hasJoinedChannel == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str());
|
||||||
|
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
int ret = irc_cmd_names (ircSession, target.c_str());
|
int ret = irc_cmd_names (ircSession, target.c_str());
|
||||||
|
safeMutex1.ReleaseLock();
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),ret);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),ret);
|
||||||
|
|
||||||
@@ -556,10 +585,16 @@ std::vector<string> IRCThread::GetIRCConnectedNickList(string target, bool waitF
|
|||||||
|
|
||||||
bool IRCThread::isConnected() {
|
bool IRCThread::isConnected() {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if(ircSession != NULL) {
|
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(validSession == true) {
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
ret = (irc_is_connected(ircSession) != 0);
|
ret = (irc_is_connected(ircSession) != 0);
|
||||||
|
safeMutex1.ReleaseLock();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,7 +635,10 @@ void IRCThread::execute() {
|
|||||||
try {
|
try {
|
||||||
#if !defined(DISABLE_IRCCLIENT)
|
#if !defined(DISABLE_IRCCLIENT)
|
||||||
irc_callbacks_t callbacks;
|
irc_callbacks_t callbacks;
|
||||||
ircSession=NULL;
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
ircSession=NULL;
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(argv.size() != 5) {
|
if(argv.size() != 5) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Usage: <server> <nick> <channel> : got params [%ld]\n",(long int)argv.size());
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Usage: <server> <nick> <channel> : got params [%ld]\n",(long int)argv.size());
|
||||||
@@ -633,12 +671,16 @@ void IRCThread::execute() {
|
|||||||
if(this->getQuitStatus() == true) {
|
if(this->getQuitStatus() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
safeMutex.Lock();
|
||||||
ircSession = irc_create_session (&callbacks);
|
ircSession = irc_create_session (&callbacks);
|
||||||
|
bool validSession = (ircSession != NULL);
|
||||||
|
|
||||||
if(!ircSession) {
|
if(validSession == false) {
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not create session\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not create session\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
// this->execute_cmd_onconnect = "";
|
// this->execute_cmd_onconnect = "";
|
||||||
// if(argv.size() >= 5) {
|
// if(argv.size() >= 5) {
|
||||||
@@ -655,16 +697,22 @@ void IRCThread::execute() {
|
|||||||
}
|
}
|
||||||
this->channel = argv[2];
|
this->channel = argv[2];
|
||||||
this->nick = argv[1];
|
this->nick = argv[1];
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
irc_set_ctx(ircSession, this);
|
irc_set_ctx(ircSession, this);
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(this->getQuitStatus() == true) {
|
if(this->getQuitStatus() == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
if(irc_connect(ircSession, argv[0].c_str(), IRC_SERVER_PORT, 0, this->nick.c_str(), this->username.c_str(), "megaglest")) {
|
if(irc_connect(ircSession, argv[0].c_str(), IRC_SERVER_PORT, 0, this->nick.c_str(), this->username.c_str(), "megaglest")) {
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession)));
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
if(this->getQuitStatus() == true) {
|
if(this->getQuitStatus() == true) {
|
||||||
return;
|
return;
|
||||||
@@ -677,7 +725,8 @@ void IRCThread::execute() {
|
|||||||
for(int iAttempts=1;
|
for(int iAttempts=1;
|
||||||
this->getQuitStatus() == false && iAttempts <= 5;
|
this->getQuitStatus() == false && iAttempts <= 5;
|
||||||
++iAttempts) {
|
++iAttempts) {
|
||||||
if(irc_run(ircSession)) {
|
//if(irc_run(ircSession)) {
|
||||||
|
if(irc_run_session(ircSession)) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not run the session: %s\n", irc_strerror (irc_errno(ircSession)));
|
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not run the session: %s\n", irc_strerror (irc_errno(ircSession)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -713,6 +762,53 @@ void IRCThread::execute() {
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IRCThread::irc_run_session(irc_session_t * session) {
|
||||||
|
// if ( session->state != LIBIRC_STATE_CONNECTING )
|
||||||
|
// {
|
||||||
|
// session->lasterror = LIBIRC_ERR_STATE;
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ( isConnected() == false ) {
|
||||||
|
//session->lasterror = LIBIRC_ERR_STATE;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( isConnected() == true ) {
|
||||||
|
struct timeval tv;
|
||||||
|
fd_set in_set, out_set;
|
||||||
|
int maxfd = 0;
|
||||||
|
|
||||||
|
tv.tv_usec = 250000;
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
|
||||||
|
// Init sets
|
||||||
|
FD_ZERO (&in_set);
|
||||||
|
FD_ZERO (&out_set);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
irc_add_select_descriptors (session, &in_set, &out_set, &maxfd);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if ( select (maxfd + 1, &in_set, &out_set, 0, &tv) < 0 ) {
|
||||||
|
int lastSocketError = Socket::getLastSocketError();
|
||||||
|
if ( lastSocketError == PLATFORM_SOCKET_INTERRUPTED ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//session->lasterror = LIBIRC_ERR_TERMINATED;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex1(&mutexIRCSession,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
if ( irc_process_select_descriptors (session, &in_set, &out_set) ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
IRCThread::~IRCThread() {
|
IRCThread::~IRCThread() {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In ~IRCThread() ...\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In ~IRCThread() ...\n");
|
||||||
|
|
||||||
|
@@ -91,9 +91,10 @@ Mutex UPNP_Tools::mutexUPNP;
|
|||||||
|
|
||||||
#define socklen_t int
|
#define socklen_t int
|
||||||
#define MAXHOSTNAME 254
|
#define MAXHOSTNAME 254
|
||||||
#define PLATFORM_SOCKET_TRY_AGAIN WSAEWOULDBLOCK
|
|
||||||
#define PLATFORM_SOCKET_INPROGRESS WSAEINPROGRESS
|
//#define PLATFORM_SOCKET_TRY_AGAIN WSAEWOULDBLOCK
|
||||||
#define PLATFORM_SOCKET_INTERRUPTED WSAEWOULDBLOCK
|
//#define PLATFORM_SOCKET_INPROGRESS WSAEINPROGRESS
|
||||||
|
//#define PLATFORM_SOCKET_INTERRUPTED WSAEWOULDBLOCK
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
|
|
||||||
//// Constants /////////////////////////////////////////////////////////
|
//// Constants /////////////////////////////////////////////////////////
|
||||||
@@ -246,13 +247,13 @@ Mutex UPNP_Tools::mutexUPNP;
|
|||||||
typedef UINT_PTR SOCKET;
|
typedef UINT_PTR SOCKET;
|
||||||
#define INVALID_SOCKET (SOCKET)(~0)
|
#define INVALID_SOCKET (SOCKET)(~0)
|
||||||
|
|
||||||
#define PLATFORM_SOCKET_TRY_AGAIN EAGAIN
|
//#define PLATFORM_SOCKET_TRY_AGAIN EAGAIN
|
||||||
#define PLATFORM_SOCKET_INPROGRESS EINPROGRESS
|
//#define PLATFORM_SOCKET_INPROGRESS EINPROGRESS
|
||||||
#define PLATFORM_SOCKET_INTERRUPTED EINTR
|
//#define PLATFORM_SOCKET_INTERRUPTED EINTR
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int getLastSocketError() {
|
int Socket::getLastSocketError() {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
return errno;
|
return errno;
|
||||||
#else
|
#else
|
||||||
@@ -260,7 +261,7 @@ int getLastSocketError() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getLastSocketErrorText(int *errNumber=NULL) {
|
const char * Socket::getLastSocketErrorText(int *errNumber) {
|
||||||
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
return strerror(errId);
|
return strerror(errId);
|
||||||
@@ -269,7 +270,7 @@ const char * getLastSocketErrorText(int *errNumber=NULL) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
string getLastSocketErrorFormattedText(int *errNumber=NULL) {
|
string Socket::getLastSocketErrorFormattedText(int *errNumber) {
|
||||||
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
||||||
string msg = "(Error: " + intToStr(errId) + " - [" + string(getLastSocketErrorText(&errId)) +"])";
|
string msg = "(Error: " + intToStr(errId) + " - [" + string(getLastSocketErrorText(&errId)) +"])";
|
||||||
return msg;
|
return msg;
|
||||||
@@ -2039,7 +2040,7 @@ void BroadCastClientSocketThread::execute() {
|
|||||||
// Prepare to receive the broadcast.
|
// Prepare to receive the broadcast.
|
||||||
bcfd = socket(AF_INET, SOCK_DGRAM, 0);
|
bcfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if( bcfd <= 0 ) {
|
if( bcfd <= 0 ) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"socket failed: %s\n", getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"socket failed: %s\n", Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create the address we are receiving on.
|
// Create the address we are receiving on.
|
||||||
@@ -2055,7 +2056,7 @@ void BroadCastClientSocketThread::execute() {
|
|||||||
setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
|
setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
|
||||||
#endif
|
#endif
|
||||||
if(::bind( bcfd, (struct sockaddr *)&bcaddr, sizeof(bcaddr) ) < 0 ) {
|
if(::bind( bcfd, (struct sockaddr *)&bcaddr, sizeof(bcaddr) ) < 0 ) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"bind failed: %s\n", getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"bind failed: %s\n", Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -2074,7 +2075,7 @@ void BroadCastClientSocketThread::execute() {
|
|||||||
//printf("Broadcasting client nb = %d buff [%s] gotData = %d\n",nb,buff,gotData);
|
//printf("Broadcasting client nb = %d buff [%s] gotData = %d\n",nb,buff,gotData);
|
||||||
|
|
||||||
if(gotData == false) {
|
if(gotData == false) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"recvfrom failed: %s\n", getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"recvfrom failed: %s\n", Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//string fromIP = inet_ntoa(bcSender.sin_addr);
|
//string fromIP = inet_ntoa(bcSender.sin_addr);
|
||||||
@@ -2871,12 +2872,12 @@ void BroadCastSocketThread::execute() {
|
|||||||
bcfd[idx] = socket( AF_INET, SOCK_DGRAM, 0 );
|
bcfd[idx] = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||||
|
|
||||||
if( bcfd[idx] <= 0 ) {
|
if( bcfd[idx] <= 0 ) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Unable to allocate broadcast socket [%s]: %s\n", ipSubnetMaskList[idx].c_str(), getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Unable to allocate broadcast socket [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
//exit(-1);
|
//exit(-1);
|
||||||
}
|
}
|
||||||
// Mark the socket for broadcast.
|
// Mark the socket for broadcast.
|
||||||
else if( setsockopt( bcfd[idx], SOL_SOCKET, SO_BROADCAST, (const char *) &one, sizeof( int ) ) < 0 ) {
|
else if( setsockopt( bcfd[idx], SOL_SOCKET, SO_BROADCAST, (const char *) &one, sizeof( int ) ) < 0 ) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Could not set socket to broadcast [%s]: %s\n", ipSubnetMaskList[idx].c_str(), getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Could not set socket to broadcast [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
//exit(-1);
|
//exit(-1);
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
@@ -2912,7 +2913,7 @@ void BroadCastSocketThread::execute() {
|
|||||||
|
|
||||||
ssize_t send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) );
|
ssize_t send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) );
|
||||||
if( send_res != buffMaxSize ) {
|
if( send_res != buffMaxSize ) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Sendto error: %s\n", getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Sendto error: %s\n", Socket::getLastSocketErrorFormattedText().c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcasting on port [%d] the message: [%s]\n",Socket::getBroadCastPort(),buff);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcasting on port [%d] the message: [%s]\n",Socket::getBroadCastPort(),buff);
|
||||||
|
Reference in New Issue
Block a user