Improve non blocking opening and closing of sockets