Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: ppapi/cpp/dev/udp_socket_dev.h

Issue 16938011: Update comments of the Pepper networking APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ 5 #ifndef PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_
6 #define PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ 6 #define PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_
7 7
8 #include "ppapi/c/dev/ppb_udp_socket_dev.h" 8 #include "ppapi/c/dev/ppb_udp_socket_dev.h"
9 #include "ppapi/cpp/dev/net_address_dev.h" 9 #include "ppapi/cpp/dev/net_address_dev.h"
10 #include "ppapi/cpp/pass_ref.h" 10 #include "ppapi/cpp/pass_ref.h"
11 #include "ppapi/cpp/resource.h" 11 #include "ppapi/cpp/resource.h"
12 12
13 namespace pp { 13 namespace pp {
14 14
15 class CompletionCallback; 15 class CompletionCallback;
16 class InstanceHandle; 16 class InstanceHandle;
17 class Var; 17 class Var;
18 18
19 template <typename T> class CompletionCallbackWithOutput; 19 template <typename T> class CompletionCallbackWithOutput;
20 20
21 /// The <code>UDPSocket_Dev</code> class provides UDP socket operations.
22 ///
23 /// Permissions: Apps permission <code>socket</code> with subrule
24 /// <code>udp-bind</code> is required for <code>Bind()</code>; subrule
25 /// <code>udp-send-to</code> is required for <code>SendTo()</code>.
26 /// For more details about network communication permissions, please see:
27 /// http://developer.chrome.com/apps/app_network.html
21 class UDPSocket_Dev: public Resource { 28 class UDPSocket_Dev: public Resource {
22 public: 29 public:
30 /// Default constructor for creating an is_null() <code>UDPSocket_Dev</code>
31 /// object.
23 UDPSocket_Dev(); 32 UDPSocket_Dev();
24 33
34 /// A constructor used to create a <code>UDPSocket_Dev</code> object.
35 ///
36 /// @param[in] instance The instance with which this resource will be
37 /// associated.
25 explicit UDPSocket_Dev(const InstanceHandle& instance); 38 explicit UDPSocket_Dev(const InstanceHandle& instance);
26 39
40 /// A constructor used when you have received a <code>PP_Resource</code> as a
41 /// return value that has had 1 ref added for you.
42 ///
43 /// @param[in] resource A <code>PPB_UDPSocket_Dev</code> resource.
27 UDPSocket_Dev(PassRef, PP_Resource resource); 44 UDPSocket_Dev(PassRef, PP_Resource resource);
28 45
46 /// The copy constructor for <code>UDPSocket_Dev</code>.
47 ///
48 /// @param[in] other A reference to another <code>UDPSocket_Dev</code>.
29 UDPSocket_Dev(const UDPSocket_Dev& other); 49 UDPSocket_Dev(const UDPSocket_Dev& other);
30 50
51 /// The destructor.
31 virtual ~UDPSocket_Dev(); 52 virtual ~UDPSocket_Dev();
32 53
54 /// The assignment operator for <code>UDPSocket_Dev</code>.
55 ///
56 /// @param[in] other A reference to another <code>UDPSocket_Dev</code>.
57 ///
58 /// @return A reference to this <code>UDPSocket_Dev</code> object.
33 UDPSocket_Dev& operator=(const UDPSocket_Dev& other); 59 UDPSocket_Dev& operator=(const UDPSocket_Dev& other);
34 60
35 // Returns true if the required interface is available. 61 /// Static function for determining whether the browser supports the
62 /// <code>PPB_UDPSocket_Dev</code> interface.
63 ///
64 /// @return true if the interface is available, false otherwise.
36 static bool IsAvailable(); 65 static bool IsAvailable();
37 66
67 /// Binds the socket to the given address.
68 ///
69 /// @param[in] addr A <code>NetAddress_Dev</code> object.
70 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
71 /// completion.
72 ///
73 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
74 /// <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
75 /// required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be
76 /// returned if the address is already in use.
38 int32_t Bind(const NetAddress_Dev& addr, 77 int32_t Bind(const NetAddress_Dev& addr,
39 const CompletionCallback& callback); 78 const CompletionCallback& callback);
79
80 /// Get the address that the socket is bound to. The socket must be bound.
81 ///
82 /// @return A <code>NetAddress_Dev</code> object. The object will be null
83 /// (i.e., is_null() returns true) on failure.
40 NetAddress_Dev GetBoundAddress(); 84 NetAddress_Dev GetBoundAddress();
85
86 /// Receives data from the socket and stores the source address. The socket
87 /// must be bound.
88 ///
89 /// <strong>Caveat:</strong> You should be careful about the lifetime of
90 /// <code>buffer</code>. Typically you will use a
91 /// <code>CompletionCallbackFactory</code> to scope callbacks to the lifetime
92 /// of your class. When your class goes out of scope, the callback factory
93 /// will not actually cancel the operation, but will rather just skip issuing
94 /// the callback on your class. This means that if the underlying
95 /// <code>PPB_UDPSocket_Dev</code> resource outlives your class, the browser
96 /// will still try to write into your buffer when the operation completes.
97 /// The buffer must be kept valid until then to avoid memory corruption.
98 /// If you want to release the buffer while the <code>RecvFrom()</code> call
99 /// is still pending, you should call <code>Close()</code> to ensure that the
100 /// buffer won't be accessed in the future.
101 ///
102 /// @param[out] buffer The buffer to store the received data on success. It
103 /// must be at least as large as <code>num_bytes</code>.
104 /// @param[in] num_bytes The number of bytes to receive.
105 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
106 /// called upon completion.
107 ///
108 /// @return A non-negative number on success to indicate how many bytes have
109 /// been received; otherwise, an error code from <code>pp_errors.h</code>.
41 int32_t RecvFrom( 110 int32_t RecvFrom(
42 char* buffer, 111 char* buffer,
43 int32_t num_bytes, 112 int32_t num_bytes,
44 const CompletionCallbackWithOutput<NetAddress_Dev>& callback); 113 const CompletionCallbackWithOutput<NetAddress_Dev>& callback);
114
115 /// Sends data to a specific destination. The socket must be bound.
116 ///
117 /// @param[in] buffer The buffer containing the data to send.
118 /// @param[in] num_bytes The number of bytes to send.
119 /// @param[in] addr A <code>NetAddress_Dev</code> object holding the
120 /// destination address.
121 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
122 /// completion.
123 ///
124 /// @return A non-negative number on success to indicate how many bytes have
125 /// been sent; otherwise, an error code from <code>pp_errors.h</code>.
126 /// <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
127 /// required permissions.
45 int32_t SendTo(const char* buffer, 128 int32_t SendTo(const char* buffer,
46 int32_t num_bytes, 129 int32_t num_bytes,
47 const NetAddress_Dev& addr, 130 const NetAddress_Dev& addr,
48 const CompletionCallback& callback); 131 const CompletionCallback& callback);
132
133 /// Cancels all pending reads and writes, and closes the socket. Any pending
134 /// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
135 /// pending IO was interrupted. After a call to this method, no output
136 /// paramters passed into previous <code>RecvFrom()</code> calls will be
137 /// accessed. It is not valid to call <code>Bind()</code> again.
138 ///
139 /// The socket is implicitly closed if it is destroyed, so you are not
140 /// required to call this method.
49 void Close(); 141 void Close();
142
143 /// Sets a socket option on the UDP socket.
144 /// Please see the <code>PP_UDPSocket_Option_Dev</code> description for option
145 /// names, value types and allowed values.
146 ///
147 /// @param[in] name The option to set.
148 /// @param[in] value The option value to set.
149 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
150 /// completion.
151 ///
152 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
50 int32_t SetOption(PP_UDPSocket_Option_Dev name, 153 int32_t SetOption(PP_UDPSocket_Option_Dev name,
51 const Var& value, 154 const Var& value,
52 const CompletionCallback& callback); 155 const CompletionCallback& callback);
53 }; 156 };
54 157
55 } // namespace pp 158 } // namespace pp
56 159
57 #endif // PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ 160 #endif // PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/tcp_socket_dev.h ('k') | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698