Fix Tairent::Main::TorrentManager::save() method's comment.
[tairent.git] / src / main / torrentserver.cpp
blob726705d6127b20be0f947f05e1d79f73c67d90a5
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation and appearing *
8 * in the file LICENSE.GPL included in the packaging of this file. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * General Public License for more details. *
14 * *
15 ***************************************************************************/
17 #include <tairon/core/config.h>
18 #include <tairon/core/log.h>
19 #include <tairon/net/server.h>
20 #include <tairon/net/socket.h>
22 #include "torrentserver.h"
24 #include "connection.h"
26 namespace Tairent
29 namespace Main
32 TorrentServer *TorrentServer::torrentserver = 0;
34 /* {{{ TorrentServer::TorrentServer() */
35 TorrentServer::TorrentServer()
37 server = new Tairon::Net::Server(0, atoi((*Tairon::Core::Config::self())["torrent-server-port"]), 2);
38 server->newConnectionSignal.connect(Tairon::Core::threadMethodDFunctor(Tairon::Core::Thread::current(), this, &TorrentServer::newConnection));
39 server->ready();
41 torrentserver = this;
43 /* }}} */
45 /* {{{ TorrentServer::~TorrentServer */
46 TorrentServer::~TorrentServer()
48 if (server) {
49 server->newConnectionSignal.disable();
50 delete server;
53 torrentserver = 0;
55 /* }}} */
57 /* {{{ TorrentServer::connectionClosed(Connection *) */
58 void TorrentServer::connectionClosed(Connection *connection)
60 pendingConnections.erase(connection);
61 delete connection;
63 /* }}} */
65 /* {{{ TorrentServer::connectionCompleted(Connection *) */
66 void TorrentServer::connectionCompleted(Connection *connection)
68 pendingConnections.erase(connection);
69 connection->closedSignal.clear();
71 /* }}} */
73 /* {{{ TorrentServer::newConnection(Tairon::Net::Server *, int) */
74 void TorrentServer::newConnection(Tairon::Net::Server *, int fd)
76 DEBUG("new connection");
78 Connection *connection = new Connection(fd);
79 connection->closedSignal.connect(Tairon::Core::methodFunctor(this, &TorrentServer::connectionClosed));
80 pendingConnections.insert(connection);
82 /* }}} */
84 /* {{{ TorrentServer::stop() */
85 void TorrentServer::stop()
87 // delete server
88 server->newConnectionSignal.disable();
89 delete server;
90 server = 0;
92 // close pending connections
93 for (std::set<Connection *>::const_iterator it = pendingConnections.begin(); it != pendingConnections.end(); ++it) {
94 (*it)->close();
95 delete *it;
98 /* }}} */
100 }; // namespace Main
102 }; // namespace Tairent
104 // vim: ai sw=4 ts=4 noet fdm=marker