transport.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package thrift
  20. import (
  21. "context"
  22. "errors"
  23. "io"
  24. )
  25. var errTransportInterrupted = errors.New("Transport Interrupted")
  26. type Flusher interface {
  27. Flush() (err error)
  28. }
  29. type ContextFlusher interface {
  30. Flush(ctx context.Context) (err error)
  31. }
  32. type ReadSizeProvider interface {
  33. RemainingBytes() (num_bytes uint64)
  34. }
  35. // Encapsulates the I/O layer
  36. type TTransport interface {
  37. io.ReadWriteCloser
  38. ContextFlusher
  39. ReadSizeProvider
  40. // Opens the transport for communication
  41. Open() error
  42. // Returns true if the transport is open
  43. IsOpen() bool
  44. }
  45. type stringWriter interface {
  46. WriteString(s string) (n int, err error)
  47. }
  48. // This is "enchanced" transport with extra capabilities. You need to use one of these
  49. // to construct protocol.
  50. // Notably, TSocket does not implement this interface, and it is always a mistake to use
  51. // TSocket directly in protocol.
  52. type TRichTransport interface {
  53. io.ReadWriter
  54. io.ByteReader
  55. io.ByteWriter
  56. stringWriter
  57. ContextFlusher
  58. ReadSizeProvider
  59. }