nsITransport.idl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsISupports.idl"
  5. interface nsIInputStream;
  6. interface nsIOutputStream;
  7. interface nsITransportEventSink;
  8. interface nsIEventTarget;
  9. /**
  10. * nsITransport
  11. *
  12. * This interface provides a common way of accessing i/o streams connected
  13. * to some resource. This interface does not in any way specify the resource.
  14. * It provides methods to open blocking or non-blocking, buffered or unbuffered
  15. * streams to the resource. The name "transport" is meant to connote the
  16. * inherent data transfer implied by this interface (i.e., data is being
  17. * transfered in some fashion via the streams exposed by this interface).
  18. *
  19. * A transport can have an event sink associated with it. The event sink
  20. * receives transport-specific events as the transfer is occuring. For a
  21. * socket transport, these events can include status about the connection.
  22. * See nsISocketTransport for more info about socket transport specifics.
  23. */
  24. [scriptable, uuid(2a8c6334-a5e6-4ec3-9865-1256541446fb)]
  25. interface nsITransport : nsISupports
  26. {
  27. /**
  28. * Open flags.
  29. */
  30. const unsigned long OPEN_BLOCKING = 1<<0;
  31. const unsigned long OPEN_UNBUFFERED = 1<<1;
  32. /**
  33. * Open an input stream on this transport.
  34. *
  35. * Flags have the following meaning:
  36. *
  37. * OPEN_BLOCKING
  38. * If specified, then the resulting stream will have blocking stream
  39. * semantics. This means that if the stream has no data and is not
  40. * closed, then reading from it will block the calling thread until
  41. * at least one byte is available or until the stream is closed.
  42. * If this flag is NOT specified, then the stream has non-blocking
  43. * stream semantics. This means that if the stream has no data and is
  44. * not closed, then reading from it returns NS_BASE_STREAM_WOULD_BLOCK.
  45. * In addition, in non-blocking mode, the stream is guaranteed to
  46. * support nsIAsyncInputStream. This interface allows the consumer of
  47. * the stream to be notified when the stream can again be read.
  48. *
  49. * OPEN_UNBUFFERED
  50. * If specified, the resulting stream may not support ReadSegments.
  51. * ReadSegments is only gauranteed to be implemented when this flag is
  52. * NOT specified.
  53. *
  54. * @param aFlags
  55. * optional transport specific flags.
  56. * @param aSegmentSize
  57. * if OPEN_UNBUFFERED is not set, then this parameter specifies the
  58. * size of each buffer segment (pass 0 to use default value).
  59. * @param aSegmentCount
  60. * if OPEN_UNBUFFERED is not set, then this parameter specifies the
  61. * maximum number of buffer segments (pass 0 to use default value).
  62. */
  63. nsIInputStream openInputStream(in unsigned long aFlags,
  64. in unsigned long aSegmentSize,
  65. in unsigned long aSegmentCount);
  66. /**
  67. * Open an output stream on this transport.
  68. *
  69. * Flags have the following meaning:
  70. *
  71. * OPEN_BLOCKING
  72. * If specified, then the resulting stream will have blocking stream
  73. * semantics. This means that if the stream is full and is not closed,
  74. * then writing to it will block the calling thread until ALL of the
  75. * data can be written or until the stream is closed. If this flag is
  76. * NOT specified, then the stream has non-blocking stream semantics.
  77. * This means that if the stream is full and is not closed, then writing
  78. * to it returns NS_BASE_STREAM_WOULD_BLOCK. In addition, in non-
  79. * blocking mode, the stream is guaranteed to support
  80. * nsIAsyncOutputStream. This interface allows the consumer of the
  81. * stream to be notified when the stream can again accept more data.
  82. *
  83. * OPEN_UNBUFFERED
  84. * If specified, the resulting stream may not support WriteSegments and
  85. * WriteFrom. WriteSegments and WriteFrom are only guaranteed to be
  86. * implemented when this flag is NOT specified.
  87. *
  88. * @param aFlags
  89. * optional transport specific flags.
  90. * @param aSegmentSize
  91. * if OPEN_UNBUFFERED is not set, then this parameter specifies the
  92. * size of each buffer segment (pass 0 to use default value).
  93. * @param aSegmentCount
  94. * if OPEN_UNBUFFERED is not set, then this parameter specifies the
  95. * maximum number of buffer segments (pass 0 to use default value).
  96. */
  97. nsIOutputStream openOutputStream(in unsigned long aFlags,
  98. in unsigned long aSegmentSize,
  99. in unsigned long aSegmentCount);
  100. /**
  101. * Close the transport and any open streams.
  102. *
  103. * @param aReason
  104. * the reason for closing the stream.
  105. */
  106. void close(in nsresult aReason);
  107. /**
  108. * Set the transport event sink.
  109. *
  110. * @param aSink
  111. * receives transport layer notifications
  112. * @param aEventTarget
  113. * indicates the event target to which the notifications should
  114. * be delivered. if NULL, then the notifications may occur on
  115. * any thread.
  116. */
  117. void setEventSink(in nsITransportEventSink aSink,
  118. in nsIEventTarget aEventTarget);
  119. /**
  120. * Generic nsITransportEventSink status codes. nsITransport
  121. * implementations may override these status codes with their own more
  122. * specific status codes (e.g., see nsISocketTransport).
  123. *
  124. * In C++, these constants have a type of uint32_t, so C++ callers must use
  125. * the NS_NET_STATUS_* constants defined below, which have a type of
  126. * nsresult.
  127. */
  128. const unsigned long STATUS_READING = 0x804b0008;
  129. const unsigned long STATUS_WRITING = 0x804b0009;
  130. };
  131. [scriptable, uuid(EDA4F520-67F7-484b-A691-8C3226A5B0A6)]
  132. interface nsITransportEventSink : nsISupports
  133. {
  134. /**
  135. * Transport status notification.
  136. *
  137. * @param aTransport
  138. * the transport sending this status notification.
  139. * @param aStatus
  140. * the transport status (resolvable to a string using
  141. * nsIErrorService). See nsISocketTransport for socket specific
  142. * status codes and more comments.
  143. * @param aProgress
  144. * the amount of data either read or written depending on the value
  145. * of the status code. this value is relative to aProgressMax.
  146. * @param aProgressMax
  147. * the maximum amount of data that will be read or written. if
  148. * unknown, -1 will be passed.
  149. */
  150. void onTransportStatus(in nsITransport aTransport,
  151. in nsresult aStatus,
  152. in long long aProgress,
  153. in long long aProgressMax);
  154. };