p2p_stream_socket.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_PROTOCOL_P2P_STREAM_SOCKET_H_
  5. #define REMOTING_PROTOCOL_P2P_STREAM_SOCKET_H_
  6. #include "net/base/completion_once_callback.h"
  7. #include "net/traffic_annotation/network_traffic_annotation.h"
  8. namespace net {
  9. class IOBuffer;
  10. } // namespace net
  11. namespace remoting {
  12. namespace protocol {
  13. // Peer-to-peer socket with stream semantics.
  14. class P2PStreamSocket {
  15. public:
  16. virtual ~P2PStreamSocket() {}
  17. // Reads data, up to |buf_len| bytes, from the socket. The number of bytes
  18. // read is returned, or an error is returned upon failure. ERR_IO_PENDING
  19. // is returned if the operation could not be completed synchronously, in which
  20. // case the result will be passed to the callback when available. If the
  21. // operation is not completed immediately, the socket acquires a reference to
  22. // the provided buffer until the callback is invoked or the socket is
  23. // closed. If the socket is destroyed before the read completes, the
  24. // callback will not be invoked.
  25. virtual int Read(const scoped_refptr<net::IOBuffer>& buf,
  26. int buf_len,
  27. net::CompletionOnceCallback callback) = 0;
  28. // Writes data, up to |buf_len| bytes, to the socket. Note: data may be
  29. // written partially. The number of bytes written is returned, or an error
  30. // is returned upon failure. ERR_IO_PENDING is returned if the operation could
  31. // not be completed synchronously, in which case the result will be passed to
  32. // the callback when available. If the operation is not completed
  33. // immediately, the socket acquires a reference to the provided buffer until
  34. // the callback is invoked or the socket is closed. Implementations of this
  35. // method should not modify the contents of the actual buffer that is written
  36. // to the socket.
  37. virtual int Write(
  38. const scoped_refptr<net::IOBuffer>& buf,
  39. int buf_len,
  40. net::CompletionOnceCallback callback,
  41. const net::NetworkTrafficAnnotationTag& traffic_annotation) = 0;
  42. };
  43. } // namespace protocol
  44. } // namespace remoting
  45. #endif // REMOTING_PROTOCOL_P2P_STREAM_SOCKET_H_