Send keepalives from walsender even when busy sending WAL.
Send keepalives from walsender even when busy sending WAL.

If walsender doesn't hear from the client for the time specified by
wal_sender_timeout, it will conclude the connection or client is dead, and
disconnect. When half of wal_sender_timeout has elapsed, it sends a ping
to the client, leaving it the remainig half of wal_sender_timeout to
respond. However, it only checked if half of wal_sender_timeout had elapsed
when it was about to sleep, so if it was busy sending WAL to the client for
long enough, it would not send the ping request in time. Then the client
would not know it needs to send a reply, and the walsender will disconnect
even though the client is still alive. Fix that.

Andres Freund, reviewed by Robert Haas, and some further changes by me.
Backpatch to 9.3. Earlier versions relied on the client to send the
keepalives on its own, and hence didn't have this problem.

adam8157/gpdb,ashwinstar/gpdb,techdragon/Postgres-XL,techdragon/Postgres-XL,50wu/gpdb,lisakowen/gpdb,ovr/postgres-xl,adam8157/gpdb,pavanvd/postgres-xl,Postgres-XL/Postgres-XL,ashwinstar/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,50wu/gpdb,xinzweb/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,yazun/postgres-xl,xinzweb/gpdb,ovr/postgres-xl,pavanvd/postgres-xl,adam8157/gpdb,50wu/gpdb,jmcatamney/gpdb,ovr/postgres-xl,oberstet/postgres-xl,xinzweb/gpdb,oberstet/postgres-xl,adam8157/gpdb,techdragon/Postgres-XL,greenplum-db/gpdb,ovr/postgres-xl,lisakowen/gpdb,Postgres-XL/Postgres-XL,50wu/gpdb,lisakowen/gpdb,zeroae/postgres-xl,oberstet/postgres-xl,greenplum-db/gpdb,ovr/postgres-xl,xinzweb/gpdb,yazun/postgres-xl,jmcatamney/gpdb,lisakowen/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,Postgres-XL/Postgres-XL,ashwinstar/gpdb,techdragon/Postgres-XL,xinzweb/gpdb,50wu/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,adam8157/gpdb,ashwinstar/gpdb,xinzweb/gpdb,pavanvd/postgres-xl,50wu/gpdb,Postgres-XL/Postgres-XL,adam8157/gpdb,xinzweb/gpdb,xinzweb/gpdb,ashwinstar/gpdb,lisakowen/gpdb,pavanvd/postgres-xl,greenplum-db/gpdb,50wu/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,adam8157/gpdb,yazun/postgres-xl,pavanvd/postgres-xl,yazun/postgres-xl,zeroae/postgres-xl,zeroae/postgres-xl,techdragon/Postgres-XL,jmcatamney/gpdb,zeroae/postgres-xl,yazun/postgres-xl,50wu/gpdb,lisakowen/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,lisakowen/gpdb,Postgres-XL/Postgres-XL,greenplum-db/gpdb,oberstet/postgres-xl,lisakowen/gpdb