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() {
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() {
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
new Connection(socket, m_page, this);
}

View File

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

View File

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