Tidied up socket blocking and thread registration