diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-02-22 17:32:39 -0500 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-04-14 12:50:57 +0200 |
commit | 36fc5f674ef1a02d1498484c563a7108f4de44ed (patch) | |
tree | 120483cd8fc0decd189d5118941a9b23d6156ad5 /dom/heapsnapshot/FileDescriptorOutputStream.cpp | |
parent | 7b30664f59e65cadb7d5eb2e42591e90a32871f8 (diff) | |
download | UXP-36fc5f674ef1a02d1498484c563a7108f4de44ed.tar UXP-36fc5f674ef1a02d1498484c563a7108f4de44ed.tar.gz UXP-36fc5f674ef1a02d1498484c563a7108f4de44ed.tar.lz UXP-36fc5f674ef1a02d1498484c563a7108f4de44ed.tar.xz UXP-36fc5f674ef1a02d1498484c563a7108f4de44ed.zip |
Reclassify heapsnapshot and nsJSInspector as not part of devtools
This resolves Issue #316
Diffstat (limited to 'dom/heapsnapshot/FileDescriptorOutputStream.cpp')
-rw-r--r-- | dom/heapsnapshot/FileDescriptorOutputStream.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/dom/heapsnapshot/FileDescriptorOutputStream.cpp b/dom/heapsnapshot/FileDescriptorOutputStream.cpp new file mode 100644 index 000000000..72a289558 --- /dev/null +++ b/dom/heapsnapshot/FileDescriptorOutputStream.cpp @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/devtools/FileDescriptorOutputStream.h" +#include "private/pprio.h" + +namespace mozilla { +namespace devtools { + +/* static */ already_AddRefed<FileDescriptorOutputStream> +FileDescriptorOutputStream::Create(const ipc::FileDescriptor& fileDescriptor) +{ + if (NS_WARN_IF(!fileDescriptor.IsValid())) + return nullptr; + + auto rawFD = fileDescriptor.ClonePlatformHandle(); + PRFileDesc* prfd = PR_ImportFile(PROsfd(rawFD.release())); + if (NS_WARN_IF(!prfd)) + return nullptr; + + RefPtr<FileDescriptorOutputStream> stream = new FileDescriptorOutputStream(prfd); + return stream.forget(); +} + +NS_IMPL_ISUPPORTS(FileDescriptorOutputStream, nsIOutputStream); + +NS_IMETHODIMP +FileDescriptorOutputStream::Close() +{ + // Repeatedly closing is idempotent. + if (!fd) + return NS_OK; + + if (PR_Close(fd) != PR_SUCCESS) + return NS_ERROR_FAILURE; + fd = nullptr; + return NS_OK; +} + +NS_IMETHODIMP +FileDescriptorOutputStream::Write(const char* buf, uint32_t count, uint32_t* retval) +{ + if (NS_WARN_IF(!fd)) + return NS_ERROR_FAILURE; + + auto written = PR_Write(fd, buf, count); + if (written < 0) + return NS_ERROR_FAILURE; + *retval = written; + return NS_OK; +} + +NS_IMETHODIMP +FileDescriptorOutputStream::Flush() +{ + if (NS_WARN_IF(!fd)) + return NS_ERROR_FAILURE; + + return PR_Sync(fd) == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +FileDescriptorOutputStream::WriteFrom(nsIInputStream* fromStream, uint32_t count, + uint32_t* retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileDescriptorOutputStream::WriteSegments(nsReadSegmentFun reader, void* closure, + uint32_t count, uint32_t* retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileDescriptorOutputStream::IsNonBlocking(bool* retval) +{ + *retval = false; + return NS_OK; +} + +} // namespace devtools +} // namespace mozilla |