Read as many bytes from socket as specified in length.
        Loop as long as every byte is read unless exception is raised.
350617
def read(self, length):
        
        data = bytearray()
        while len(data) != length:
            data += self.sock.recv((length - len(data)))
            if not data:
                raise ConnectionError('Connection unexpectedly closed.')
        return data
44257
def _read(self, n):
        
        result = self.sslobj.read(n)

        while len(result) < n:
            s = self.sslobj.read(n - len(result))
            if not s:
                raise IOError('Socket closed')
            result += s

        return result
551243
def _read(self, size):
        
        data = ''
        while len(data) < size:
            try:
                chunk = self.socket.recv(size-len(data))
            except socket.error as (err, msg):
                self.connected = False
                raise ScratchError("[Errno %d] %s" % (err, msg))
            if chunk == '':
                self.connected = False
                raise ScratchConnectionError("Connection broken")
            data += chunk
        return data
571955
def _read_loop(self, data=''):
        
        while True:
            if not self.is_connected or self.is_connecting or self.io.closed():
                break

            try:
                yield self.io.read_bytes(
                    DEFAULT_READ_CHUNK_SIZE,
                    streaming_callback=self._ps.parse,
                    partial=True)
            except tornado.iostream.StreamClosedError as e:
                self._err = e
                if self._error_cb is not None and not self.is_reconnecting and not self.is_closed:
                    self._error_cb(e)
                break
712232
def read_bytes(self, num_bytes):
        """"""
        buffer_size = len(self._buffer)
        if buffer_size > num_bytes:
            # The buffer is larger than the requested amount of bytes.
            data, self._buffer = self._buffer[:num_bytes], self._buffer[num_bytes:]
        elif 0 < buffer_size <= num_bytes:
            # This might return less bytes than requested.
            data, self._buffer = self._buffer, bytearray()
        else:
            # Buffer is empty. Try to read `num_bytes` and call `read_bytes()`
            # again. This ensures that at most `num_bytes` are returned.
            self._buffer += self.__read__(num_bytes)
            return self.read_bytes(num_bytes)
        return data
321215
public synchronized int read( byte[] b, int off, int len ) throws IOException {
        if( len == 0 ) {
            return 0;
        }
        tot = 0;

        while( true ) {
            while( bip > 0 ) {
                n = in.read( b, off, Math.min( len, bip ));
                if( n == -1 ) {
                    return tot > 0 ? tot : -1;
                }
                tot += n;
                off += n;
                len -= n;
                bip -= n;
                if( len == 0 ) {
                    return tot;
                }
            }

            switch( SessionServicePacket.readPacketType( in, header, 0 )) {
                case SessionServicePacket.SESSION_KEEP_ALIVE:
                    break;
                case SessionServicePacket.SESSION_MESSAGE:
                    bip = SessionServicePacket.readLength( header, 0 );
                    break;
                case -1:
                    if( tot > 0 ) {
                        return tot;
                    }
                    return -1;
            }
        }
    }
929304
def read(self, size=1):
        
        if self.is_closed_flag:
            raise Exception("Unable to read - already closed!")
        if self.get_remaining_size() < size:
            raise Exception("Unable to read byte buffer - too short remaining data size!")
        self.read_count += size
        return self.file.read(size)
640338
def read(sock, count):
    
    data = None

    try:
        data = sock.recv(count)
    except ssl.SSLError as e:
        return data, e.errno, e.strerror if strerror else e.message
    except socket.herror as (errnum, errmsg):
        return data, errnum, errmsg
    except socket.gaierror as (errnum, errmsg):
        return data, errnum, errmsg
    except socket.timeout:
        return data, errno.ETIMEDOUT, "Connection timed out"
    except socket.error as (errnum, errmsg):
        return data, errnum, errmsg
    
    ba_data = bytearray(data)
    
    if len(ba_data) == 0:
        return ba_data, errno.ECONNRESET, "Connection closed"
    
    return ba_data, 0, ""
150375
public int read(byte []buf, int offset, int length)
    throws IOException
  {
    try {
      if (_s == null || _is == null)
        return -1;

      int readLength = _is.read(buf, offset, length);

      if (readLength >= 0)
        _totalReadBytes += readLength;

      return readLength;
    } catch (InterruptedIOException e) {
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      if (_throwReadInterrupts)
        throw e;

      log.log(Level.FINER, e.toString(), e);
    }

    return -1;
  }
253891
def read(self, size=-1):
        """"""
        if self.connected is None:
            return None

        # Extract requested amount of data from the read buffer.
        data = self._get_input(size)

        return data
485171
def read(self, len=1024, buffer=None):
        

        try:
            return self._wrap_socket_library_call(
                lambda: SSL_read(self._ssl.value, len, buffer), ERR_READ_TIMEOUT)
        except openssl_error() as err:
            if err.ssl_error == SSL_ERROR_SYSCALL and err.result == -1:
                raise_ssl_error(ERR_PORT_UNREACHABLE, err)
            raise
