1 | // |
---|---|
2 | // HTTPServerSession.cpp |
3 | // |
4 | // Library: Net |
5 | // Package: HTTPServer |
6 | // Module: HTTPServerSession |
7 | // |
8 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Net/HTTPServerSession.h" |
16 | |
17 | |
18 | namespace Poco { |
19 | namespace Net { |
20 | |
21 | |
22 | HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams::Ptr pParams): |
23 | HTTPSession(socket, pParams->getKeepAlive()), |
24 | _firstRequest(true), |
25 | _keepAliveTimeout(pParams->getKeepAliveTimeout()), |
26 | _maxKeepAliveRequests(pParams->getMaxKeepAliveRequests()) |
27 | { |
28 | setTimeout(pParams->getTimeout()); |
29 | this->socket().setReceiveTimeout(pParams->getTimeout()); |
30 | } |
31 | |
32 | |
33 | HTTPServerSession::~HTTPServerSession() |
34 | { |
35 | } |
36 | |
37 | |
38 | bool HTTPServerSession::hasMoreRequests() |
39 | { |
40 | if (!socket().impl()->initialized()) return false; |
41 | |
42 | if (_firstRequest) |
43 | { |
44 | _firstRequest = false; |
45 | --_maxKeepAliveRequests; |
46 | return socket().poll(getTimeout(), Socket::SELECT_READ); |
47 | } |
48 | else if (_maxKeepAliveRequests != 0 && getKeepAlive()) |
49 | { |
50 | if (_maxKeepAliveRequests > 0) |
51 | --_maxKeepAliveRequests; |
52 | return buffered() > 0 || socket().poll(_keepAliveTimeout, Socket::SELECT_READ); |
53 | } |
54 | else return false; |
55 | } |
56 | |
57 | |
58 | SocketAddress HTTPServerSession::clientAddress() |
59 | { |
60 | return socket().peerAddress(); |
61 | } |
62 | |
63 | |
64 | SocketAddress HTTPServerSession::serverAddress() |
65 | { |
66 | return socket().address(); |
67 | } |
68 | |
69 | |
70 | } } // namespace Poco::Net |
71 |