nsSimpleStreamListener.cpp (2364B)
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/. */ 5 6 #include "nsSimpleStreamListener.h" 7 8 namespace mozilla { 9 namespace net { 10 11 // 12 //---------------------------------------------------------------------------- 13 // nsISupports implementation... 14 //---------------------------------------------------------------------------- 15 // 16 NS_IMPL_ISUPPORTS(nsSimpleStreamListener, nsISimpleStreamListener, 17 nsIStreamListener, nsIRequestObserver) 18 19 // 20 //---------------------------------------------------------------------------- 21 // nsIRequestObserver implementation... 22 //---------------------------------------------------------------------------- 23 // 24 NS_IMETHODIMP 25 nsSimpleStreamListener::OnStartRequest(nsIRequest* aRequest) { 26 return mObserver ? mObserver->OnStartRequest(aRequest) : NS_OK; 27 } 28 29 NS_IMETHODIMP 30 nsSimpleStreamListener::OnStopRequest(nsIRequest* request, nsresult aStatus) { 31 return mObserver ? mObserver->OnStopRequest(request, aStatus) : NS_OK; 32 } 33 34 // 35 //---------------------------------------------------------------------------- 36 // nsIStreamListener implementation... 37 //---------------------------------------------------------------------------- 38 // 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); 45 // 46 // Equate zero bytes read and NS_SUCCEEDED to stopping the read. 47 // 48 if (NS_SUCCEEDED(rv) && (writeCount == 0)) return NS_BASE_STREAM_CLOSED; 49 return rv; 50 } 51 52 // 53 //---------------------------------------------------------------------------- 54 // nsISimpleStreamListener implementation... 55 //---------------------------------------------------------------------------- 56 // 57 NS_IMETHODIMP 58 nsSimpleStreamListener::Init(nsIOutputStream* aSink, 59 nsIRequestObserver* aObserver) { 60 MOZ_ASSERT(aSink, "null output stream"); 61 62 mSink = aSink; 63 mObserver = aObserver; 64 65 return NS_OK; 66 } 67 68 } // namespace net 69 } // namespace mozilla