nsIInputStream.idl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Warren Harris <[email protected]>
  24. * Darin Fisher <[email protected]>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #include "nsISupports.idl"
  40. interface nsIInputStream;
  41. %{C++
  42. /**
  43. * The signature of the writer function passed to ReadSegments. This
  44. * is the "consumer" of data that gets read from the stream's buffer.
  45. *
  46. * @param aInStream stream being read
  47. * @param aClosure opaque parameter passed to ReadSegments
  48. * @param aFromSegment pointer to memory owned by the input stream
  49. * @param aToOffset amount already read (since ReadSegments was called)
  50. * @param aCount length of fromSegment
  51. * @param aWriteCount number of bytes read
  52. *
  53. * Implementers should return the following:
  54. *
  55. * @return NS_OK and (*aWriteCount > 0) if consumed some data
  56. * @return <any-error> if not interested in consuming any data
  57. *
  58. * Errors are never passed to the caller of ReadSegments.
  59. *
  60. * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
  61. *
  62. * @status FROZEN
  63. */
  64. typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream,
  65. void *aClosure,
  66. const char *aFromSegment,
  67. PRUint32 aToOffset,
  68. PRUint32 aCount,
  69. PRUint32 *aWriteCount);
  70. %}
  71. native nsWriteSegmentFun(nsWriteSegmentFun);
  72. /**
  73. * nsIInputStream
  74. *
  75. * @status FROZEN
  76. */
  77. [scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)]
  78. interface nsIInputStream : nsISupports
  79. {
  80. /**
  81. * Close the stream.
  82. */
  83. void close();
  84. /**
  85. * @return number of bytes currently available in the stream
  86. */
  87. unsigned long available();
  88. /**
  89. * Read data from the stream.
  90. *
  91. * @param aBuf the buffer into which the data is to be read
  92. * @param aCount the maximum number of bytes to be read
  93. *
  94. * @return number of bytes read (may be less than aCount).
  95. * @return 0 if reached end of file
  96. *
  97. * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
  98. * block the calling thread (non-blocking mode only)
  99. * @throws <other-error> on failure
  100. */
  101. [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount);
  102. /**
  103. * Low-level read method that has access to the stream's underlying buffer.
  104. * The writer function may be called multiple times for segmented buffers.
  105. * ReadSegments is expected to keep calling the writer until either there is
  106. * nothing left to read or the writer returns an error. ReadSegments should
  107. * not call the writer with zero bytes to consume.
  108. *
  109. * @param aWriter the "consumer" of the data to be read
  110. * @param aClosure opaque parameter passed to writer
  111. * @param aCount the maximum number of bytes to be read
  112. *
  113. * @return number of bytes read (may be less than aCount)
  114. * @return 0 if reached end of file (or if aWriter refused to consume data)
  115. *
  116. * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
  117. * block the calling thread (non-blocking mode only)
  118. * @throws <other-error> on failure
  119. *
  120. * NOTE: this function may be unimplemented if a stream has no underlying
  121. * buffer (e.g., socket input stream).
  122. */
  123. [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter,
  124. in voidPtr aClosure,
  125. in unsigned long aCount);
  126. /**
  127. * @return true if stream is non-blocking
  128. */
  129. boolean isNonBlocking();
  130. };