|
From: <arn...@us...> - 2008-03-07 23:02:07
|
Revision: 1030
http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1030&view=rev
Author: arnetheduck
Date: 2008-03-07 15:01:59 -0800 (Fri, 07 Mar 2008)
Log Message:
-----------
Clean up socket thread handling, hopefully fixing network crash
Modified Paths:
--------------
dcplusplus/trunk/dcpp/AdcHub.cpp
dcplusplus/trunk/dcpp/AdcHub.h
dcplusplus/trunk/dcpp/BufferedSocket.cpp
dcplusplus/trunk/dcpp/BufferedSocket.h
dcplusplus/trunk/dcpp/Client.cpp
dcplusplus/trunk/dcpp/Client.h
dcplusplus/trunk/dcpp/ClientManager.cpp
dcplusplus/trunk/dcpp/ClientManager.h
dcplusplus/trunk/dcpp/NmdcHub.cpp
dcplusplus/trunk/dcpp/NmdcHub.h
dcplusplus/trunk/dcpp/Speaker.h
dcplusplus/trunk/dcpp/Thread.h
dcplusplus/trunk/dcpp/stdinc.h
dcplusplus/trunk/win32/AspectStatus.h
dcplusplus/trunk/win32/DirectoryListingFrame.cpp
dcplusplus/trunk/win32/TypedTreeView.h
dcplusplus/trunk/win32/UsersFrame.cpp
dcplusplus/trunk/win32/WinUtil.cpp
Modified: dcplusplus/trunk/dcpp/AdcHub.cpp
===================================================================
--- dcplusplus/trunk/dcpp/AdcHub.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/AdcHub.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -204,7 +204,7 @@
if(!baseOk) {
fire(ClientListener::StatusMessage(), this, _("Failed to negotiate base protocol"));
- socket->disconnect(false);
+ disconnect(false);
return;
} else if(!tigrOk) {
oldPassword = true;
@@ -441,6 +441,7 @@
udp.writeTo(ip, port, command);
} catch(const SocketException& e) {
dcdebug("AdcHub::sendUDP: write failed: %s\n", e.getError().c_str());
+ udp.close();
}
}
Modified: dcplusplus/trunk/dcpp/AdcHub.h
===================================================================
--- dcplusplus/trunk/dcpp/AdcHub.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/AdcHub.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -21,8 +21,7 @@
#include "Client.h"
#include "AdcCommand.h"
-#include "TimerManager.h"
-#include "User.h"
+#include "Socket.h"
namespace dcpp {
Modified: dcplusplus/trunk/dcpp/BufferedSocket.cpp
===================================================================
--- dcplusplus/trunk/dcpp/BufferedSocket.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/BufferedSocket.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -34,18 +34,18 @@
// Polling is used for tasks...should be fixed...
#define POLL_TIMEOUT 250
-BufferedSocket::BufferedSocket(char aSeparator) throw() :
-separator(aSeparator), mode(MODE_LINE), filterIn(NULL),
-dataBytes(0), rollback(0), failed(false), sock(0), disconnecting(false)
+BufferedSocket::BufferedSocket(char aSeparator) throw(ThreadException) :
+separator(aSeparator), mode(MODE_LINE), dataBytes(0), rollback(0), disconnecting(false),
+state(STARTING)
{
+ start();
+
Thread::safeInc(sockets);
}
volatile long BufferedSocket::sockets = 0;
BufferedSocket::~BufferedSocket() throw() {
- delete sock;
- delete filterIn;
Thread::safeDec(sockets);
}
@@ -55,89 +55,66 @@
return;
}
- if (mode == MODE_ZPIPE) {
- // should not happen!
- if (filterIn) {
- delete filterIn;
- filterIn = NULL;
- }
- }
-
- mode = aMode;
switch (aMode) {
case MODE_LINE:
rollback = aRollback;
break;
case MODE_ZPIPE:
- filterIn = new UnZFilter;
+ filterIn = std::auto_ptr<UnZFilter>(new UnZFilter);
break;
case MODE_DATA:
break;
}
+ mode = aMode;
}
-void BufferedSocket::accept(const Socket& srv, bool secure, bool allowUntrusted) throw(SocketException, ThreadException) {
- dcassert(!sock);
- try {
- dcdebug("BufferedSocket::accept() %p\n", (void*)this);
- sock = secure ? CryptoManager::getInstance()->getServerSocket(allowUntrusted) : new Socket;
+void BufferedSocket::setSocket(std::auto_ptr<Socket> s) {
+ dcassert(!sock.get());
+ if(SETTING(SOCKET_IN_BUFFER) > 0)
+ s->setSocketOpt(SO_RCVBUF, SETTING(SOCKET_IN_BUFFER));
+ if(SETTING(SOCKET_OUT_BUFFER) > 0)
+ s->setSocketOpt(SO_SNDBUF, SETTING(SOCKET_OUT_BUFFER));
+ s->setBlocking(false);
- sock->accept(srv);
- if(SETTING(SOCKET_IN_BUFFER) > 0)
- sock->setSocketOpt(SO_RCVBUF, SETTING(SOCKET_IN_BUFFER));
- if(SETTING(SOCKET_OUT_BUFFER) > 0)
- sock->setSocketOpt(SO_SNDBUF, SETTING(SOCKET_OUT_BUFFER));
- sock->setBlocking(false);
+ inbuf.resize(s->getSocketOptInt(SO_RCVBUF));
+
+ sock = s;
+}
- inbuf.resize(sock->getSocketOptInt(SO_RCVBUF));
+void BufferedSocket::accept(const Socket& srv, bool secure, bool allowUntrusted) throw(SocketException) {
+ dcdebug("BufferedSocket::accept() %p\n", (void*)this);
+
+ std::auto_ptr<Socket> s(secure ? CryptoManager::getInstance()->getServerSocket(allowUntrusted) : new Socket);
- // This lock prevents the shutdown task from being added and executed before we're done initializing the socket
- Lock l(cs);
- start();
- addTask(ACCEPTED, 0);
- } catch(...) {
- delete sock;
- sock = 0;
- throw;
- }
-
+ s->accept(srv);
+
+ setSocket(s);
+
+ Lock l(cs);
+ addTask(ACCEPTED, 0);
}
-void BufferedSocket::connect(const string& aAddress, uint16_t aPort, bool secure, bool allowUntrusted, bool proxy) throw(SocketException, ThreadException) {
- dcassert(!sock);
+void BufferedSocket::connect(const string& aAddress, uint16_t aPort, bool secure, bool allowUntrusted, bool proxy) throw(SocketException) {
+ dcdebug("BufferedSocket::connect() %p\n", (void*)this);
+ std::auto_ptr<Socket> s(secure ? CryptoManager::getInstance()->getClientSocket(allowUntrusted) : new Socket);
- try {
- dcdebug("BufferedSocket::connect() %p\n", (void*)this);
- sock = secure ? CryptoManager::getInstance()->getClientSocket(allowUntrusted) : new Socket;
-
- sock->create();
- sock->bind(0, SETTING(BIND_ADDRESS));
- if(SETTING(SOCKET_IN_BUFFER) >= 1024)
- sock->setSocketOpt(SO_RCVBUF, SETTING(SOCKET_IN_BUFFER));
- if(SETTING(SOCKET_OUT_BUFFER) >= 1024)
- sock->setSocketOpt(SO_SNDBUF, SETTING(SOCKET_OUT_BUFFER));
- sock->setBlocking(false);
-
- inbuf.resize(sock->getSocketOptInt(SO_RCVBUF));
-
- Lock l(cs);
- start();
- addTask(CONNECT, new ConnectInfo(aAddress, aPort, proxy && (SETTING(OUTGOING_CONNECTIONS) == SettingsManager::OUTGOING_SOCKS5)));
- } catch(...) {
- delete sock;
- sock = 0;
- throw;
- }
-
+ s->create();
+ s->bind(0, SETTING(BIND_ADDRESS));
+
+ setSocket(s);
+
+ Lock l(cs);
+ addTask(CONNECT, new ConnectInfo(aAddress, aPort, proxy && (SETTING(OUTGOING_CONNECTIONS) == SettingsManager::OUTGOING_SOCKS5)));
}
#define CONNECT_TIMEOUT 30000
void BufferedSocket::threadConnect(const string& aAddr, uint16_t aPort, bool proxy) throw(SocketException) {
+ dcassert(state == STARTING);
+
dcdebug("threadConnect %s:%d\n", aAddr.c_str(), (int)aPort);
- dcassert(sock);
- if(!sock)
- return;
fire(BufferedSocketListener::Connecting());
+
+ state = RUNNING;
uint64_t startTime = GET_TICK();
if(proxy) {
@@ -159,9 +136,9 @@
}
void BufferedSocket::threadRead() throw(SocketException) {
- dcassert(sock);
- if(!sock)
+ if(state != RUNNING)
return;
+
int left = sock->read(&inbuf[0], (int)inbuf.size());
if(left == -1) {
// EWOULDBLOCK, no data received...
@@ -177,8 +154,7 @@
while (left > 0) {
switch (mode) {
- case MODE_ZPIPE:
- if(filterIn) {
+ case MODE_ZPIPE: {
const int BUF_SIZE = 1024;
// Special to autodetect nmdc connections...
string::size_type pos = 0;
@@ -263,9 +239,11 @@
}
void BufferedSocket::threadSendFile(InputStream* file) throw(Exception) {
- dcassert(sock);
- if(!sock || disconnecting)
+ if(state != RUNNING)
return;
+
+ if(disconnecting)
+ return;
dcassert(file != NULL);
size_t sockSize = (size_t)sock->getSocketOptInt(SO_SNDBUF);
size_t bufSize = max(sockSize, (size_t)64*1024);
@@ -347,8 +325,7 @@
}
void BufferedSocket::write(const char* aBuf, size_t aLen) throw() {
- dcassert(sock);
- if(!sock)
+ if(!sock.get())
return;
Lock l(cs);
if(writeBuf.empty())
@@ -358,9 +335,9 @@
}
void BufferedSocket::threadSendData() {
- dcassert(sock);
- if(!sock)
+ if(state != RUNNING)
return;
+
{
Lock l(cs);
if(writeBuf.empty())
@@ -394,59 +371,46 @@
}
bool BufferedSocket::checkEvents() {
- while(isConnected() ? taskSem.wait(0) : taskSem.wait()) {
- pair<Tasks, TaskData*> p;
+ while(state == RUNNING ? taskSem.wait(0) : taskSem.wait()) {
+ pair<Tasks, std::tr1::shared_ptr<TaskData> > p;
{
Lock l(cs);
dcassert(tasks.size() > 0);
p = tasks.front();
tasks.erase(tasks.begin());
}
- if(failed && p.first != SHUTDOWN) {
- dcdebug("BufferedSocket: New command when already failed: %d\n", p.first);
- fail(_("Disconnected"));
- delete p.second;
- continue;
+
+ if(p.first == SHUTDOWN) {
+ return false;
+ } else if(p.first == UPDATED) {
+ fire(BufferedSocketListener::Updated());
}
-
- try {
- switch(p.first) {
- case SEND_DATA:
- threadSendData(); break;
- case SEND_FILE:
- threadSendFile(((SendFileInfo*)p.second)->stream); break;
- case CONNECT:
- {
- ConnectInfo* ci = (ConnectInfo*)p.second;
- threadConnect(ci->addr, ci->port, ci->proxy);
- break;
- }
- case DISCONNECT:
- if(isConnected())
- fail(_("Disconnected"));
- break;
- case SHUTDOWN:
- return false;
- case ACCEPTED:
- break;
- case UPDATED:
- fire(BufferedSocketListener::Updated());
- break;
+
+ if(state == STARTING) {
+ if(p.first == CONNECT) {
+ ConnectInfo* ci = static_cast<ConnectInfo*>(p.second.get());
+ threadConnect(ci->addr, ci->port, ci->proxy);
+ } else if(p.first == ACCEPTED) {
+ state = RUNNING;
+ } else {
+ dcdebug("%d unexpected in STARTING state", p.first);
}
- } catch(...) {
- delete p.second;
- throw;
+ } else if(state == RUNNING) {
+ if(p.first == SEND_DATA) {
+ threadSendData();
+ } else if(p.first == SEND_FILE) {
+ threadSendFile(static_cast<SendFileInfo*>(p.second.get())->stream); break;
+ } else if(p.first == DISCONNECT) {
+ fail(_("Disconnected"));
+ } else {
+ dcdebug("%d unexpected in RUNNING state", p.first);
+ }
}
- delete p.second;
}
return true;
}
void BufferedSocket::checkSocket() {
- dcassert(sock);
- if(!sock)
- return;
-
int waitFor = sock->wait(POLL_TIMEOUT, Socket::WAIT_READ);
if(waitFor & Socket::WAIT_READ) {
@@ -462,9 +426,12 @@
dcdebug("BufferedSocket::run() start %p\n", (void*)this);
while(true) {
try {
- if(!checkEvents())
+ if(!checkEvents()) {
break;
- checkSocket();
+ }
+ if(state == RUNNING) {
+ checkSocket();
+ }
} catch(const Exception& e) {
fail(e.getError());
}
@@ -475,24 +442,23 @@
}
void BufferedSocket::fail(const string& aError) {
- if(sock) {
- sock->disconnect();
- }
- if(!failed) {
- failed = true;
+ sock->disconnect();
+
+ if(state == RUNNING) {
+ state = FAILED;
fire(BufferedSocketListener::Failed(), aError);
}
}
void BufferedSocket::shutdown() {
- if(sock) {
- Lock l(cs);
- disconnecting = true;
- addTask(SHUTDOWN, 0);
- } else {
- // Socket thread not running yet, disconnect...
- delete this;
- }
+ Lock l(cs);
+ disconnecting = true;
+ addTask(SHUTDOWN, 0);
}
+void BufferedSocket::addTask(Tasks task, TaskData* data) {
+ dcassert(task == SHUTDOWN || sock.get());
+ tasks.push_back(make_pair(task, data)); taskSem.signal();
+}
+
} // namespace dcpp
Modified: dcplusplus/trunk/dcpp/BufferedSocket.h
===================================================================
--- dcplusplus/trunk/dcpp/BufferedSocket.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/BufferedSocket.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -29,8 +29,7 @@
namespace dcpp {
-class BufferedSocket : public Speaker<BufferedSocketListener>, public Thread
-{
+class BufferedSocket : public Speaker<BufferedSocketListener>, private Thread {
public:
enum Modes {
MODE_LINE,
@@ -43,7 +42,7 @@
* @param sep Line separator
* @return An unconnected socket
*/
- static BufferedSocket* getSocket(char sep) throw() {
+ static BufferedSocket* getSocket(char sep) throw(ThreadException) {
return new BufferedSocket(sep);
}
@@ -57,8 +56,8 @@
Thread::sleep(100);
}
- void accept(const Socket& srv, bool secure, bool allowUntrusted) throw(SocketException, ThreadException);
- void connect(const string& aAddress, uint16_t aPort, bool secure, bool allowUntrusted, bool proxy) throw(SocketException, ThreadException);
+ void accept(const Socket& srv, bool secure, bool allowUntrusted) throw(SocketException);
+ void connect(const string& aAddress, uint16_t aPort, bool secure, bool allowUntrusted, bool proxy) throw(SocketException);
/** Sets data mode for aBytes bytes. Must be called within onLine. */
void setDataMode(int64_t aBytes = -1) { mode = MODE_DATA; dataBytes = aBytes; }
@@ -70,12 +69,12 @@
void setLineMode(size_t aRollback) { setMode (MODE_LINE, aRollback);}
void setMode(Modes mode, size_t aRollback = 0);
Modes getMode() const { return mode; }
- const string& getIp() const { return sock ? sock->getIp() : Util::emptyString; }
- bool isConnected() const { return sock && sock->isConnected(); }
+ const string& getIp() const { return sock->getIp(); }
+ bool isConnected() const { return sock->isConnected(); }
- bool isSecure() const { return sock && sock->isSecure(); }
- bool isTrusted() const { return sock && sock->isTrusted(); }
- std::string getCipherName() const { return sock ? sock->getCipherName() : Util::emptyString; }
+ bool isSecure() const { return sock->isSecure(); }
+ bool isTrusted() const { return sock->isTrusted(); }
+ std::string getCipherName() const { return sock->getCipherName(); }
void write(const string& aData) { write(aData.data(), aData.length()); }
void write(const char* aBuf, size_t aLen) throw();
@@ -87,7 +86,7 @@
void disconnect(bool graceless = false) throw() { Lock l(cs); if(graceless) disconnecting = true; addTask(DISCONNECT, 0); }
- string getLocalIp() const { return sock ? sock->getLocalIp() : Util::getLocalIp(); }
+ string getLocalIp() const { return sock->getLocalIp(); }
GETSET(char, separator, Separator)
private:
@@ -100,6 +99,12 @@
ACCEPTED,
UPDATED
};
+
+ enum State {
+ STARTING, // Waiting for CONNECT/ACCEPTED/SHUTDOWN
+ RUNNING,
+ FAILED
+ };
struct TaskData {
virtual ~TaskData() { }
@@ -115,30 +120,26 @@
InputStream* stream;
};
- BufferedSocket(char aSeparator) throw();
+ BufferedSocket(char aSeparator) throw(ThreadException);
- // Dummy...
- BufferedSocket(const BufferedSocket&);
- BufferedSocket& operator=(const BufferedSocket&);
-
virtual ~BufferedSocket() throw();
CriticalSection cs;
Semaphore taskSem;
- vector<pair<Tasks, TaskData*> > tasks;
+ deque<pair<Tasks, std::tr1::shared_ptr<TaskData> > > tasks;
Modes mode;
- UnZFilter *filterIn;
+ std::auto_ptr<UnZFilter> filterIn;
int64_t dataBytes;
size_t rollback;
- bool failed;
string line;
ByteVector inbuf;
ByteVector writeBuf;
ByteVector sendBuf;
- Socket* sock;
+ std::auto_ptr<Socket> sock;
+ State state;
bool disconnecting;
virtual int run();
@@ -155,8 +156,9 @@
bool checkEvents();
void checkSocket();
+ void setSocket(std::auto_ptr<Socket> s);
void shutdown();
- void addTask(Tasks task, TaskData* data) { tasks.push_back(make_pair(task, data)); taskSem.signal(); }
+ void addTask(Tasks task, TaskData* data);
};
} // namespace dcpp
Modified: dcplusplus/trunk/dcpp/Client.cpp
===================================================================
--- dcplusplus/trunk/dcpp/Client.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/Client.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -34,7 +34,7 @@
Client::Client(const string& hubURL, char separator_, bool secure_) :
myIdentity(ClientManager::getInstance()->getMe(), 0),
reconnDelay(120), lastActivity(GET_TICK()), registered(false), autoReconnect(false),
- encoding(Text::systemCharset), state(STATE_DISCONNECTED), socket(0),
+ encoding(Text::systemCharset), state(STATE_DISCONNECTED), sock(0),
hubUrl(hubURL), port(0), separator(separator_),
secure(secure_), countType(COUNT_UNCOUNTED)
{
@@ -45,7 +45,7 @@
}
Client::~Client() throw() {
- dcassert(!socket);
+ dcassert(!sock);
// In case we were deleted before we Failed
FavoriteManager::getInstance()->removeUserCommand(getHubUrl());
@@ -60,10 +60,9 @@
}
void Client::shutdown() {
-
- if(socket) {
- BufferedSocket::putSocket(socket);
- socket = 0;
+ if(sock) {
+ BufferedSocket::putSocket(sock);
+ sock = 0;
}
}
@@ -90,8 +89,8 @@
}
void Client::connect() {
- if(socket)
- BufferedSocket::putSocket(socket);
+ if(sock)
+ BufferedSocket::putSocket(sock);
setAutoReconnect(true);
setReconnDelay(120 + Util::rand(0, 60));
@@ -101,13 +100,13 @@
setHubIdentity(Identity());
try {
- socket = BufferedSocket::getSocket(separator);
- socket->addListener(this);
- socket->connect(address, port, secure, BOOLSETTING(ALLOW_UNTRUSTED_HUBS), true);
+ sock = BufferedSocket::getSocket(separator);
+ sock->addListener(this);
+ sock->connect(address, port, secure, BOOLSETTING(ALLOW_UNTRUSTED_HUBS), true);
} catch(const Exception& e) {
- if(socket) {
- BufferedSocket::putSocket(socket);
- socket = 0;
+ if(sock) {
+ BufferedSocket::putSocket(sock);
+ sock = 0;
}
fire(ClientListener::Failed(), this, e.getError());
}
@@ -115,9 +114,18 @@
state = STATE_CONNECTING;
}
+void Client::send(const char* aMessage, size_t aLen) {
+ dcassert(sock);
+ if(!sock)
+ return;
+ updateActivity();
+ sock->write(aMessage, aLen);
+}
+
void Client::on(Connected) throw() {
updateActivity();
- ip = socket->getIp();
+ ip = sock->getIp();
+ localIp = sock->getLocalIp();
fire(ClientListener::Connected(), this);
state = STATE_PROTOCOL;
}
@@ -125,13 +133,13 @@
void Client::on(Failed, const string& aLine) throw() {
state = STATE_DISCONNECTED;
FavoriteManager::getInstance()->removeUserCommand(getHubUrl());
- socket->removeListener(this);
+ sock->removeListener(this);
fire(ClientListener::Failed(), this, aLine);
}
void Client::disconnect(bool graceLess) {
- if(socket)
- socket->disconnect(graceLess);
+ if(sock)
+ sock->disconnect(graceLess);
}
void Client::updateCounts(bool aRemove) {
@@ -169,14 +177,12 @@
if(!SETTING(EXTERNAL_IP).empty()) {
return Socket::resolve(SETTING(EXTERNAL_IP));
}
+
+ if(localIp.empty()) {
+ return Util::getLocalIp();
+ }
- string lip;
- if(socket)
- lip = socket->getLocalIp();
-
- if(lip.empty())
- return Util::getLocalIp();
- return lip;
+ return localIp;
}
void Client::on(Line, const string& /*aLine*/) throw() {
Modified: dcplusplus/trunk/dcpp/Client.h
===================================================================
--- dcplusplus/trunk/dcpp/Client.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/Client.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -16,12 +16,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(CLIENT_H)
-#define CLIENT_H
+#ifndef DCPLUSPLUS_DCPP_CLIENT_H
+#define DCPLUSPLUS_DCPP_CLIENT_H
+#include "forward.h"
+
#include "User.h"
-#include "BufferedSocket.h"
-#include "SettingsManager.h"
+#include "Speaker.h"
+#include "BufferedSocketListener.h"
#include "TimerManager.h"
#include "ClientListener.h"
@@ -52,7 +54,7 @@
virtual string escape(string const& str) const { return str; }
- bool isConnected() const { return socket && socket->isConnected(); }
+ bool isConnected() const { return state != STATE_DISCONNECTED; }
bool isOp() const { return getMyIdentity().isOp(); }
uint16_t getPort() const { return port; }
@@ -80,13 +82,7 @@
void shutdown();
void send(const string& aMessage) { send(aMessage.c_str(), aMessage.length()); }
- void send(const char* aMessage, size_t aLen) {
- dcassert(socket);
- if(!socket)
- return;
- updateActivity();
- socket->write(aMessage, aLen);
- }
+ void send(const char* aMessage, size_t aLen);
string getMyNick() const { return getMyIdentity().getNick(); }
string getHubName() const { return getHubIdentity().getNick().empty() ? getHubUrl() : getHubIdentity().getNick(); }
@@ -129,7 +125,7 @@
STATE_DISCONNECTED, ///< Nothing in particular
} state;
- BufferedSocket* socket;
+ BufferedSocket* sock;
static Counts counts;
Counts lastCounts;
@@ -165,6 +161,7 @@
string hubUrl;
string address;
string ip;
+ string localIp;
uint16_t port;
char separator;
bool secure;
Modified: dcplusplus/trunk/dcpp/ClientManager.cpp
===================================================================
--- dcplusplus/trunk/dcpp/ClientManager.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/ClientManager.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -55,8 +55,6 @@
}
void ClientManager::putClient(Client* aClient) {
- aClient->shutdown();
-
fire(ClientManagerListener::ClientDisconnected(), aClient);
aClient->removeListeners();
@@ -64,6 +62,7 @@
Lock l(cs);
clients.remove(aClient);
}
+ aClient->shutdown();
delete aClient;
}
Modified: dcplusplus/trunk/dcpp/ClientManager.h
===================================================================
--- dcplusplus/trunk/dcpp/ClientManager.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/ClientManager.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -25,6 +25,7 @@
#include "Singleton.h"
#include "SettingsManager.h"
#include "User.h"
+#include "Socket.h"
#include "ClientManagerListener.h"
Modified: dcplusplus/trunk/dcpp/NmdcHub.cpp
===================================================================
--- dcplusplus/trunk/dcpp/NmdcHub.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/NmdcHub.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -578,12 +578,12 @@
fire(ClientListener::UserUpdated(), this, u);
}
} else if(cmd == "$ForceMove") {
- socket->disconnect(false);
+ disconnect(false);
fire(ClientListener::Redirect(), this, param);
} else if(cmd == "$HubIsFull") {
fire(ClientListener::HubFull(), this);
} else if(cmd == "$ValidateDenide") { // Mind the spelling...
- socket->disconnect(false);
+ disconnect(false);
fire(ClientListener::NickTaken(), this);
} else if(cmd == "$UserIP") {
if(!param.empty()) {
@@ -729,7 +729,7 @@
} else if(cmd == "$BadPass") {
setPassword(Util::emptyString);
} else if(cmd == "$ZOn") {
- socket->setMode(BufferedSocket::MODE_ZPIPE);
+ sock->setMode(BufferedSocket::MODE_ZPIPE);
} else {
dcassert(cmd[0] == '$');
dcdebug("NmdcHub::onLine Unknown command %s\n", aLine.c_str());
Modified: dcplusplus/trunk/dcpp/NmdcHub.h
===================================================================
--- dcplusplus/trunk/dcpp/NmdcHub.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/NmdcHub.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -16,13 +16,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(NMDC_HUB_H)
-#define NMDC_HUB_H
+#ifndef DCPLUSPLUS_DCPP_NMDC_HUB_H
+#define DCPLUSPLUS_DCPP_NMDC_HUB_H
#include "TimerManager.h"
#include "SettingsManager.h"
-#include "User.h"
+#include "forward.h"
#include "CriticalSection.h"
#include "Text.h"
#include "Client.h"
Modified: dcplusplus/trunk/dcpp/Speaker.h
===================================================================
--- dcplusplus/trunk/dcpp/Speaker.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/Speaker.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -16,8 +16,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(SPEAKER_H)
-#define SPEAKER_H
+#ifndef DCPLUSPLUS_DCPP_SPEAKER_H
+#define DCPLUSPLUS_DCPP_SPEAKER_H
#include "CriticalSection.h"
Modified: dcplusplus/trunk/dcpp/Thread.h
===================================================================
--- dcplusplus/trunk/dcpp/Thread.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/Thread.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -16,8 +16,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(THREAD_H)
-#define THREAD_H
+#ifndef DCPLUSPLUS_DCPP_THREAD_H
+#define DCPLUSPLUS_DCPP_THREAD_H
#ifndef _WIN32
#include <pthread.h>
@@ -31,7 +31,7 @@
STANDARD_EXCEPTION(ThreadException);
-class Thread
+class Thread : private boost::noncopyable
{
public:
#ifdef _WIN32
@@ -124,10 +124,6 @@
protected:
virtual int run() = 0;
-private:
- Thread(const Thread&);
- Thread& operator=(const Thread&);
-
#ifdef _WIN32
HANDLE threadHandle;
DWORD threadId;
Modified: dcplusplus/trunk/dcpp/stdinc.h
===================================================================
--- dcplusplus/trunk/dcpp/stdinc.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/dcpp/stdinc.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -121,6 +121,7 @@
#include <boost/format.hpp>
#include <boost/scoped_array.hpp>
+#include <boost/noncopyable.hpp>
#ifdef _STLPORT_VERSION
Modified: dcplusplus/trunk/win32/AspectStatus.h
===================================================================
--- dcplusplus/trunk/win32/AspectStatus.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/win32/AspectStatus.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -81,10 +81,10 @@
}
void mapWidget(int s, SmartWin::Widget* widget) {
- RECT sr;
- ::SendMessage(status->handle(), SB_GETRECT, s, reinterpret_cast<LPARAM>(&sr));
- ::MapWindowPoints(status->handle(), static_cast<WidgetType*>(this)->handle(), (POINT*)&sr, 2);
- ::MoveWindow(widget->handle(), sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top, TRUE);
+ POINT p[2];
+ ::SendMessage(status->handle(), SB_GETRECT, s, reinterpret_cast<LPARAM>(p));
+ ::MapWindowPoints(status->handle(), static_cast<WidgetType*>(this)->handle(), (POINT*)p, 2);
+ ::MoveWindow(widget->handle(), p[0].x, p[0].y, p[1].x - p[0].x, p[1].y - p[0].y, TRUE);
}
WidgetStatusBarSectionsPtr status;
Modified: dcplusplus/trunk/win32/DirectoryListingFrame.cpp
===================================================================
--- dcplusplus/trunk/win32/DirectoryListingFrame.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/win32/DirectoryListingFrame.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -762,7 +762,7 @@
changeDir(dir);
// Check file names in list pane
- for(int i=0; i<files->size(); i++) {
+ for(size_t i = 0; i < files->size(); i++) {
ItemInfo* ii = files->getData(i);
if(ii->type == ItemInfo::FILE) {
if(str.match(ii->file->getName())) {
Modified: dcplusplus/trunk/win32/TypedTreeView.h
===================================================================
--- dcplusplus/trunk/win32/TypedTreeView.h 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/win32/TypedTreeView.h 2008-03-07 23:01:59 UTC (rev 1030)
@@ -76,7 +76,7 @@
ContentType* content = reinterpret_cast<ContentType*>(nm->item.lParam);
const tstring& text = content->getText();
_tcsncpy(nm->item.pszText, text.data(), std::min(text.size(), (size_t)nm->item.cchTextMax));
- if(text.size() < nm->item.cchTextMax) {
+ if(text.size() < static_cast<size_t>(nm->item.cchTextMax)) {
nm->item.pszText[text.size()] = 0;
}
}
Modified: dcplusplus/trunk/win32/UsersFrame.cpp
===================================================================
--- dcplusplus/trunk/win32/UsersFrame.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/win32/UsersFrame.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -117,7 +117,7 @@
}
void UsersFrame::updateUser(const UserPtr& aUser) {
- for(int i = 0; i < users->size(); ++i) {
+ for(size_t i = 0; i < users->size(); ++i) {
UserInfo *ui = users->getData(i);
if(ui->user == aUser) {
ui->columns[COLUMN_SEEN] = aUser->isOnline() ? T_("Online") : Text::toT(Util::formatTime("%Y-%m-%d %H:%M", FavoriteManager::getInstance()->getLastSeen(aUser)));
@@ -127,7 +127,7 @@
}
void UsersFrame::removeUser(const FavoriteUser& aUser) {
- for(int i = 0; i < users->size(); ++i) {
+ for(size_t i = 0; i < users->size(); ++i) {
UserInfo *ui = users->getData(i);
if(ui->user == aUser.getUser()) {
users->erase(i);
Modified: dcplusplus/trunk/win32/WinUtil.cpp
===================================================================
--- dcplusplus/trunk/win32/WinUtil.cpp 2008-03-07 00:20:14 UTC (rev 1029)
+++ dcplusplus/trunk/win32/WinUtil.cpp 2008-03-07 23:01:59 UTC (rev 1030)
@@ -120,7 +120,7 @@
}
// Const so that noone else will change them after they've been initialized
- SmartWin::WidgetButton::Seed& xbutton = const_cast<SmartWin::WidgetButton::Seed&>(Seeds::button);
+ //SmartWin::WidgetButton::Seed& xbutton = const_cast<SmartWin::WidgetButton::Seed&>(Seeds::button);
SmartWin::WidgetComboBox::Seed& xcomboBoxEdit = const_cast<SmartWin::WidgetComboBox::Seed&>(Seeds::comboBoxEdit);
SmartWin::WidgetComboBox::Seed& xcomboBoxStatic = const_cast<SmartWin::WidgetComboBox::Seed&>(Seeds::comboBoxStatic);
SmartWin::WidgetListView::Seed& xlistView = const_cast<SmartWin::WidgetListView::Seed&>(Seeds::listView);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|