|Subject:||TidCookieManager questions (threads)|
|Posted by:||dk_sz (dk_…@hotmail.com)|
|Date:||Thu, 22 Mar 2007|
I need to share cookies between multiple threads
(I need to share session/login information across threads)
My [first solution] was to use a shared cookiemanager
(override TidHttp.SetCookieManager to avoid
multi threads AVs in notification system)
Advantages is speed and minimal locks. However, this
does not fully work (it sometimes work for a little time).
I suspect some data gets messed up, perhaps related to:
It seems like all access to raw TidCookies collection
data is not threadsafe (e.g. Items, Cookie) as opposed to
*LockCookieListByDomain / FCookieListByDomain*
OK, giving up on this I tried my second solution.
It consists of copying cookies back and forth
like this (slightly pseudo for readability):
UpdateCookieManager(const ACookieManagerUpdate, ACookieManagerShared:
E := ACookieManagerShared.CookieCollection.Count - 1;
for I := 0 to E do
O := ACookieManagerShared.CookieCollection[I];
N := ACookieManagerUpdate.CookieCollection.Add;
ACookieManagerUpdate.OnNewCookie := OnNewCookie_Handler;
OnNewCookie_Handler(ASender: TObject; ACookie: TIdCookieRFC2109; Var
VAccept := True;
TmpCookieNew := ACookieManagerShared.CookieCollection.Add;
However, this does not work at all. Session/cookie/login is
seemingly not maintained fully (?) across two different TidHttp
... even in non-threaded (!) VCL main thread environment.
So perhaps my copying is insufficuent? Can anyone help?
I had hoped I perhaps could replace TidCookieManager
entirely with my own, but as most methods are not virtual
etc. this does not seem like a feasible solution?