Page Speed Optimization Libraries  1.7.30.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Public Attributes | 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

List of all members.

Classes

class  ProtectedWriter

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 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 ()

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(). 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.

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.


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