Fixed some msvc problems with libircclient. Fixed auto start boost timer issue. Fixed irc thread termination (this time for real). Using strdup and free on MSVC causes "heap corruption error" in debug mode - use _strdup instead in libircclient.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
// Speeds up compilation a bit on msvc
|
||||
#if (defined _MSC_VER) && (_MSC_VER >= 1200)
|
||||
#pragma once
|
||||
#define _WINSOCKAPI_
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include <sys/select.h> /* fd_set */
|
||||
#include <netinet/in.h> /* sockaddr_in */
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* $Id: libircclient.c 42 2004-10-10 16:16:15Z gyunaev $
|
||||
*/
|
||||
|
||||
|
||||
#include "portable.c"
|
||||
#include "sockets.c"
|
||||
|
||||
@@ -25,6 +26,11 @@
|
||||
#include "colors.c"
|
||||
#include "dcc.c"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#undef strdup
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#define IS_DEBUG_ENABLED(s) ((s)->option & LIBIRC_OPTION_DEBUG)
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -249,7 +249,6 @@ ClientStateStartConnect::Process(ClientThread &client)
|
||||
if (errCode == SOCKET_ERR_WOULDBLOCK)
|
||||
{
|
||||
boost::timers::portable::microsec_timer connectTimer;
|
||||
connectTimer.start();
|
||||
ClientStateConnecting::Instance().SetTimer(connectTimer);
|
||||
client.SetState(ClientStateConnecting::Instance());
|
||||
retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
|
||||
#include <net/ircthread.h>
|
||||
|
||||
#include <net/socket_helper.h>
|
||||
#include <libircclient.h>
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define IRC_WAIT_TERMINATION_MSEC 500
|
||||
|
||||
struct IrcContext
|
||||
{
|
||||
IrcContext(IrcThread &t) : ircThread(t), session(NULL), serverPort(0) {}
|
||||
@@ -137,7 +140,7 @@ irc_event_numeric(irc_session_t * session, unsigned irc_event, const char *origi
|
||||
}
|
||||
|
||||
IrcThread::IrcThread(IrcCallback &callback)
|
||||
: m_callback(callback)
|
||||
: m_callback(callback), m_terminationTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
|
||||
{
|
||||
m_context.reset(new IrcContext(*this));
|
||||
}
|
||||
@@ -212,14 +215,54 @@ void
|
||||
IrcThread::Main()
|
||||
{
|
||||
IrcContext &context = GetContext();
|
||||
|
||||
irc_session_t *s = context.session;
|
||||
if (s)
|
||||
{
|
||||
if (irc_connect(s, context.serverAddress.c_str(), context.serverPort, 0, context.nick.c_str(), 0, 0) == 0)
|
||||
{
|
||||
if (!ShouldTerminate())
|
||||
irc_run(s);
|
||||
// Main loop.
|
||||
while (irc_is_connected(s))
|
||||
{
|
||||
// Handle thread termination - gracefully.
|
||||
if (!m_terminationTimer.is_running())
|
||||
{
|
||||
if (ShouldTerminate())
|
||||
m_terminationTimer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_terminationTimer.elapsed().total_milliseconds() > IRC_WAIT_TERMINATION_MSEC)
|
||||
break;
|
||||
}
|
||||
|
||||
struct timeval timeout;
|
||||
fd_set readSet, writeSet;
|
||||
int maxfd = 0;
|
||||
|
||||
|
||||
FD_ZERO(&readSet);
|
||||
FD_ZERO(&writeSet);
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = RECV_TIMEOUT_MSEC * 1000;
|
||||
|
||||
irc_add_select_descriptors(s, &readSet, &writeSet, &maxfd);
|
||||
|
||||
int selectResult = select(maxfd + 1, &readSet, &writeSet, 0, &timeout);
|
||||
if (!IS_VALID_SELECT(selectResult))
|
||||
{
|
||||
//todo
|
||||
break;
|
||||
}
|
||||
|
||||
if (irc_process_select_descriptors(s, &readSet, &writeSet) != 0)
|
||||
{
|
||||
//todo
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
irc_destroy_session(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FD_SETSIZE 512
|
||||
#endif
|
||||
|
||||
#include <net/receiverhelper.h>
|
||||
#include <net/socket_msg.h>
|
||||
#include <net/netexception.h>
|
||||
|
||||
@@ -190,6 +190,7 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AbstractServerGameStateTimer::AbstractServerGameStateTimer()
|
||||
: m_timer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ ServerLobbyThread::CloseSessionDelayed(SessionWrapper session)
|
||||
m_gameSessionManager.RemoveSession(session.sessionData->GetSocket());
|
||||
|
||||
boost::timers::portable::microsec_timer closeTimer;
|
||||
closeTimer.start();
|
||||
CloseSessionList::value_type closeSessionData(closeTimer, session.sessionData);
|
||||
|
||||
boost::mutex::scoped_lock lock(m_closeSessionListMutex);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#define _GENERICSOCKET_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FD_SETSIZE 512
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
|
||||
+4
-1
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <net/irccallback.h>
|
||||
#include <core/thread.h>
|
||||
#include <core/boost/timers.hpp>
|
||||
#include <string>
|
||||
|
||||
struct IrcContext;
|
||||
@@ -52,8 +53,10 @@ protected:
|
||||
IrcContext &GetContext();
|
||||
|
||||
private:
|
||||
std::auto_ptr<IrcContext> m_context;
|
||||
boost::shared_ptr<IrcContext> m_context;
|
||||
IrcCallback &m_callback;
|
||||
|
||||
boost::timers::portable::microsec_timer m_terminationTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <deque>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#define RECV_TIMEOUT_MSEC 50
|
||||
|
||||
class ReceiverHelper
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -69,6 +69,8 @@ typedef unsigned char u_char;
|
||||
#define IS_VALID_SEND(_s) ((_s) != SOCKET_ERROR)
|
||||
#define IS_VALID_SELECT(_s) ((_s) != SOCKET_ERROR)
|
||||
|
||||
#define RECV_TIMEOUT_MSEC 50
|
||||
|
||||
#ifdef IPPROTO_SCTP
|
||||
#define SOCKET_IPPROTO_SCTP IPPROTO_SCTP
|
||||
#else
|
||||
|
||||
+2
-2
@@ -66,14 +66,14 @@ PlayerData::SetAvatarFile(const std::string &avatarFile)
|
||||
boost::shared_ptr<SessionData>
|
||||
PlayerData::GetNetSessionData() const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
// setting/getting boost::shared_ptr is thread safe.
|
||||
return m_netSessionData;
|
||||
}
|
||||
|
||||
void
|
||||
PlayerData::SetNetSessionData(boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
// setting/getting boost::shared_ptr is thread safe.
|
||||
m_netSessionData = session;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
|
||||
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 1000
|
||||
#define NET_SERVER_TERMINATE_TIMEOUT_MSEC 2000
|
||||
#define NET_IRC_TERMINATE_TIMEOUT_MSEC 5000
|
||||
#define NET_IRC_TERMINATE_TIMEOUT_MSEC 2000
|
||||
|
||||
#define NET_DEFAULT_GAME "default"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user