Commit c357bd13330838171885a1ef8fea6928d570c973

make fastcgi interface use SocketFlusher from HttpInterface
  
4040 RequestQueue
4141 RequestRunner
4242 Settings
43 SocketFlusher
4344 ThreadedResponder_Private
4445 ThreadPool
4546 ThreadPool_Worker
  
1#include "SocketFlusher.h"
2
3namespace FastCgiQt
4{
5 SocketFlusher::SocketFlusher(QAbstractSocket* socket)
6 : QObject(0)
7 , m_socket(socket)
8 {
9 socket->setParent(this);
10 connect(
11 socket,
12 SIGNAL(bytesWritten(qint64)),
13 this,
14 SLOT(deleteIfFlushed())
15 );
16 deleteIfFlushed();
17 }
18
19 void SocketFlusher::deleteIfFlushed()
20 {
21 if(!m_socket->bytesToWrite())
22 {
23 deleteLater();
24 }
25 else
26 {
27 m_socket->flush();
28 }
29 }
30};
  
1#pragma once
2
3#include <QAbstractSocket>
4
5namespace FastCgiQt
6{
7 /** Class to cleanup a socket.
8 *
9 * Takes ownership, and automatically deletes both itself and the socket
10 * when there's no more data to write to the socket.
11 */
12 class SocketFlusher : public QObject
13 {
14 Q_OBJECT
15 public:
16 SocketFlusher(QAbstractSocket* socket);
17 private slots:
18 void deleteIfFlushed();
19 private:
20 QAbstractSocket* m_socket;
21 };
22}
  
1616#include "FastCgiStream.h"
1717
1818#include "EndRequestRecord.h"
19#include "SocketFlusher.h"
1920#include "StandardInputRecord.h"
2021#include "StandardOutputRecord.h"
2122
6565 FastCgiStream::~FastCgiStream()
6666 {
6767 m_socket->write(EndRequestRecord::create(m_requestId));
68 while(m_socket->bytesToWrite())
69 {
70 m_socket->flush();
71 }
72 m_socket->close(); // TODO: check the flag; but every httpd sets it anyway...
68 new SocketFlusher(m_socket);
7369 }
7470
7571 qint64 FastCgiStream::readData(char* data, qint64 maxSize)
  
1414 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515*/
1616#pragma once
17// WIP for new internal API
17
1818#include "ClientIODevice.h"
1919
2020class QTcpSocket;
  
33 HttpInterface
44 HttpInterfaceFactory
55 HttpRequest
6 SocketFlusher
76)
87
98SET(SOURCES)
  
6060
6161 HttpRequest::~HttpRequest()
6262 {
63 m_socket->flush();
6463 new SocketFlusher(m_socket);
6564 }
6665
  
1#include "SocketFlusher.h"
2
3namespace FastCgiQt
4{
5 SocketFlusher::SocketFlusher(QAbstractSocket* socket)
6 : QObject(0)
7 , m_socket(socket)
8 {
9 socket->setParent(this);
10 connect(
11 socket,
12 SIGNAL(bytesWritten(qint64)),
13 this,
14 SLOT(deleteIfFlushed())
15 );
16 socket->flush();
17 deleteIfFlushed();
18 }
19
20 void SocketFlusher::deleteIfFlushed()
21 {
22 if(!m_socket->bytesToWrite())
23 {
24 deleteLater();
25 }
26 }
27};
  
1#pragma once
2
3#include <QAbstractSocket>
4
5namespace FastCgiQt
6{
7 /** Class to cleanup a socket.
8 *
9 * Takes ownership, and automatically deletes both itself and the socket
10 * when there's no more data to write to the socket.
11 */
12 class SocketFlusher : public QObject
13 {
14 Q_OBJECT
15 public:
16 SocketFlusher(QAbstractSocket* socket);
17 private slots:
18 void deleteIfFlushed();
19 private:
20 QAbstractSocket* m_socket;
21 };
22}