1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
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. *
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. *
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"
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
));
45 /* {{{ TorrentServer::~TorrentServer */
46 TorrentServer::~TorrentServer()
49 server
->newConnectionSignal
.disable();
57 /* {{{ TorrentServer::connectionClosed(Connection *) */
58 void TorrentServer::connectionClosed(Connection
*connection
)
60 pendingConnections
.erase(connection
);
65 /* {{{ TorrentServer::connectionCompleted(Connection *) */
66 void TorrentServer::connectionCompleted(Connection
*connection
)
68 pendingConnections
.erase(connection
);
69 connection
->closedSignal
.clear();
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
);
84 /* {{{ TorrentServer::stop() */
85 void TorrentServer::stop()
88 server
->newConnectionSignal
.disable();
92 // close pending connections
93 for (std::set
<Connection
*>::const_iterator it
= pendingConnections
.begin(); it
!= pendingConnections
.end(); ++it
) {
102 }; // namespace Tairent
104 // vim: ai sw=4 ts=4 noet fdm=marker