Bumping manifests a=b2g-bump
[gecko.git] / ipc / glue / FileDescriptorUtils.h
blobfb244f3367c06c67223733b129e340a1242945d3
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 #ifndef mozilla_ipc_FileDescriptorUtils_h
7 #define mozilla_ipc_FileDescriptorUtils_h
9 #include "mozilla/Attributes.h"
10 #include "mozilla/ipc/FileDescriptor.h"
11 #include "nsIRunnable.h"
12 #include <stdio.h>
14 namespace mozilla {
15 namespace ipc {
17 // When Dispatch() is called (from main thread) this class arranges to close the
18 // provided FileDescriptor on one of the socket transport service threads (to
19 // avoid main thread I/O).
20 class CloseFileRunnable MOZ_FINAL : public nsIRunnable
22 typedef mozilla::ipc::FileDescriptor FileDescriptor;
24 FileDescriptor mFileDescriptor;
26 public:
27 explicit CloseFileRunnable(const FileDescriptor& aFileDescriptor)
28 #ifdef DEBUG
30 #else
31 : mFileDescriptor(aFileDescriptor)
32 { }
33 #endif
35 NS_DECL_THREADSAFE_ISUPPORTS
36 NS_DECL_NSIRUNNABLE
38 void Dispatch();
40 private:
41 ~CloseFileRunnable();
43 void CloseFile();
46 // On failure, FileDescriptorToFILE closes the given descriptor; on
47 // success, fclose()ing the returned FILE* will close the handle.
48 // This is meant for use with FileDescriptors received over IPC.
49 FILE* FileDescriptorToFILE(const FileDescriptor& aDesc,
50 const char* aOpenMode);
52 // FILEToFileDescriptor does not consume the given FILE*; it must be
53 // fclose()d as normal, and this does not invalidate the returned
54 // FileDescriptor.
55 FileDescriptor FILEToFileDescriptor(FILE* aStream);
57 } // namespace ipc
58 } // namespace mozilla
60 #endif // mozilla_ipc_FileDescriptorUtils_h