Fix incorrect socket error handling and buffer overrun in ThreadedSocketConnection::send() method