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:
lotodore
2007-09-30 13:15:52 +00:00
parent c33bf3a3d6
commit 5edf38a6cb
15 changed files with 69 additions and 14 deletions
-1
View File
@@ -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;
+46 -3
View File
@@ -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);
}
}
+4
View File
@@ -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>
+1
View File
@@ -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)
{
}
-1
View File
@@ -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);
-1
View File
@@ -21,7 +21,6 @@
#define _GENERICSOCKET_H_
#ifdef _WIN32
#define FD_SETSIZE 512
#include <winsock2.h>
#include <ws2tcpip.h>
#else
+4 -1
View File
@@ -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
-2
View File
@@ -28,8 +28,6 @@
#include <deque>
#include <boost/shared_ptr.hpp>
#define RECV_TIMEOUT_MSEC 50
class ReceiverHelper
{
public:
+2
View File
@@ -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