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