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
18namespace Poco {
19namespace Net {
20
21
22HTTPServerSession::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 this->socket().setSendTimeout(pParams->getTimeout());
31}
32
33
34HTTPServerSession::~HTTPServerSession()
35{
36}
37
38
39bool HTTPServerSession::hasMoreRequests()
40{
41 if (!socket().impl()->initialized()) return false;
42
43 if (_firstRequest)
44 {
45 _firstRequest = false;
46 --_maxKeepAliveRequests;
47 return socket().poll(getTimeout(), Socket::SELECT_READ);
48 }
49 else if (_maxKeepAliveRequests != 0 && getKeepAlive())
50 {
51 if (_maxKeepAliveRequests > 0)
52 --_maxKeepAliveRequests;
53 return buffered() > 0 || socket().poll(_keepAliveTimeout, Socket::SELECT_READ);
54 }
55 else return false;
56}
57
58
59SocketAddress HTTPServerSession::clientAddress()
60{
61 return socket().peerAddress();
62}
63
64
65SocketAddress HTTPServerSession::serverAddress()
66{
67 return socket().address();
68}
69
70
71} } // namespace Poco::Net
72