当前位置: 首页>>代码示例>>C++>>正文


C++ nsCOMPtr::Flush方法代码示例

本文整理汇总了C++中nsCOMPtr::Flush方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCOMPtr::Flush方法的具体用法?C++ nsCOMPtr::Flush怎么用?C++ nsCOMPtr::Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nsCOMPtr的用法示例。


在下文中一共展示了nsCOMPtr::Flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

NS_IMETHODIMP
nsMsgSaveAsListener::OnStopRequest(nsIRequest *request, nsISupports * aCtxt, nsresult aStatus)
{
  if (m_outputStream)
  {
    m_outputStream->Flush();
    m_outputStream->Close();
  }
  return NS_OK;
} 
开发者ID:stonewell,项目名称:exchange-ews-thunderbird,代码行数:10,代码来源:MsgMailNewsUrlBase.cpp

示例2: ReadCRLF


//.........这里部分代码省略.........
    // Look for a byte range request header. If there is one, set the
    // media resource offset to start from to that requested. Here we
    // only check for the range request format used by Android rather
    // than implementing all possibilities in the HTTP specification.
    // That is, the range request is of the form:
    //   Range: bytes=nnnn-
    // Were 'nnnn' is an integer number.
    // The end of the range is not checked, instead we return up to
    // the end of the resource and the client is informed of this via
    // the content-range header.
    NS_NAMED_LITERAL_CSTRING(byteRange, "Range: bytes=");
    const char* s = strstr(line.get(), byteRange.get());
    if (s) {
      start = strtoll(s+byteRange.Length(), nullptr, 10);

      // Clamp 'start' to be between 0 and the resource length.
      start = std::max(int64_t(0), std::min(resource->GetLength(), start));
    }
  }

  // HTTP response to use if this is a non byte range request
  const char* response_normal = "HTTP/1.1 200 OK\r\n";

  // HTTP response to use if this is a byte range request
  const char* response_range = "HTTP/1.1 206 Partial Content\r\n";

  // End of HTTP reponse headers is indicated by an empty line.
  const char* response_end = "\r\n";

  // If the request was a byte range request, we need to read from the
  // requested offset. If the resource is non-seekable, or the seek
  // fails, then the start offset is set back to zero. This results in all
  // HTTP response data being as if the byte range request was not made.
  if (start > 0 && !resource->IsTransportSeekable()) {
    start = 0;
  }

  const char* response_line = start > 0 ?
                                response_range :
                                response_normal;
  rv = WriteAll(response_line, strlen(response_line));
  if (NS_FAILED(rv)) { Shutdown(); return NS_OK; }

  // Buffer used for reading from the input stream and writing to
  // the output stream. The buffer size should be big enough for the
  // HTTP response headers sent below. A static_assert ensures
  // this where the buffer is used.
  const int buffer_size = 32768;
  nsAutoArrayPtr<char> b(new char[buffer_size]);

  // If we know the length of the resource, send a Content-Length header.
  int64_t contentlength = resource->GetLength() - start;
  if (contentlength > 0) {
    static_assert (buffer_size > 1024,
                   "buffer_size must be large enough "
                   "to hold response headers");
    snprintf(b, buffer_size, "Content-Length: %" PRId64 "\r\n", contentlength);
    rv = WriteAll(b, strlen(b));
    if (NS_FAILED(rv)) { Shutdown(); return NS_OK; }
  }

  // If the request was a byte range request, respond with a Content-Range
  // header which details the extent of the data returned.
  if (start > 0) {
    static_assert (buffer_size > 1024,
                   "buffer_size must be large enough "
                   "to hold response headers");
    snprintf(b, buffer_size, "Content-Range: "
             "bytes %" PRId64 "-%" PRId64 "/%" PRId64 "\r\n",
             start, resource->GetLength() - 1, resource->GetLength());
    rv = WriteAll(b, strlen(b));
    if (NS_FAILED(rv)) { Shutdown(); return NS_OK; }
  }

  rv = WriteAll(response_end, strlen(response_end));
  if (NS_FAILED(rv)) { Shutdown(); return NS_OK; }

  rv = mOutput->Flush();
  if (NS_FAILED(rv)) { Shutdown(); return NS_OK; }

  // Read data from media resource
  uint32_t bytesRead = 0; // Number of bytes read/written to streams
  rv = resource->ReadAt(start, b, buffer_size, &bytesRead);
  while (NS_SUCCEEDED(rv) && bytesRead != 0) {
    // Keep track of what we think the starting position for the next read
    // is. This is used in subsequent ReadAt calls to ensure we are reading
    // from the correct offset in the case where another thread is reading
    // from th same MediaResource.
    start += bytesRead;

    // Write data obtained from media resource to output stream
    rv = WriteAll(b, bytesRead);
    if (NS_FAILED (rv)) break;

    rv = resource->ReadAt(start, b, 32768, &bytesRead);
  }

  Shutdown();
  return NS_OK;
}
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:101,代码来源:AndroidMediaResourceServer.cpp


注:本文中的nsCOMPtr::Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。