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
));
44 /* {{{ TorrentServer::~TorrentServer */
45 TorrentServer::~TorrentServer()
48 server
->newConnectionSignal
.disable();
56 /* {{{ TorrentServer::connectionClosed(Connection *) */
57 void TorrentServer::connectionClosed(Connection
*connection
)
59 pendingConnections
.erase(connection
);
64 /* {{{ TorrentServer::connectionCompleted(Connection *) */
65 void TorrentServer::connectionCompleted(Connection
*connection
)
67 pendingConnections
.erase(connection
);
68 connection
->closedSignal
.clear();
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
);
83 /* {{{ TorrentServer::stop() */
84 void TorrentServer::stop()
87 server
->newConnectionSignal
.disable();
91 // close pending connections
92 for (std::set
<Connection
*>::const_iterator it
= pendingConnections
.begin(); it
!= pendingConnections
.end(); ++it
)
99 }; // namespace Tairent
101 // vim: ai sw=4 ts=4 noet fdm=marker