fix some issues when reading sockets