~nytpu/tlsada

344160de006e5b01f9257a2daef55b25cc010e7c — nytpu 1 year, 11 months ago 0881e70
TLS.Contexts.Read: Substantially simplify return value handling
1 files changed, 4 insertions(+), 14 deletions(-)

M src/tls-contexts.adb
M src/tls-contexts.adb => src/tls-contexts.adb +4 -14
@@ 246,24 246,14 @@ package body TLS.Contexts is
				-- Alternatively:
				-- size_t(Item'Size + CHAR_BIT - 1) / CHAR_BIT
			);
			case Sz is
				when -1 =>
					raise Device_Error with "unable to read data: " &
						Retrieve_Error_Message(Ctx.Context);

				-- just keep making the call until tls_read is successful
				when Bs.TLS_WANT_POLLIN | Bs.TLS_WANT_POLLOUT => null;

				-- We got a successful tls_read
				when others => exit;
			end case;
			exit when Sz /= Bs.TLS_WANT_POLLIN and Sz /= Bs.TLS_WANT_POLLOUT;
		end loop;

		if Sz = 0 then
			Last := Stream_Element_Offset'First;
		elsif Sz < 0 then
		if Sz < 0 then
			raise Device_Error with "unable to read data: " &
				Retrieve_Error_Message(Ctx.Context);
		elsif Sz = 0 then
			Last := Stream_Element_Offset'First;
		else
			-- Subtract one from Item'First since C is zero-indexed while Item
			-- isn't necessarily.