3 //=============================================================================
9 //=============================================================================
11 #ifndef ACE_HTBP_SESSION_H
12 #define ACE_HTBP_SESSION_H
13 #include /**/ "ace/pre.h"
15 #include "ace/SOCK_IO.h"
16 #include "ace/Hash_Map_Manager.h"
17 #include "ace/Synch.h"
18 #include "ace/Message_Queue.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "HTBP_Addr.h"
25 #include "HTBP_Export.h"
26 #include "HTBP_Channel.h"
28 #include "HTBP_Stream.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 // Forward declarations.
33 class ACE_HTBP_Filter
;
34 class ACE_Event_Handler
;
48 bool operator ==(const Session_Id_t
&other
) const;
54 * @brief Defines the methods in the <Session> abstraction.
56 * A session is an entity that combines two Ht_Channels that connect directly
57 * to a proxy to manage communication with a remote peer. The Session may
58 * persist longer than either stream, assuming that the proxy is libel to
59 * close a connection at any time.
61 * This means that the session needs to be able to reconnect to the remote
62 * peer. This also means that the session needs to be aware of its location
63 * If it is outside the proxy and looses a stream, oh well. If it is inside,
64 * then the next time a stream is required, then it must reconnect before
65 * returning the stream.
67 * The session does not queue outbound messages. That is going to be the
68 * responsibility of the application, or a higher level protocol wrapper.
70 class HTBP_Export Session
73 // Initialization and termination methods.
77 /// Constructor (sets the underlying session id with <sid>).
78 Session (const Addr
& peer
,
81 ACE_INET_Addr
*proxy
= 0,
82 bool take_proxy
= false);
83 Session (const Session_Id_t
&id
,
84 ACE_INET_Addr
*proxy
= 0,
85 bool take_proxy
= false);
87 Session (const Session
&other
);
88 Session
& operator= (const Session
&other
);
93 /// The following methods are specific to the Session
94 static ACE_UINT32
next_session_id ();
96 static int add_session (Session
*);
97 static int remove_session (Session
*);
98 static int find_session (const Session_Id_t
&,
101 Stream
*stream () const;
102 void stream (Stream
*);
104 int enqueue (ACE_Message_Block
*msg
);
105 int flush_outbound_queue ();
107 int close_inbound () const;
108 int close_outbound () const;
110 /// get references to the actual streams based on the direction
111 /// of data flow if this session is on the inside of the proxy
112 /// ie, has a non-null proxy addr, then the inbound stream is
113 /// the out_to_in stream, otherwise it is the in_to_out
114 /// stream. The outbound is the opposite of the inbound.
115 /// Whenever an application wishes to send data, whether that is
116 /// request or reply data, it uses the outbound stream, and it
117 /// should associate an event handler with the inbound stream
118 /// for receiving data.
119 Channel
*inbound () const;
120 Channel
*outbound () const;
121 void inbound (Channel
*);
122 void outbound (Channel
*);
124 int enable (int value
);
125 int disable (int value
);
127 const Session_Id_t
& session_id() const;
128 void session_id (ACE_UINT32
);
130 const ACE_INET_Addr
*proxy_addr () const;
131 void proxy_addr (ACE_INET_Addr
*, int destroy
= 0);
133 const Addr
&peer_addr () const;
134 const Addr
&local_addr () const;
136 void peer_addr (const Addr
&);
137 void local_addr (const Addr
&);
139 /// invoke close on both streams, then remove self from session map
142 ACE_Event_Handler
*handler ();
143 void handler (ACE_Event_Handler
*);
144 void reactor (ACE_Reactor
*);
145 void detach (Channel
*);
147 int sock_flags() const;
150 /// Connected Stream ensures that the particular stream is
151 /// connected to the proxy, if possible. The result is same as
152 /// the reference passed in, so that it may be used inline for
153 /// the inboundor outbound methods
155 void reconnect () const;
156 void reconnect_i (Channel
*) const;
158 typedef ACE_Hash_Map_Manager
<Session_Id_t
, Session
*,
159 ACE_SYNCH_MUTEX
> Session_Map
;
160 typedef ACE_Hash_Map_Entry
<Session_Id_t
, Session
*> Map_Entry
;
161 static Session_Map session_map_
;
162 static ACE_UINT32 last_session_id_
;
163 static ACE_SYNCH_MUTEX session_id_lock_
;
165 ACE_INET_Addr
*proxy_addr_
;
166 int destroy_proxy_addr_
;
168 Session_Id_t session_id_
;
175 ACE_Event_Handler
*handler_
;
176 ACE_Reactor
*reactor_
;
178 ACE_Message_Queue
<ACE_SYNCH
> outbound_queue_
;
185 ACE_END_VERSIONED_NAMESPACE_DECL
187 #if defined (__ACE_INLINE__)
188 #include "HTBP_Session.inl"
191 #include /**/ "ace/post.h"
192 #endif /* ACE_HTBP_SESSION_H */