Export (0) Print
Expand All

IHttpUser::ReferenceUser Method

IIS 7.0

Increments the user internal reference count.

virtual VOID ReferenceUser(
   VOID
) = 0;

This method takes no parameters.

Classes that implement the IHttpUser interface are thread safe for the ReferenceUser and DereferenceUser methods.

Classes that implement the IHttpUser interface use reference counting that is thread safe for memory management. When an IHttpUser pointer is constructed, the internal reference count (a private member variable) is set to 1. When the ReferenceUser method is called, this reference count is incremented by 1. When the DereferenceUser method is called, this same reference count is decremented by 1. The IHttpUser interface is removed from the heap only when the reference count goes to 0. This scheme guarantees that the IHttpUser pointer will not be deleted until the last client of that pointer calls the DereferenceUser method.

The ReferenceUser and DereferenceUser method implementations should be thread safe for an IHttpUser pointer. Implementers should provide only private or protected destructors that are called only when the reference count goes to 0.

Clients should never attempt to cast an IHttpUser interface to a more specific class and then call delete directly; clients should instead call the ReferenceUser method exactly once when a pointer to an IHttpUser interface is retrieved, and then call the DereferenceUser method when the IHttpUser interface will no longer be accessed. You should call the ReferenceUser and DereferenceUser methods as early and as late as possible, respectively, to guarantee that an IHttpUser pointer will be valid on the heap when it is accessed and deleted when it is no longer needed.

The following code example demonstrates a class called MyHttpUser that implements the IHttpUser interface.

// Create a class that implements the IHttpUser interface.
class MyHttpUser : public IHttpUser
{
public:
    // Create a public constructor.
    // Set the internal reference count to 1.
    MyHttpUser()
    {
        m_cRefs = 1;
    }

    // Increment the internal reference count.
    virtual VOID ReferenceUser(VOID)
    {
        InterlockedIncrement(&m_cRefs);
    }

    // Decrement the internal reference count.
    virtual VOID DereferenceUser(VOID)
    {
        // Decrement the reference count and call delete this
        // if the count is 0.
        if (0 == InterlockedDecrement(&m_cRefs))
        {
            delete this;
        }
    }

private:
    // Create a private destructor called from DereferenceUser.
    virtual ~MyHttpUser()
    {

    }

    // Create a private reference count member.
    LONG m_cRefs;
}

Type

Description

Client

  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS Express 7.5 on Windows XP, Windows Vista, Windows 7

  • IIS 8.0 on Windows 8 Client

Server

  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS Express 7.5 on Windows Server 2003, Windows Server 2008, Windows Server 2008 R2

  • IIS 8.0 on Windows Server 2012

Product

IIS 7.0, IIS 7.5, IIS Express 7.5, IIS 8.0

Header

Httpserv.h

Community Additions

ADD
Show:
© 2014 Microsoft