Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / nsSimpleStreamListener.cpp
blobbeed8a9f401cf6f7bf80cb7956a4384a059c638c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSimpleStreamListener.h"
8 namespace mozilla {
9 namespace net {
12 //----------------------------------------------------------------------------
13 // nsISupports implementation...
14 //----------------------------------------------------------------------------
16 NS_IMPL_ISUPPORTS(nsSimpleStreamListener, nsISimpleStreamListener,
17 nsIStreamListener, nsIRequestObserver)
20 //----------------------------------------------------------------------------
21 // nsIRequestObserver implementation...
22 //----------------------------------------------------------------------------
24 NS_IMETHODIMP
25 nsSimpleStreamListener::OnStartRequest(nsIRequest* aRequest) {
26 return mObserver ? mObserver->OnStartRequest(aRequest) : NS_OK;
29 NS_IMETHODIMP
30 nsSimpleStreamListener::OnStopRequest(nsIRequest* request, nsresult aStatus) {
31 return mObserver ? mObserver->OnStopRequest(request, aStatus) : NS_OK;
35 //----------------------------------------------------------------------------
36 // nsIStreamListener implementation...
37 //----------------------------------------------------------------------------
39 NS_IMETHODIMP
40 nsSimpleStreamListener::OnDataAvailable(nsIRequest* request,
41 nsIInputStream* aSource,
42 uint64_t aOffset, uint32_t aCount) {
43 uint32_t writeCount;
44 nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount);
46 // Equate zero bytes read and NS_SUCCEEDED to stopping the read.
48 if (NS_SUCCEEDED(rv) && (writeCount == 0)) return NS_BASE_STREAM_CLOSED;
49 return rv;
53 //----------------------------------------------------------------------------
54 // nsISimpleStreamListener implementation...
55 //----------------------------------------------------------------------------
57 NS_IMETHODIMP
58 nsSimpleStreamListener::Init(nsIOutputStream* aSink,
59 nsIRequestObserver* aObserver) {
60 MOZ_ASSERT(aSink, "null output stream");
62 mSink = aSink;
63 mObserver = aObserver;
65 return NS_OK;
68 } // namespace net
69 } // namespace mozilla