Listen on a random port and send a status heading to stderr on launch, also make error message a little clearer on where it is coming from

This commit is contained in:
John Barker 2011-05-30 12:36:03 +08:00
parent e12198152d
commit 92d731f425
3 changed files with 8 additions and 3 deletions

View File

@ -11,11 +11,14 @@ Server::Server(QObject *parent) : QObject(parent) {
bool Server::start() { bool Server::start() {
connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(handleConnection())); connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(handleConnection()));
return m_tcp_server->listen(QHostAddress::Any, 9200); return m_tcp_server->listen(QHostAddress::Any, 0);
}
quint16 Server::server_port() const {
return m_tcp_server->serverPort();
} }
void Server::handleConnection() { void Server::handleConnection() {
QTcpSocket *socket = m_tcp_server->nextPendingConnection(); QTcpSocket *socket = m_tcp_server->nextPendingConnection();
new Connection(socket, m_page, this); new Connection(socket, m_page, this);
} }

View File

@ -9,6 +9,7 @@ class Server : public QObject {
public: public:
Server(QObject *parent = 0); Server(QObject *parent = 0);
bool start(); bool start();
quint16 server_port() const;
public slots: public slots:
void handleConnection(); void handleConnection();

View File

@ -11,9 +11,10 @@ int main(int argc, char **argv) {
Server server; Server server;
if (server.start()) { if (server.start()) {
std::cerr << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl;
return app.exec(); return app.exec();
} else { } else {
std::cerr << "Couldn't start server" << std::endl; std::cerr << "Couldn't start capybara-webkit server" << std::endl;
return 1; return 1;
} }
} }