Send correct informations to a http tracker.
[tairent.git] / src / main / torrentserver.cpp
blob55083a0ce08ea20cdf224fd0b0cbc29e1008c626
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));
40 torrentserver = this;
42 /* }}} */
44 /* {{{ TorrentServer::~TorrentServer */
45 TorrentServer::~TorrentServer()
47 if (server) {
48 server->newConnectionSignal.disable();
49 delete server;
52 torrentserver = 0;
54 /* }}} */
56 /* {{{ TorrentServer::connectionClosed(Connection *) */
57 void TorrentServer::connectionClosed(Connection *connection)
59 pendingConnections.erase(connection);
60 delete connection;
62 /* }}} */
64 /* {{{ TorrentServer::connectionCompleted(Connection *) */
65 void TorrentServer::connectionCompleted(Connection *connection)
67 pendingConnections.erase(connection);
68 connection->closedSignal.clear();
70 /* }}} */
72 /* {{{ TorrentServer::newConnection(Tairon::Net::Server *, int) */
73 void TorrentServer::newConnection(Tairon::Net::Server *, int fd)
75 DEBUG("new connection");
77 Connection *connection = new Connection(fd);
78 connection->closedSignal.connect(Tairon::Core::methodFunctor(this, &TorrentServer::connectionClosed));
79 pendingConnections.insert(connection);
81 /* }}} */
83 /* {{{ TorrentServer::stop() */
84 void TorrentServer::stop()
86 // delete server
87 server->newConnectionSignal.disable();
88 delete server;
89 server = 0;
91 // close pending connections
92 for (std::set<Connection *>::const_iterator it = pendingConnections.begin(); it != pendingConnections.end(); ++it)
93 (*it)->close();
95 /* }}} */
97 }; // namespace Main
99 }; // namespace Tairent
101 // vim: ai sw=4 ts=4 noet fdm=marker