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"
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
;
27 explicit CloseFileRunnable(const FileDescriptor
& aFileDescriptor
)
31 : mFileDescriptor(aFileDescriptor
)
35 NS_DECL_THREADSAFE_ISUPPORTS
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
55 FileDescriptor
FILEToFileDescriptor(FILE* aStream
);
58 } // namespace mozilla
60 #endif // mozilla_ipc_FileDescriptorUtils_h