Page Speed Optimization Libraries  1.4.26.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions
net_instaweb::SyncFetcherAdapterCallback Class Reference

Class to help run an asynchronous fetch synchronously with a timeout. More...

#include "sync_fetcher_adapter_callback.h"

Inheritance diagram for net_instaweb::SyncFetcherAdapterCallback:
net_instaweb::AsyncFetch net_instaweb::Writer

List of all members.

Public Member Functions

 SyncFetcherAdapterCallback (ThreadSystem *thread_system, Writer *writer, const RequestContextPtr &request_context)
void Release ()
bool done () const
bool success () const
bool released () const
bool LockIfNotReleased ()
void Unlock ()
 Releases mutex acquired by a successful LockIfNotReleased() call.

Protected Member Functions

virtual void HandleDone (bool success)
virtual bool HandleWrite (const StringPiece &content, MessageHandler *handler)
virtual bool HandleFlush (MessageHandler *handler)
virtual void HandleHeadersComplete ()

Detailed Description

Class to help run an asynchronous fetch synchronously with a timeout.


Member Function Documentation

If this fetcher hasn't yet been released(), returns true with mutex_ held. Otherwise, returns false with the mutex_ released. These methods should be used to guard accesses to writer() and response_headers().

When implementing a synchronous fetch with a timeout based on an underlying asynchronous mechanism, we need to ensure that we don't write to freed memory if the Done callback fires after the timeout.

So we need to make sure the Writer and Response Buffers are owned by this Callback class, which will forward the output and headers to the caller *if* it has not been released by the time the callback is called.

If this object may be accessed from multiple threads (e.g. due to async rewrites), you should use LockIfNotReleased() and Unlock() to guard access to these. When the 'owner' of this callback -- the code that calls 'new' -- is done with it, it can call release. This will only delete the callback if Done() has been called. Otherwise it will stay around waiting for Done() to be called, and only then will it be deleted.

When Release is called prior to Done(), the writer and response_headers will be NULLed out in this structure so they will not be updated when Done() is finally called.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines