p2p_datagram_socket.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_DATAGRAM_SOCKET_H_
  5. #define REMOTING_PROTOCOL_P2P_DATAGRAM_SOCKET_H_
  6. #include "net/base/completion_repeating_callback.h"
  7. namespace net {
  8. class IOBuffer;
  9. } // namespace net
  10. namespace remoting {
  11. namespace protocol {
  12. // Peer-to-peer socket with datagram semantics.
  13. class P2PDatagramSocket {
  14. public:
  15. virtual ~P2PDatagramSocket() {}
  16. // Receives a packet, up to |buf_len| bytes, from the socket. Size of the
  17. // incoming packet is returned in case of success. If the packet is larger
  18. // than |buf_len| then it is truncated, i.e. only the first |buf_len| bytes
  19. // are stored in the buffer. In case of failure a net error code is returned.
  20. // ERR_IO_PENDING is returned if the operation could not be completed
  21. // synchronously, in which case the result will be passed to the callback when
  22. // available. If the operation is not completed immediately, the socket
  23. // acquires a reference to the provided buffer until the callback is invoked
  24. // or the socket is closed. If the socket is destroyed before the read
  25. // completes, the callback will not be invoked.
  26. virtual int Recv(const scoped_refptr<net::IOBuffer>& buf,
  27. int buf_len,
  28. const net::CompletionRepeatingCallback& callback) = 0;
  29. // Sends a packet. Returns |buf_len| to indicate success, otherwise a net
  30. // error code is returned. 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 immediately,
  33. // the socket acquires a reference to the provided buffer until the callback
  34. // is invoked or the socket is closed. Implementations of this method should
  35. // not modify the contents of the actual buffer that is written to the socket.
  36. virtual int Send(const scoped_refptr<net::IOBuffer>& buf,
  37. int buf_len,
  38. const net::CompletionRepeatingCallback& callback) = 0;
  39. };
  40. } // namespace protocol
  41. } // namespace remoting
  42. #endif // REMOTING_PROTOCOL_P2P_DATAGRAM_SOCKET_H_