centralise the setsockopt code in one place instead of duplicating workarounds.