Allow latches to wait for socket writability without waiting for readability

Enterprise / PostgreSQL - Andres Freund [anarazel.de] - 13 January 2015 05:58 UTC

So far WaitLatchOrSocket() required to pass in WL_SOCKET_READABLE as that solely was used to indicate error conditions, like EOF. Waiting for WL_SOCKET_WRITEABLE would have meant to busy wait upon socket errors.

Adjust the API to signal errors by returning the socket as readable, writable or both, depending on WL_SOCKET_READABLE/WL_SOCKET_WRITEABLE being specified. It would arguably be nicer to return WL_SOCKET_ERROR but that's not possible on platforms and would probably also result in more complex callsites.

This previously had explicitly been forbidden in e42a21b9e6c9, as there was no strong use case at that point. We now are looking into making FE/BE communication use latches, so changing this makes sense.

There also are some portability concerns because there cases of older platforms where select(2) is known to, in violation of POSIX, not return a socket as writable after the peer has closed it. So far the platforms where that's the case provide a working poll(2). If we find one where that's not the case, we'll need to add a workaround for that platform.

Discussion: 20140927191243.GD5423@alap3.anarazel.de

4bad60e Allow latches to wait for socket writability without waiting for readability.
src/backend/port/unix_latch.c | 31 ++++++++++++++++++++++++-------
src/backend/port/win32_latch.c | 15 ++++++++++-----
2 files changed, 34 insertions(+), 12 deletions(-)

Upstream: git.postgresql.org


  • Share