Commit c357bd13330838171885a1ef8fea6928d570c973
make fastcgi interface use SocketFlusher from HttpInterface
| |   |
| 40 | 40 | RequestQueue |
| 41 | 41 | RequestRunner |
| 42 | 42 | Settings |
| SocketFlusher |
| 43 | 44 | ThreadedResponder_Private |
| 44 | 45 | ThreadPool |
| 45 | 46 | ThreadPool_Worker |
| |   |
| #include "SocketFlusher.h" |
|
| namespace FastCgiQt |
| { |
| SocketFlusher::SocketFlusher(QAbstractSocket* socket) |
| : QObject(0) |
| , m_socket(socket) |
| { |
| socket->setParent(this); |
| connect( |
| socket, |
| SIGNAL(bytesWritten(qint64)), |
| this, |
| SLOT(deleteIfFlushed()) |
| ); |
| deleteIfFlushed(); |
| } |
|
| void SocketFlusher::deleteIfFlushed() |
| { |
| if(!m_socket->bytesToWrite()) |
| { |
| deleteLater(); |
| } |
| else |
| { |
| m_socket->flush(); |
| } |
| } |
| }; |
| |   |
| #pragma once |
|
| #include <QAbstractSocket> |
|
| namespace FastCgiQt |
| { |
| /** Class to cleanup a socket. |
| * |
| * Takes ownership, and automatically deletes both itself and the socket |
| * when there's no more data to write to the socket. |
| */ |
| class SocketFlusher : public QObject |
| { |
| Q_OBJECT |
| public: |
| SocketFlusher(QAbstractSocket* socket); |
| private slots: |
| void deleteIfFlushed(); |
| private: |
| QAbstractSocket* m_socket; |
| }; |
| } |
| |   |
| 16 | 16 | #include "FastCgiStream.h" |
| 17 | 17 | |
| 18 | 18 | #include "EndRequestRecord.h" |
| #include "SocketFlusher.h" |
| 19 | 20 | #include "StandardInputRecord.h" |
| 20 | 21 | #include "StandardOutputRecord.h" |
| 21 | 22 | |
| … | … | |
| 65 | 65 | FastCgiStream::~FastCgiStream() |
| 66 | 66 | { |
| 67 | 67 | m_socket->write(EndRequestRecord::create(m_requestId)); |
| while(m_socket->bytesToWrite()) |
| { |
| m_socket->flush(); |
| } |
| m_socket->close(); // TODO: check the flag; but every httpd sets it anyway... |
| new SocketFlusher(m_socket); |
| 73 | 69 | } |
| 74 | 70 | |
| 75 | 71 | qint64 FastCgiStream::readData(char* data, qint64 maxSize) |
| |   |
| 14 | 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | 15 | */ |
| 16 | 16 | #pragma once |
| // WIP for new internal API |
|
| 18 | 18 | #include "ClientIODevice.h" |
| 19 | 19 | |
| 20 | 20 | class QTcpSocket; |
| |   |
| 3 | 3 | HttpInterface |
| 4 | 4 | HttpInterfaceFactory |
| 5 | 5 | HttpRequest |
| SocketFlusher |
| 7 | 6 | ) |
| 8 | 7 | |
| 9 | 8 | SET(SOURCES) |
| |   |
| 60 | 60 | |
| 61 | 61 | HttpRequest::~HttpRequest() |
| 62 | 62 | { |
| m_socket->flush(); |
| 64 | 63 | new SocketFlusher(m_socket); |
| 65 | 64 | } |
| 66 | 65 | |
| |   |
| #include "SocketFlusher.h" |
|
| namespace FastCgiQt |
| { |
| SocketFlusher::SocketFlusher(QAbstractSocket* socket) |
| : QObject(0) |
| , m_socket(socket) |
| { |
| socket->setParent(this); |
| connect( |
| socket, |
| SIGNAL(bytesWritten(qint64)), |
| this, |
| SLOT(deleteIfFlushed()) |
| ); |
| socket->flush(); |
| deleteIfFlushed(); |
| } |
|
| void SocketFlusher::deleteIfFlushed() |
| { |
| if(!m_socket->bytesToWrite()) |
| { |
| deleteLater(); |
| } |
| } |
| }; |
| |   |
| #pragma once |
|
| #include <QAbstractSocket> |
|
| namespace FastCgiQt |
| { |
| /** Class to cleanup a socket. |
| * |
| * Takes ownership, and automatically deletes both itself and the socket |
| * when there's no more data to write to the socket. |
| */ |
| class SocketFlusher : public QObject |
| { |
| Q_OBJECT |
| public: |
| SocketFlusher(QAbstractSocket* socket); |
| private slots: |
| void deleteIfFlushed(); |
| private: |
| QAbstractSocket* m_socket; |
| }; |
| } |