Page Speed Optimization Libraries
1.13.35.1
|
Class to help run an asynchronous fetch synchronously with a timeout. More...
#include "sync_fetcher_adapter_callback.h"
Public Member Functions | |
SyncFetcherAdapterCallback (ThreadSystem *thread_system, Writer *writer, const RequestContextPtr &request_context) | |
void | Release () LOCKS_EXCLUDED(mutex_) |
bool | IsDone () const LOCKS_EXCLUDED(mutex_) |
bool | IsDoneLockHeld () const EXCLUSIVE_LOCKS_REQUIRED(mutex_) |
Version of IsDone() that may only be called if you already hold the mutex. | |
bool | success () const LOCKS_EXCLUDED(mutex_) |
bool | released () const LOCKS_EXCLUDED(mutex_) |
bool | LockIfNotReleased () EXCLUSIVE_TRYLOCK_FUNCTION(true |
void | Unlock () UNLOCK_FUNCTION(mutex_) |
Releases mutex acquired by a successful LockIfNotReleased() call. | |
void | TimedWait (int64 timeout_ms) EXCLUSIVE_LOCKS_REQUIRED(mutex_) |
Public Member Functions inherited from net_instaweb::AsyncFetch | |
AsyncFetch (const RequestContextPtr &request_ctx) | |
void | HeadersComplete () |
void | Done (bool success) |
virtual bool | Write (const StringPiece &content, MessageHandler *handler) |
virtual bool | Flush (MessageHandler *handler) |
virtual bool | IsCachedResultValid (const ResponseHeaders &headers) |
RequestHeaders * | request_headers () |
void | set_request_headers (RequestHeaders *headers) |
void | SetRequestHeadersTakingOwnership (RequestHeaders *headers) |
Same as above, but takes ownership. | |
const RequestHeaders * | request_headers () const |
ResponseHeaders * | response_headers () |
See doc for request_headers and set_request_headers. | |
void | set_response_headers (ResponseHeaders *headers) |
ResponseHeaders * | extra_response_headers () |
void | set_extra_response_headers (ResponseHeaders *headers) |
virtual bool | IsBackgroundFetch () const |
virtual void | Reset () |
bool | headers_complete () const |
bool | content_length_known () const |
int64 | content_length () const |
void | set_content_length (int64 x) |
GoogleString | LoggingString () |
virtual const RequestContextPtr & | request_context () |
virtual AbstractLogRecord * | log_record () |
void | FixCacheControlForGoogleCache () |
Public Member Functions inherited from net_instaweb::Writer | |
virtual bool | Dump (Writer *writer, MessageHandler *message_handler) |
Public Attributes | |
bool | mutex_ |
Protected Member Functions | |
virtual void | HandleDone (bool success) LOCKS_EXCLUDED(mutex_) |
virtual bool | HandleWrite (const StringPiece &content, MessageHandler *handler) |
virtual bool | HandleFlush (MessageHandler *handler) |
virtual void | HandleHeadersComplete () |
Additional Inherited Members | |
Static Public Member Functions inherited from net_instaweb::AsyncFetch | |
static bool | IsGoogleCacheVia (StringPiece via_value) |
Static Public Attributes inherited from net_instaweb::AsyncFetch | |
static const int | kContentLengthUnknown = -1 |
Class to help run an asynchronous fetch synchronously with a timeout.
bool net_instaweb::SyncFetcherAdapterCallback::LockIfNotReleased | ( | ) |
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().
void net_instaweb::SyncFetcherAdapterCallback::Release | ( | ) |
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(). That will arrange for the object to be deleted as soon as it's safe to do so, which may be immediately at the point of call, or from some asynchronous event. The object should not be used by the owner after Release() has been called.
void net_instaweb::SyncFetcherAdapterCallback::TimedWait | ( | int64 | timeout_ms | ) |
Waits on condition variable associated with the mutex, with timeout of timeout_ms. The wake up condition is Done() being called, but this merely waits for lookup and does not ensure the condition has occurred — the caller should use a while loop conditioned on done_lock_held(). Should not be called if this callback is already released, and expects mutex already held.