56717
def read( nbytes )
      while @read_buffer.length < nbytes
        @read_buffer << socket.readpartial(nbytes - @read_buffer.length)
      end

      result = @read_buffer.slice!(0, nbytes)

      $stderr.puts "<-- #{result}" if $DEBUG
      return result
    rescue KJess::NetworkError
      close
      raise
    rescue => e
      close
      raise Error, "Could not read from #{host}:#{port}: #{e.class}: #{e.message}", e.backtrace
    end
651006
def _read_callback(connection_id, data_buffer, data_length_pointer):
    
    wrapped_socket = None
    try:
        wrapped_socket = _connection_refs.get(connection_id)
        if wrapped_socket is None:
            return SecurityConst.errSSLInternal
        base_socket = wrapped_socket.socket

        requested_length = data_length_pointer[0]

        timeout = wrapped_socket.gettimeout()
        error = None
        read_count = 0

        try:
            while read_count < requested_length:
                if timeout is None or timeout >= 0:
                    if not util.wait_for_read(base_socket, timeout):
                        raise socket.error(errno.EAGAIN, 'timed out')

                remaining = requested_length - read_count
                buffer = (ctypes.c_char * remaining).from_address(
                    data_buffer + read_count
                )
                chunk_size = base_socket.recv_into(buffer, remaining)
                read_count += chunk_size
                if not chunk_size:
                    if not read_count:
                        return SecurityConst.errSSLClosedGraceful
                    break
        except (socket.error) as e:
            error = e.errno

            if error is not None and error != errno.EAGAIN:
                data_length_pointer[0] = read_count
                if error == errno.ECONNRESET or error == errno.EPIPE:
                    return SecurityConst.errSSLClosedAbort
                raise

        data_length_pointer[0] = read_count

        if read_count != requested_length:
            return SecurityConst.errSSLWouldBlock

        return 0
    except Exception as e:
        if wrapped_socket is not None:
            wrapped_socket._exception = e
        return SecurityConst.errSSLInternal
1345030
public int read(CharBuffer buf, int length) throws IOException
  {
    int len = buf.length();

    buf.length(len + length);
    
    int readLength = read(buf.buffer(), len, length);
    
    if (readLength < 0) {
      buf.length(len);
    }
    else if (readLength < length) {
      buf.length(len + readLength);
    }

    return length;
  }
153941
def recvall(sock, size):
    
    data = b""
    while len(data) < size:
        s = sock.recv(size - len(data))
        data += s
        if not s:
            raise RuntimeError("did not receive data from socket "
                               "(size {}, got only {!r})".format(size, data))
    return data
1029550
def readBytes(self, size):
        

        # try to satisfy the read from any buffered data
        if self._iobuf:
            if size >= len(self._iobuf):
                res = self._iobuf
                self.buf = None
                return res
            res = self._iobuf[:size]
            self._iobuf = self._iobuf[size:]
            return res

        # We need to initiate a read
        buf = ctypes.create_string_buffer(size)
        olap = OVERLAPPED()
        olap.hEvent = self._waitable

        log("made read buff of size %d", size)

        # ReadFile docs warn against sending in the nread parameter for async
        # operations, so we always collect it via GetOverlappedResultEx
        immediate = ReadFile(self.pipe, buf, size, None, olap)

        if not immediate:
            err = GetLastError()
            if err != ERROR_IO_PENDING:
                self._raise_win_err("failed to read %d bytes" % size, err)

        nread = wintypes.DWORD()
        if not self._get_overlapped_result_ex(
            self.pipe, olap, nread, 0 if immediate else self.timeout, True
        ):
            err = GetLastError()
            CancelIoEx(self.pipe, olap)

            if err == WAIT_TIMEOUT:
                log("GetOverlappedResultEx timedout")
                raise SocketTimeout(
                    "timed out after waiting %dms for read" % self.timeout
                )

            log("GetOverlappedResultEx reports error %d", err)
            self._raise_win_err("error while waiting for read", err)

        nread = nread.value
        if nread == 0:
            # Docs say that named pipes return 0 byte when the other end did
            # a zero byte write.  Since we don't ever do that, the only
            # other way this shows up is if the client has gotten in a weird
            # state, so let's bail out
            CancelIoEx(self.pipe, olap)
            raise IOError("Async read yielded 0 bytes; unpossible!")

        # Holds precisely the bytes that we read from the prior request
        buf = buf[:nread]

        returned_size = min(nread, size)
        if returned_size == nread:
            return buf

        # keep any left-overs around for a later read to consume
        self._iobuf = buf[returned_size:]
        return buf[:returned_size]
637231
def read(self, n):
        
        buf = self._read_buf
        pos = self._read_pos
        end = pos + n

        if end <= len(buf):
            # Fast path: the data to read is fully buffered.
            self._read_pos += n
            return self._update_pos(buf[pos:end])

        # Slow path: read from the stream until enough bytes are read,
        # or until an EOF occurs or until read() would block.
        wanted = max(self.buffer_size, n)
        while len(buf) < end:
            chunk = self.raw.read(wanted)
            if not chunk:
                break
            buf += chunk

        self._read_buf = buf[end:]  # Save the extra data in the buffer.
        self._read_pos = 0
        return self._update_pos(buf[pos:end])