~george-edison55/jethttp/jethttp-singlethread

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
//=================================================
//
//           JetHTTP - CJetHTTPServer.cpp
//           Copyright 2011 - Nathan Osman
//     This file is released under the GPL v3
//
//=================================================

#include "CJetHTTPServer.h"

// Linux specific code
#ifdef Q_OS_LINUX
#include <QCoreApplication>
#include <QSocketNotifier>
#endif

// JetHTTP includes
#include <CJetHTTPSocket.h>

CJetHTTPServer::CJetHTTPServer()
{
    // Connect to the new connection signal
    connect(this, SIGNAL(newConnection()), SLOT(OnNewConnection()));

    // Determine the port number to use
    int port_number = m_settings.GetSetting("System/Port", QVariant(8080)).toInt();

    // Make sure that the document root gets set
    m_settings.GetSetting("System/DocumentRoot", "/var/www");

    // Now listen on the specified port.
    if(!listen(QHostAddress::Any, port_number))
        throw QString(QObject::tr("Unable to listen on port %1.").arg(port_number));
}

CJetHTTPServer::~CJetHTTPServer()
{
    //....
}

void CJetHTTPServer::OnNewConnection()
{
    new CJetHTTPSocket(this, nextPendingConnection());
}

void CJetHTTPServer::OnSignal(int)
{
    #ifdef Q_OS_LINUX

    QCoreApplication::quit();

    // Now deactivate the signal
    QSocketNotifier * pNote = dynamic_cast<QSocketNotifier *>(this->sender());
    pNote->setEnabled(false);

    #endif
}