Receive an answer from the daemon and return the response.

    Args:
    socket (socket.socket): A socket that is connected to the daemon.

    Returns:
        dir or string: The unpickled answer.
480451
def receive_data(socket):
    
    answer = b""
    while True:
        packet = socket.recv(4096)
        if not packet: break
        answer += packet
    response = pickle.loads(answer)
    socket.close()
    return response
364927
def _receive_all(self):
        
        (data, part) = ('', '')
        if is_py3:
            crlf_bytes = bytes(self.__CRLF, encoding=self.__encoding)
        else:
            crlf_bytes = self.__CRLF

        while self._running and part[-2:] != crlf_bytes:
            try:
                part = self._socket.recv(self.buffer_size)
            except (socket.timeout, socket.error) as e:
                if self._running:
                    self.stop()
                    raise SocketError('[Connect: %s]: Socket %s' % (self._unique_id, e))
                else:
                    return  # 133, prevents error if stop is called mid recv

            # an empty string indicates the server shutdown the socket
            if len(part) == 0:
                self.stop()
                raise SocketError('Connection closed by server')

            data += part.decode(self.__encoding)
        return data
157868
def recv(self):
        """"""
        LOGGER.debug('Receiving')
        try:
            message_length = struct.unpack('>i', self._socket.recv(4))[0]
            message_length -= Connection.COMM_LENGTH
            LOGGER.debug('Length: %i', message_length)
        except socket.timeout:
            return None
        
        comm_status = struct.unpack('>i', self._socket.recv(4))[0]
        LOGGER.debug('Status: %i', comm_status)
        bytes_received = 0
        message = b""
        
        while bytes_received < message_length:
            if message_length - bytes_received >= 1024:
                recv_len = 1024
            else:
                recv_len = message_length - bytes_received
            bytes_received += recv_len
            LOGGER.debug('Received %i', bytes_received)
            message += self._socket.recv(recv_len)
        
        if comm_status == 0:
            message = self._crypt.decrypt(message)
        else:
            return Message(len(message), Connection.COMM_ERROR, message)
        
        msg = Message(message_length, comm_status, message)

        return msg
133799
def _receive(self):
        
        result = self._talk.get()
        if not result:
            self._logger.error('Failed to receive')
        return result
242624
private static List<ResponsePacket> readResponses(Socket socket) {
		List<ResponsePacket> responses = new Vector<ResponsePacket>();
		int previousTimeout = 0;
		try {
			/* Set socket timeout to avoid getting stuck on read() */
			try {
				previousTimeout = socket.getSoTimeout();
				socket.setSoTimeout(TIMEOUT);
			} catch (Exception e) {
			}
			InputStream input = socket.getInputStream();
			while (true) {
				ResponsePacket packet = readResponsePacketData(input);
				if (packet != null) responses.add(packet);
				else break;
			}

		} catch (Exception e) {
			/* Ignore exception, as we are expecting timeout exceptions because Apple might not reply anything */
			//System.out.println(e);
		}
		/* Reset socket timeout, just in case */
		try {
			socket.setSoTimeout(previousTimeout);
		} catch (Exception e) {
		}
		//System.out.println("Received "+responses.size()+" response packets");
		return responses;
	}
1083952
def readn(self, n):
        
        data = ''

        while len(data) < n:
            received = self.sock.recv(n - len(data))

            if not len(received):
                raise socket.error('no data read from socket')

            data += received

        return data
575510
def send_message(
        self, request: str, response_expected: bool, **kwargs: Any
    ) -> Response:
        
        self.socket.send_string(request)
        return Response(self.socket.recv().decode())
1364009
def _check_with_socket(self, sock_info, metadata=None):
        
        cmd = SON([('ismaster', 1)])
        if metadata is not None:
            cmd['client'] = metadata
        start = _time()
        request_id, msg, max_doc_size = message.query(
            0, 'admin.$cmd', 0, -1, cmd,
            None, DEFAULT_CODEC_OPTIONS)

        # TODO: use sock_info.command()
        sock_info.send_message(msg, max_doc_size)
        raw_response = sock_info.receive_message(1, request_id)
        result = helpers._unpack_response(raw_response)
        return IsMaster(result['data'][0]), _time() - start
844588
def _recv(self):
        
        prefix = self._read(self.prefix_len)
        msg = self._read(self._extract_len(prefix))
        return prefix + msg
1206093
def send(self, message):
        
        message = message.SerializeToString()
        self.socket.sendall(struct.pack('!I', len(message)) + message)

        length = struct.unpack('!I', self.socket.recv(4))[0]
        response = riemann_client.riemann_pb2.Msg()
        response.ParseFromString(socket_recvall(self.socket, length))

        if not response.ok:
            raise RiemannError(response.error)

        return response
