netwerk/base/src/nsTemporaryFileInputStream.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/nsTemporaryFileInputStream.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsTemporaryFileInputStream_h__
    1.10 +#define nsTemporaryFileInputStream_h__
    1.11 +
    1.12 +#include "mozilla/Mutex.h"
    1.13 +#include "nsIInputStream.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +#include "prio.h"
    1.16 +
    1.17 +class nsTemporaryFileInputStream : public nsIInputStream
    1.18 +{
    1.19 +public:
    1.20 +  //used to release a PRFileDesc
    1.21 +  class FileDescOwner
    1.22 +  {
    1.23 +    friend class nsTemporaryFileInputStream;
    1.24 +  public:
    1.25 +    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileDescOwner)
    1.26 +    FileDescOwner(PRFileDesc* aFD)
    1.27 +      : mFD(aFD),
    1.28 +        mMutex("FileDescOwner::mMutex")
    1.29 +    {
    1.30 +      MOZ_ASSERT(aFD);
    1.31 +    }
    1.32 +    ~FileDescOwner()
    1.33 +    {
    1.34 +      PR_Close(mFD);
    1.35 +    }
    1.36 +    mozilla::Mutex& FileMutex() { return mMutex; }
    1.37 +
    1.38 +  private:
    1.39 +    PRFileDesc* mFD;
    1.40 +    mozilla::Mutex mMutex;
    1.41 +  };
    1.42 +
    1.43 +  nsTemporaryFileInputStream(FileDescOwner* aFileDescOwner, uint64_t aStartPos, uint64_t aEndPos);
    1.44 +
    1.45 +  virtual ~nsTemporaryFileInputStream() { }
    1.46 +
    1.47 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.48 +  NS_DECL_NSIINPUTSTREAM
    1.49 +
    1.50 +private:
    1.51 +  nsRefPtr<FileDescOwner> mFileDescOwner;
    1.52 +  uint64_t mStartPos;
    1.53 +  uint64_t mEndPos;
    1.54 +  bool mClosed;
    1.55 +};
    1.56 +
    1.57 +#endif // nsTemporaryFileInputStream_h__

mercurial