mainloop: Simplify the keepalive functions

Moving the "compare values + update timeout" logic into a helper function
lets us delete several duplicated checks and temporary variables.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
dtls: Fix link error on !HAVE_DTLS builds

Several internal library functions call dtls_close() to clean up, so just
make it a stub function if this is a non-DTLS build.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>