Read at most max bytes from the underlying stream into buf,

without considering any eventual buffer

Returns how many bytes were read

Property definitions

core $ Reader :: raw_read_bytes
	# Read at most `max` bytes from the underlying stream into `buf`,
	# without considering any eventual buffer
	#
	# Returns how many bytes were read
	protected fun raw_read_bytes(buf: CString, max: Int): Int do
		var rd = 0
		for i in [0 .. max[ do
			var b = raw_read_byte
			if b < 0 then break
			buf[i] = b
			rd += 1
		end
		return rd
	end
lib/core/stream.nit:116,2--129,4

core $ BytesReader :: raw_read_bytes
	redef fun raw_read_bytes(ns, max) do
		if cursor >= bytes.length then return 0

		var copy = max.min(bytes.length - cursor)
		bytes.items.copy_to(ns, copy, cursor, 0)
		cursor += copy
		return copy
	end
lib/core/stream.nit:730,2--737,4

core $ ReaderProtocol :: raw_read_bytes
	redef fun raw_read_bytes(ns, len) do
		return origin.read_bytes_to_cstring(ns, len)
	end
lib/core/protocol.nit:35,2--37,4

core $ FileReader :: raw_read_bytes
	redef fun raw_read_bytes(cstr, max)
	do
		var nb = _file.as(not null).io_read(cstr, max)
		if last_error == null and _file.as(not null).ferror then
			last_error = new IOError("Cannot read `{path.as(not null)}`: {sys.errno.strerror}")
		end
		return nb
	end
lib/core/file.nit:136,2--143,4

socket $ TCPStream :: raw_read_bytes
	redef fun raw_read_bytes(ns, max) do
		var rd = native.read(ns, max)
		print "Read {rd} bytes"
		if rd < 0 then return -1
		return rd
	end
lib/socket/socket.nit:168,2--173,4

websocket $ WebsocketConnection :: raw_read_bytes
	redef fun raw_read_bytes(ns, len) do
		while not closed and frame_cursor >= frame_length do
			read_frame_info
		end
		if closed then return -1
		var available = frame_length - frame_cursor
		var to_rd = len.min(available)
		var rd = origin.read_bytes_to_cstring(ns, to_rd)
		if rd < 0 then
			close
			return 0
		end
		if has_mask then
			ns.xor(mask, rd, 4, mask_offset)
			mask_offset = rd % 4
		end
		frame_cursor += rd
		return rd
	end
lib/websocket/websocket.nit:259,2--277,4