Use signals/slots for QTcpSocket in Net_Connection

This patch makes Net_Connection use QTcpSocket signals.  It leaves the
->Run() interface which the client and server still call.  The next step
is to add signals to the Net_Connection interface so that the client and
server can also become event-driven.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Convert Net_Connection keepalive timers to QTimer

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Add signals to Net_Connection interface

Make it possible for Net_Connection to be used in an event-driven
fashion with the messagesReady() signal, which is emitted each time one
or more new messages arrive.

The disconnected() signal is emitted when the connection enters an error
state or has been closed.

For now the ->Run() method is still available so that the client and
server can be converted to an event-driven architecture independently.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Keep track of User_Group in User_Connection

Keep the User_Group in a User_Connection field so we don't have to pass
it around all the time.  This will be critical once we hook up the
Net_Connection signals/slots and we cannot pass the group directly to
the slot.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Hook up User_Connection to Net_Connection::messagesReady()

Process messages in a slot instead of polling in ->Run().

Note that processMessage() has a lot of reindentation changes but the
code is almost unchanged except that m_netcon.Run() has been removed
where unnecessary.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Cache remote address in Net_Connection

The QTcpSocket::peerAddress() is only available when the socket is in
the connected state.  Since we want to report the remote address on
disconnect we need to keep it cached.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Use signals/slots for User_Connection and User_Group

This patch removes ->Run() for User_Connection, User_Group, and Server.
These functions can be converted to event-driven code by processing
incoming network messages, responding to timeouts, and removing users on
disconnect using signals/slots.

The user lookup and authentication process also uses ->Run() but can
easily be converted to use signals/slots.

The main loop is still spins because we check whether SIGHUP or SIGINT
want to reload the configuration file or shutdown the server.  A future
patch will address this so wahjamsrv can finally use app.exec() and be
fully event-driven.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Fix User_Group and Server ownership

Take advantage of the QObject parent relationship so that User_Group is
a child of Server.  This ensures that User_Group is automatically
deleted when Server is destroyed without ad-hoc User_Group instance
ownership rules.

Reported-by: Ikkei Shimomura (tea) <Ikkei.Shimomura@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Adapt signal handlers to Qt event loop

This commit finally converts the main loop to app.exec().  The last
missing piece was the POSIX signal handlers that need to be adapted to
the Qt event loop.

Qt integration for POSIX signals is poor so we use ugly adapter code
that converts signals into writes on a socketpair(2) file descriptor.

The good news is that the server is now event-driven and only consumes
CPU when there is event processing work to be done!

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Remove Net_Connection::Send() "queue full" comment

Qt's QTcpConnection now handles the send queue for us and
Net_Message::Send() can no longer fail in this way.  Remove the comment.

Reported-by: Ikkei Shimomura (tea) <Ikkei.Shimomura@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>