• Andres Freund's avatar
    Allow latches to wait for socket writability without waiting for readability. · 4bad60e3
    Andres Freund authored
    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 e42a21b9, 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
    Reviewed-By: Heikki Linnakangas, Noah Misch
    4bad60e3
unix_latch.c 19.5 KB