757019
def read(self):
        ""
        if self.verbose > 1:
            sys.stderr.write("poll: reading from daemon...\n")
        eol = self.linebuffer.find('\n')
        if eol == -1:
            frag = self.sock.recv(4096)
            self.linebuffer += frag
            if self.verbose > 1:
                sys.stderr.write("poll: read complete.\n")
            if not self.linebuffer:
                if self.verbose > 1:
                    sys.stderr.write("poll: returning -1.\n")
                # Read failed
                return -1
            eol = self.linebuffer.find('\n')
            if eol == -1:
                if self.verbose > 1:
                    sys.stderr.write("poll: returning 0.\n")
                # Read succeeded, but only got a fragment
                return 0
        else:
            if self.verbose > 1:
                sys.stderr.write("poll: fetching from buffer.\n")

        # We got a line
        eol += 1
        self.response = self.linebuffer[:eol]
        self.linebuffer = self.linebuffer[eol:]

        # Can happen if daemon terminates while we're reading.
        if not self.response:
            return -1
        if self.verbose:
            sys.stderr.write("poll: data is %s\n" % repr(self.response))
        self.received = time.time()
        # We got a \n-terminated line
        return len(self.response)
936790
def recv(self, timeout=None):
        
        if timeout:
            timeout *= 1000.

        for sub in list(self.subscribers) + self._hooks:
            self.poller.register(sub, POLLIN)
        self._loop = True
        try:
            while self._loop:
                sleep(0)
                try:
                    socks = dict(self.poller.poll(timeout=timeout))
                    if socks:
                        for sub in self.subscribers:
                            if sub in socks and socks[sub] == POLLIN:
                                m__ = Message.decode(sub.recv_string(NOBLOCK))
                                if not self._filter or self._filter(m__):
                                    if self._translate:
                                        url = urlsplit(self.sub_addr[sub])
                                        host = url[1].split(":")[0]
                                        m__.sender = (m__.sender.split("@")[0]
                                                      + "@" + host)
                                    yield m__

                        for sub in self._hooks:
                            if sub in socks and socks[sub] == POLLIN:
                                m__ = Message.decode(sub.recv_string(NOBLOCK))
                                self._hooks_cb[sub](m__)
                    else:
                        # timeout
                        yield None
                except ZMQError as err:
                    LOGGER.exception("Receive failed: %s", str(err))
        finally:
            for sub in list(self.subscribers) + self._hooks:
                self.poller.unregister(sub)
765606
def client(addr):
        """"""
        success = False
        while not success:
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sock.connect(addr)
                success = True
            except socket.error as err:
                sock.close()
        talk = SocketTalk(sock)
        return talk
944656
def get_client_sock(addr):
    ""
    s = _socket.create_connection(addr)
    s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, True)
    s.setblocking(False)
    return s
951718
async def recv(self, nbytes: int = -1, **kwargs) -> bytes:
        '''
        
        '''
        return await asynclib.recv(self.sock, nbytes, **kwargs)
1135262
def result
      line = @sock.gets
      debug "< #{line}" if @debug
      raise Errno::ECONNRESET, "No response" unless line
      chr = line[0]
      if chr == '+'
        line[1..-1].strip
      elsif chr == '$'
        count = line[1..-1].strip.to_i
        return nil if count == -1
        data = @sock.read(count) if count > 0
        line = @sock.gets # read extra linefeeds
        data
      elsif chr == '-'
        # Server can respond with:
        #
        # -ERR Something unexpected
        # We raise a CommandError
        #
        # -NOTUNIQUE Job not unique
        # We return ["NOTUNIQUE", "Job not unique"]
        err = line[1..-1].split(" ", 2)
        raise CommandError, err[1] if err[0] == "ERR"
        err
      else
        # this is bad, indicates we need to reset the socket
        # and start fresh
        raise ParseError, line.strip
      end
    end
209827
def receive(self, command_id, streams=('stdout', 'stderr'), command_timeout=60):
        
        logging.info('receive command: ' + command_id)
        response_streams = dict.fromkeys(streams, '')
        (complete, exit_code) = self._receive_poll(command_id, response_streams)
        while not complete:
            (complete, exit_code) = self._receive_poll(command_id, response_streams)

        # This retains some compatibility with pywinrm
        if sorted(response_streams.keys()) == sorted(['stderr', 'stdout']):
            return response_streams['stdout'], response_streams['stderr'], exit_code
        else:
            return response_streams, exit_code