File: Poco.Net.TCPServer.html

package info (click to toggle)
poco-doc 1.3.6-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 10,076 kB
  • ctags: 9,611
  • sloc: makefile: 31
file content (136 lines) | stat: -rw-r--r-- 14,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::Net::TCPServer</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.Net.html" class="namespace">Poco::Net</a></h1>
<h1 class="symbol">class TCPServer</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Net<br />
<b>Package:</b> TCPServer<br />
<b>Header:</b> Poco/Net/TCPServer.h</p>
<h2>Description</h2>
<div class="description">
<p>This class implements a multithreaded TCP server. </p>
<p>The server uses a <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> to listen for incoming connections. The <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> must have been bound to an address before it is passed to the <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a> constructor. Additionally, the <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> must be put into listening state before the <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a> is started by calling the <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>() method. </p>
<p>The server uses a thread pool to assign threads to incoming connections. Before incoming connections are assigned to a connection thread, they are put into a queue. Connection threads fetch new connections from the queue as soon as they become free. Thus, a connection thread may serve more than one connection. </p>
<p>As soon as a connection thread fetches the next connection from the queue, it creates a <a href="Poco.Net.TCPServerConnection.html" title="class Poco::Net::TCPServerConnection">TCPServerConnection</a> object for it (using the <a href="Poco.Net.TCPServerConnectionFactory.html" title="class Poco::Net::TCPServerConnectionFactory">TCPServerConnectionFactory</a> passed to the constructor) and calls the <a href="Poco.Net.TCPServerConnection.html" title="class Poco::Net::TCPServerConnection">TCPServerConnection</a>'s <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>() method. When the <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>() method returns, the connection object is deleted. </p>
<p>The number of connection threads is adjusted dynamically, depending on the number of connections waiting to be served. </p>
<p>It is possible to specify a maximum number of queued connections. This prevents the connection queue from overflowing in the  case of an extreme server load. In such a case, connections that cannot be queued are silently and immediately closed. </p>
<p><a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a> uses a separate thread to accept incoming connections. Thus, the call to <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>() returns immediately, and the server continues to run in the background. </p>
<p>To stop the server from accepting new connections, call <a href="Poco.Net.TCPServer.html#15562" title="Poco::Net::TCPServer::stop()">stop</a>(). </p>
<p>After calling <a href="Poco.Net.TCPServer.html#15562" title="Poco::Net::TCPServer::stop()">stop</a>(), no new connections will be accepted and all queued connections will be discarded. Already served connections, however, will continue being served. </p>
</div>
<h2>Inheritance</h2>
<p><b>Direct Base Classes: </b><a href="Poco.Runnable.html" title="class Poco::Runnable">Poco::Runnable</a></p>
<p><b>All Base Classes: </b><a href="Poco.Runnable.html" title="class Poco::Runnable">Poco::Runnable</a></p>
<p><b>Known Derived Classes: </b><a href="Poco.Net.HTTPServer.html" title="class Poco::Net::HTTPServer">HTTPServer</a></p>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.Net.TCPServer.html#15565" title="Poco::Net::TCPServer::currentConnections()">currentConnections</a>, <a href="Poco.Net.TCPServer.html#15563" title="Poco::Net::TCPServer::currentThreads()">currentThreads</a>, <a href="Poco.Net.TCPServer.html#15566" title="Poco::Net::TCPServer::maxConcurrentConnections()">maxConcurrentConnections</a>, <a href="Poco.Net.TCPServer.html#15560" title="Poco::Net::TCPServer::params()">params</a>, <a href="Poco.Net.TCPServer.html#15569" title="Poco::Net::TCPServer::port()">port</a>, <a href="Poco.Net.TCPServer.html#15567" title="Poco::Net::TCPServer::queuedConnections()">queuedConnections</a>, <a href="Poco.Net.TCPServer.html#15568" title="Poco::Net::TCPServer::refusedConnections()">refusedConnections</a>, <a href="Poco.Net.TCPServer.html#15570" title="Poco::Net::TCPServer::run()">run</a>, <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>, <a href="Poco.Net.TCPServer.html#15562" title="Poco::Net::TCPServer::stop()">stop</a>, <a href="Poco.Net.TCPServer.html#15571" title="Poco::Net::TCPServer::threadName()">threadName</a>, <a href="Poco.Net.TCPServer.html#15564" title="Poco::Net::TCPServer::totalConnections()">totalConnections</a></p>
<p><b>Inherited Functions: </b><a href="Poco.Runnable.html#9810" title="Poco::Runnable::run()">run</a></p>
<h2>Constructors</h2>
<h3><a name="15550">TCPServer</a></h3>
<p class="decl"><a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a>(<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="Poco.Net.TCPServerConnectionFactory.html#15595" title="Poco::Net::TCPServerConnectionFactory::Ptr">TCPServerConnectionFactory::Ptr</a> pFactory,<br />&nbsp;&nbsp;&nbsp;&nbsp;const <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> &amp; socket,<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="Poco.Net.TCPServerParams.html#15648" title="Poco::Net::TCPServerParams::Ptr">TCPServerParams::Ptr</a> pParams = 0<br />);</p>
<div class="description">
<p>Creates the <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a>, using the given <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a>. </p>
<p>The server takes ownership of the <a href="Poco.Net.TCPServerConnectionFactory.html" title="class Poco::Net::TCPServerConnectionFactory">TCPServerConnectionFactory</a> and deletes it when it's no longer needed. </p>
<p>The server also takes ownership of the <a href="Poco.Net.TCPServerParams.html" title="class Poco::Net::TCPServerParams">TCPServerParams</a> object. If no <a href="Poco.Net.TCPServerParams.html" title="class Poco::Net::TCPServerParams">TCPServerParams</a> object is given, the server's <a href="Poco.Net.TCPServerDispatcher.html" title="class Poco::Net::TCPServerDispatcher">TCPServerDispatcher</a> creates its own one. </p>
<p>News threads are taken from the default thread pool. </p>
</div>
<h3><a name="15554">TCPServer</a></h3>
<p class="decl"><a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a>(<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="Poco.Net.TCPServerConnectionFactory.html#15595" title="Poco::Net::TCPServerConnectionFactory::Ptr">TCPServerConnectionFactory::Ptr</a> pFactory,<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="Poco.ThreadPool.html" title="class Poco::ThreadPool">Poco::ThreadPool</a> &amp; threadPool,<br />&nbsp;&nbsp;&nbsp;&nbsp;const <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> &amp; socket,<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="Poco.Net.TCPServerParams.html#15648" title="Poco::Net::TCPServerParams::Ptr">TCPServerParams::Ptr</a> pParams = 0<br />);</p>
<div class="description">
<p>Creates the <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a>, using the given <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a>. </p>
<p>The server takes ownership of the <a href="Poco.Net.TCPServerConnectionFactory.html" title="class Poco::Net::TCPServerConnectionFactory">TCPServerConnectionFactory</a> and deletes it when it's no longer needed. </p>
<p>The server also takes ownership of the <a href="Poco.Net.TCPServerParams.html" title="class Poco::Net::TCPServerParams">TCPServerParams</a> object. If no <a href="Poco.Net.TCPServerParams.html" title="class Poco::Net::TCPServerParams">TCPServerParams</a> object is given, the server's <a href="Poco.Net.TCPServerDispatcher.html" title="class Poco::Net::TCPServerDispatcher">TCPServerDispatcher</a> creates its own one. </p>
<p>News threads are taken from the given thread pool. </p>
</div>
<h2>Destructor</h2>
<h3><a name="15559">~TCPServer</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual ~<a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a>();</p>
<div class="description">
<p>Destroys the <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a> and its <a href="Poco.Net.TCPServerConnectionFactory.html" title="class Poco::Net::TCPServerConnectionFactory">TCPServerConnectionFactory</a>. </p>
</div>
<h2>Member Functions</h2>
<h3><a name="15565">currentConnections</a></h3>
<p class="decl">int currentConnections() const;</p>
<div class="description">
<p>Returns the number of currently handled connections. </p>
</div>
<h3><a name="15563">currentThreads</a></h3>
<p class="decl">int currentThreads() const;</p>
<div class="description">
<p>Returns the number of currently used connection threads. </p>
</div>
<h3><a name="15566">maxConcurrentConnections</a></h3>
<p class="decl">int maxConcurrentConnections() const;</p>
<div class="description">
<p>Returns the maximum number of concurrently handled connections.	 </p>
</div>
<h3><a name="15560">params</a></h3>
<p class="decl">const <a href="Poco.Net.TCPServerParams.html" title="class Poco::Net::TCPServerParams">TCPServerParams</a> &amp; params() const;</p>
<div class="description">
<p>Returns a const reference to the TCPServerParam object used by the server's <a href="Poco.Net.TCPServerDispatcher.html" title="class Poco::Net::TCPServerDispatcher">TCPServerDispatcher</a>.	 </p>
</div>
<h3><a name="15569">port</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.html#11352" title="Poco::UInt16">Poco::UInt16</a> port() const;</p>
<div class="description">
<p>Returns the port the server socket listens to </p>
</div>
<h3><a name="15567">queuedConnections</a></h3>
<p class="decl">int queuedConnections() const;</p>
<div class="description">
<p>Returns the number of queued connections. </p>
</div>
<h3><a name="15568">refusedConnections</a></h3>
<p class="decl">int refusedConnections() const;</p>
<div class="description">
<p>Returns the number of refused connections. </p>
</div>
<h3><a name="15561">start</a></h3>
<p class="decl">void start();</p>
<div class="description">
<p>Starts the server. A new thread will be created that waits for and accepts incoming connections. </p>
<p>Before <a href="Poco.Net.TCPServer.html#15561" title="Poco::Net::TCPServer::start()">start</a>() is called, the <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> passed to <a href="Poco.Net.TCPServer.html" title="class Poco::Net::TCPServer">TCPServer</a> must have been bound and put into listening state. </p>
</div>
<h3><a name="15562">stop</a></h3>
<p class="decl">void stop();</p>
<div class="description">
<p>Stops the server. </p>
<p>No new connections will be accepted. Already handled connections will continue to be served. </p>
<p>Once the server is stopped, it cannot be restarted. </p>
</div>
<h3><a name="15564">totalConnections</a></h3>
<p class="decl">int totalConnections() const;</p>
<div class="description">
<p>Returns the total number of handled connections. </p>
</div>
<h3><a name="15570">run</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" />  <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void run();</p>
<div class="description">
<p>Runs the server. The server will run until the <a href="Poco.Net.TCPServer.html#15562" title="Poco::Net::TCPServer::stop()">stop</a>() method is called, or the server object is destroyed, which implicitly calls the <a href="Poco.Net.TCPServer.html#15562" title="Poco::Net::TCPServer::stop()">stop</a>() method. </p>
</div>
<div class="description"><p><b>See also:</b> <a href="Poco.Runnable.html#9810" title="Poco::Runnable::run()">Poco::Runnable::run()</a></p></div>
<h3><a name="15571">threadName</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" />  <img src="images/static.gif" alt="static" title="static" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">static std::string threadName(<br />&nbsp;&nbsp;&nbsp;&nbsp;const <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a> &amp; socket<br />);</p>
<div class="description">
<p>Returns a thread name for the server thread. </p>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright &copy; 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>

</div>
</body>
</html>