LOG(("handle dataevent=%8lX\n",(long)this));
nsOnDataAvailableEvent::HandleEvent(){    LOG(("nsOnDataAvailableEvent: HandleEvent [req=%x]", mRequest.get()));    if (NS_FAILED(mProxy->GetListenerStatus())) {        LOG(("nsOnDataAvailableEvent: Discarding event [listener_status=%x, req=%x]\n",            mProxy->GetListenerStatus(), mRequest.get()));        return;    }    nsresult status = NS_OK;    nsresult rv = mRequest->GetStatus(&status);    NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");    // We should only forward this event to the listener if the request is    // still in a "good" state.  Because these events are being processed    // asynchronously, there is a very real chance that the listener might    // have cancelled the request after _this_ event was triggered.    if (NS_FAILED(status)) {        LOG(("nsOnDataAvailableEvent: Not calling OnDataAvailable [req=%x]",            mRequest.get()));        return;    }    // Find out from the listener proxy how many bytes to report.    PRUint32 count = mProxy->GetPendingCount();#if defined(PR_LOGGING)    {        PRUint32 avail;        mSource->Available(&avail);        LOG(("nsOnDataAvailableEvent: Calling the consumer's OnDataAvailable "            "[offset=%u count=%u avail=%u req=%x]\n",            mOffset, count, avail, mRequest.get()));    }#endif    nsCOMPtr<nsIStreamListener> listener;    rv = mProxy->GetListener(getter_AddRefs(listener));    // Forward call to listener    if (listener)        rv = listener->OnDataAvailable(mRequest, mContext,                                       mSource, mOffset, count);    LOG(("nsOnDataAvailableEvent: Done with the consumer's OnDataAvailable "         "[rv=%x, req=%x]\n", rv, mRequest.get()));    // XXX Need to suspend the underlying request... must consider    //     other pending events (such as OnStopRequest). These    //     should not be forwarded to the listener if the request    //     is suspended. Also, handling the Resume could be tricky.    if (rv == NS_BASE_STREAM_WOULD_BLOCK) {        NS_NOTREACHED("listener returned NS_BASE_STREAM_WOULD_BLOCK"                      " -- support for this is not implemented");        rv = NS_BINDING_FAILED;    }    // Cancel the request on unexpected errors    if (NS_FAILED(rv) && (rv != NS_BASE_STREAM_CLOSED)) {        LOG(("OnDataAvailable failed [rv=%x] canceling request!\n"));        mRequest->Cancel(rv);    }    mProxy->SetListenerStatus(rv);}