~nytpu/tlsada

bf8a3de789b25c7790605d7421f10f0479346999 — nytpu 1 year, 11 months ago edbfb13
TLS.Contexts.Write: Document better and clean up
1 files changed, 15 insertions(+), 9 deletions(-)

M src/tls-contexts.adb
M src/tls-contexts.adb => src/tls-contexts.adb +15 -9
@@ 287,21 287,27 @@ package body TLS.Contexts is

		Sz : Bs.ssize_t;
	begin
		-- Keep going until we write the entire buffer, since tls_write can
		-- decide to write as little as it wants.
		while Remaining > 0 loop
			Sz := Bs.tls_write(
				Ctx.Context.Context,
				Current,
				size_t(Remaining)
			);
			if Sz = -1 then
				raise Device_Error with "unable to write data: " &
					Retrieve_Error_Message(Ctx.Context);
			elsif Sz = Bs.TLS_WANT_POLLIN or Sz = Bs.TLS_WANT_POLLOUT then
				null;
			else
				Remaining := Remaining - Sz;
				Current := Current + Storage_Offset(Sz);
			end if;
			case Sz is
				when -1 =>
					raise Device_Error with "unable to write data: " &
						Retrieve_Error_Message(Ctx.Context);

				when Bs.TLS_WANT_POLLIN | Bs.TLS_WANT_POLLOUT => null;

				when others =>
					-- FIXME: pointer arithmetic, really? There has to be a
					-- better way to do this...
					Remaining := Remaining - Sz;
					Current := Current + Storage_Offset(Sz);
			end case;
		end loop;
	end Write;