Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
acceptor_thread.cpp
1
2
/***************************************************************************
3
* acceptor_thread.cpp - Thread accepting Fawkes network connections
4
*
5
* Created: Fri Nov 17 14:09:38 2006
6
* Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include <netcomm/utils/acceptor_thread.h>
25
#include <netcomm/utils/incoming_connection_handler.h>
26
#include <netcomm/socket/stream.h>
27
28
namespace
fawkes {
29
30
/** @class NetworkAcceptorThread <netcomm/utils/acceptor_thread.h>
31
* Network Acceptor Thread.
32
* Opens and maintains a server socket and waits for incoming connections. If
33
* that happens NetworkConnectionHandler::add_connection() is called.
34
*
35
* @ingroup NetComm
36
* @author Tim Niemueller
37
*/
38
39
/** Constructor.
40
* @param handler Connection handler for newly accepted incoming connections.
41
* @param port port to listen on for incoming connections
42
* @param thread_name name of the thread
43
* @exception SocketException as thrown by StreamSocket connstructor, bind and listen.
44
*/
45
NetworkAcceptorThread::NetworkAcceptorThread
(
NetworkIncomingConnectionHandler
*handler,
46
unsigned
short
int
port,
47
const
char
*thread_name)
48
:
Thread
(thread_name)
49
{
50
__handler = handler;
51
__port = port;
52
53
set_prepfin_conc_loop
(
true
);
54
55
try
{
56
__socket =
new
StreamSocket
();
57
__socket->
bind
(__port);
58
__socket->
listen
();
59
}
catch
(
SocketException
&e) {
60
throw
;
61
}
62
}
63
64
65
/** Constructor.
66
* @param handler Connection handler for newly accepted incoming connections.
67
* @param socket socket, must already be bound to the desired port. Socket::listen()
68
* will be called by the acceptor thread.
69
* @param thread_name name of the thread
70
* @exception SocketException as thrown by StreamSocket connstructor, bind and listen.
71
*/
72
NetworkAcceptorThread::NetworkAcceptorThread
(
NetworkIncomingConnectionHandler
*handler,
73
StreamSocket
*socket,
74
const
char
*thread_name)
75
:
Thread
(thread_name)
76
{
77
__handler = handler;
78
__port = 0;
79
__socket = socket;
80
81
set_prepfin_conc_loop
(
true
);
82
83
try
{
84
__socket->
listen
();
85
}
catch
(
SocketException
&e) {
86
throw
;
87
}
88
}
89
90
91
/** Destructor. */
92
NetworkAcceptorThread::~NetworkAcceptorThread
()
93
{
94
delete
__socket;
95
}
96
97
98
/** Thread loop.
99
* Waits on a socket for an incoming connection (blocking accept). If a new
100
* connection has been established it is reported to the handler.
101
*/
102
void
103
NetworkAcceptorThread::loop
()
104
{
105
StreamSocket
*s = __socket->
accept
<
StreamSocket
>();
106
__handler->
add_connection
(s);
107
}
108
109
}
// end namespace fawkes
src
libs
netcomm
utils
acceptor_thread.cpp
Generated by
1.8.1.1