test: Fix tls tests which fail sporadically

The count of ECONNRESETs is dependent on timing, and thus unreliable,
especially on Linux machines.
test: Fix regression in tls test

Undefined reference, introduced by a77c29a.
tls: Write pending data on socket drain

Fixes #4800