----------------------------------------------------------------------------- -- -- Onions Network Streams Library -- -- O N I O N S . O U T S T R E A M S . C H A N N E L -- -- B o d y -- -- Copyright (C) 1997-1998 Regents of the University of California -- -- Onions is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation, with or without the single exception listed below; -- either version 2, or (at your option) any later version. Onions is -- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- distributed with Onions; see the file COPYING. If not, write to the -- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- As a special exception, if other files instantiate generics from this -- library, or you link this library with other files to produce an -- executable, this library does not by itself cause the resulting -- executable to be covered by the GNU General Public License. This -- exception does not however invalidate any other reasons why the -- executable file might be covered by the GNU General Public License. -- -- Created in 1997 by Roy T. Fielding and Kari Nies ----------------------------------------------------------------------------- -- -- The Channel Output Stream is a stream end that acts as a filter between -- the client and the connection established by the connection manager. -- This filter is needed so that the normal close, abort, and reset calls -- on the stream can be intercepted and handled by the connection manager, -- thus enabling multiple streams to use the same socket connection as -- in HTTP/1.1 persistent connections. A similar Mux filter could be -- used to implement HTTP-NG multiplexing. -- with Interfaces.C; with Onions.Buckets; use Onions.Buckets; with Onions.Connections; with Unchecked_Deallocation; package body Onions.Outstreams.Channel is use Bucket_Queues; use type C.int; --------------------------------------------- -- Dispatching Stream Control Operations -- --------------------------------------------- procedure Dispose is new Unchecked_Deallocation (Channel_Output_Stream, Channel_Output_Stream_Ptr); -- Free the storage associated with a stream object. -- procedure Free (SP : in out Channel_Output_Stream_Ptr) is ItemList : Bucket_List; begin if SP /= null then if Length (SP.Unprocessed) > 0 then Dequeue (SP.Unprocessed, ItemList); Free (ItemList); end if; if SP.Outbound /= null then Abort_Stream (SP.all); end if; Dispose (SP); end if; end Free; -- Bind the channel to a connection object. -- function Bind (Stream : in Channel_Output_Stream_Ptr; Connie : in Onions.Connections.A_Connection) return Output_Pipe is begin Stream.Conn := Connie; return Output_Pipe (Stream); end Bind; -- Close the channel by handing it back to the connection manager. -- procedure Close (Stream : in out Channel_Output_Stream) is ItemList : Bucket_List; begin Flush (Stream); Onions.Connections.Close_Outgoing (Stream.Conn); Stream.Outbound := null; end Close; -- Abort_Stream should only be used if a stream is interrupted -- by the user, or an error occurs that makes the whole stream bad. -- It forces the stream closed without a flush. -- procedure Abort_Stream (Stream : in out Channel_Output_Stream) is ItemList : Bucket_List; begin if Length (Stream.Unprocessed) > 0 then Dequeue (Stream.Unprocessed, ItemList); Free (ItemList); end if; Onions.Connections.Abort_Outgoing (Stream.Conn); Stream.Outbound := null; end Abort_Stream; -- Reset the channel to its original state without closing it. -- procedure Reset (Stream : in out Channel_Output_Stream) is begin Flush (Stream); Stream.Byte_Count := 0; Stream.Timeout := 0; Stream.System_Error := 0; end Reset; -- Name returns a string containing the currently open server address. -- function Name (Stream : in Channel_Output_Stream) return String is begin return Onions.Connections.Name (Stream.Conn); end Name; -- We inherit Flush, Process, and Ada.Streams Write. end Onions.Outstreams.Channel;