Files
firefox/devtools/shared/heapsnapshot/FileDescriptorOutputStream.cpp
T
Ehsan Akhgari 6d06c0bc8f Bug 1508472 - Part 1: First batch of comment fix-ups in preparation for the tree reformat r=sylvestre
This is a best effort attempt at ensuring that the adverse impact of
reformatting the entire tree over the comments would be minimal.  I've used a
combination of strategies including disabling of formatting, some manual
formatting and some changes to formatting to work around some clang-format
limitations.

Differential Revision: https://phabricator.services.mozilla.com/D13046
2018-11-27 10:08:58 +00:00

87 lines
2.1 KiB
C++

/* -*- 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