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

Side by Side Diff: ppapi/cpp/dev/tcp_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
« no previous file with comments | « ppapi/cpp/dev/net_address_dev.h ('k') | ppapi/cpp/dev/udp_socket_dev.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_TCP_SOCKET_DEV_H_ 5 #ifndef PPAPI_CPP_DEV_TCP_SOCKET_DEV_H_
6 #define PPAPI_CPP_DEV_TCP_SOCKET_DEV_H_ 6 #define PPAPI_CPP_DEV_TCP_SOCKET_DEV_H_
7 7
8 #include "ppapi/c/dev/ppb_tcp_socket_dev.h" 8 #include "ppapi/c/dev/ppb_tcp_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 17
18 /// The <code>TCPSocket_Dev</code> class provides TCP socket operations.
19 ///
20 /// Permissions: Apps permission <code>socket</code> with subrule
21 /// <code>tcp-connect</code> is required for <code>Connect()</code>.
22 /// For more details about network communication permissions, please see:
23 /// http://developer.chrome.com/apps/app_network.html
18 class TCPSocket_Dev: public Resource { 24 class TCPSocket_Dev: public Resource {
19 public: 25 public:
26 /// Default constructor for creating an is_null() <code>TCPSocket_Dev</code>
27 /// object.
20 TCPSocket_Dev(); 28 TCPSocket_Dev();
21 29
30 /// A constructor used to create a <code>TCPSocket_Dev</code> object.
31 ///
32 /// @param[in] instance The instance with which this resource will be
33 /// associated.
22 explicit TCPSocket_Dev(const InstanceHandle& instance); 34 explicit TCPSocket_Dev(const InstanceHandle& instance);
23 35
36 /// A constructor used when you have received a <code>PP_Resource</code> as a
37 /// return value that has had 1 ref added for you.
38 ///
39 /// @param[in] resource A <code>PPB_TCPSocket_Dev</code> resource.
24 TCPSocket_Dev(PassRef, PP_Resource resource); 40 TCPSocket_Dev(PassRef, PP_Resource resource);
25 41
42 /// The copy constructor for <code>TCPSocket_Dev</code>.
43 ///
44 /// @param[in] other A reference to another <code>TCPSocket_Dev</code>.
26 TCPSocket_Dev(const TCPSocket_Dev& other); 45 TCPSocket_Dev(const TCPSocket_Dev& other);
27 46
47 /// The destructor.
28 virtual ~TCPSocket_Dev(); 48 virtual ~TCPSocket_Dev();
29 49
50 /// The assignment operator for <code>TCPSocket_Dev</code>.
51 ///
52 /// @param[in] other A reference to another <code>TCPSocket_Dev</code>.
53 ///
54 /// @return A reference to this <code>TCPSocket_Dev</code> object.
30 TCPSocket_Dev& operator=(const TCPSocket_Dev& other); 55 TCPSocket_Dev& operator=(const TCPSocket_Dev& other);
31 56
32 // Returns true if the required interface is available. 57 /// Static function for determining whether the browser supports the
58 /// <code>PPB_TCPSocket_Dev</code> interface.
59 ///
60 /// @return true if the interface is available, false otherwise.
33 static bool IsAvailable(); 61 static bool IsAvailable();
34 62
63 /// Connects the socket to the given address.
64 ///
65 /// @param[in] addr A <code>NetAddress_Dev</code> object.
66 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
67 /// completion.
68 ///
69 /// @return An int32_t containing an error code from <code>pp_errors.h</code>,
70 /// including (but not limited to):
71 /// - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
72 /// permissions.
73 /// - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is
74 /// unreachable.
75 /// - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was
76 /// refused.
77 /// - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed.
78 /// - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed
79 /// out.
35 int32_t Connect(const NetAddress_Dev& addr, 80 int32_t Connect(const NetAddress_Dev& addr,
36 const CompletionCallback& callback); 81 const CompletionCallback& callback);
82
83 /// Gets the local address of the socket, if it is connected.
84 ///
85 /// @return A <code>NetAddress_Dev</code> object. The object will be null
86 /// (i.e., is_null() returns true) on failure.
37 NetAddress_Dev GetLocalAddress() const; 87 NetAddress_Dev GetLocalAddress() const;
88
89 /// Gets the remote address of the socket, if it is connected.
90 ///
91 /// @return A <code>NetAddress_Dev</code> object. The object will be null
92 /// (i.e., is_null() returns true) on failure.
38 NetAddress_Dev GetRemoteAddress() const; 93 NetAddress_Dev GetRemoteAddress() const;
94
95 /// Reads data from the socket. The socket must be connected. It may perform a
96 /// partial read.
97 ///
98 /// <strong>Caveat:</strong> You should be careful about the lifetime of
99 /// <code>buffer</code>. Typically you will use a
100 /// <code>CompletionCallbackFactory</code> to scope callbacks to the lifetime
101 /// of your class. When your class goes out of scope, the callback factory
102 /// will not actually cancel the operation, but will rather just skip issuing
103 /// the callback on your class. This means that if the underlying
104 /// <code>PPB_TCPSocket_Dev</code> resource outlives your class, the browser
105 /// will still try to write into your buffer when the operation completes.
106 /// The buffer must be kept valid until then to avoid memory corruption.
107 /// If you want to release the buffer while the <code>Read()</code> call is
108 /// still pending, you should call <code>Close()</code> to ensure that the
109 /// buffer won't be accessed in the future.
110 ///
111 /// @param[out] buffer The buffer to store the received data on success. It
112 /// must be at least as large as <code>bytes_to_read</code>.
113 /// @param[in] bytes_to_read The number of bytes to read.
114 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
115 /// completion.
116 ///
117 /// @return A non-negative number on success to indicate how many bytes have
118 /// been read, 0 means that end-of-file was reached; otherwise, an error code
119 /// from <code>pp_errors.h</code>.
39 int32_t Read(char* buffer, 120 int32_t Read(char* buffer,
40 int32_t bytes_to_read, 121 int32_t bytes_to_read,
41 const CompletionCallback& callback); 122 const CompletionCallback& callback);
123
124 /// Writes data to the socket. The socket must be connected. It may perform a
125 /// partial write.
126 ///
127 /// @param[in] buffer The buffer containing the data to write.
128 /// @param[in] bytes_to_write The number of bytes to write.
129 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
130 /// completion.
131 ///
132 /// @return A non-negative number on success to indicate how many bytes have
133 /// been written; otherwise, an error code from <code>pp_errors.h</code>.
42 int32_t Write(const char* buffer, 134 int32_t Write(const char* buffer,
43 int32_t bytes_to_write, 135 int32_t bytes_to_write,
44 const CompletionCallback& callback); 136 const CompletionCallback& callback);
137
138 /// Cancels all pending reads and writes and disconnects the socket. Any
139 /// pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code>
140 /// if pending IO was interrupted. After a call to this method, no output
141 /// buffer pointers passed into previous <code>Read()</code> calls will be
142 /// accessed. It is not valid to call <code>Connect()</code> again.
143 ///
144 /// The socket is implicitly closed if it is destroyed, so you are not
145 /// required to call this method.
45 void Close(); 146 void Close();
147
148 /// Sets a socket option on the TCP socket.
149 /// Please see the <code>PP_TCPSocket_Option_Dev</code> description for option
150 /// names, value types and allowed values.
151 ///
152 /// @param[in] name The option to set.
153 /// @param[in] value The option value to set.
154 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
155 /// completion.
156 ///
157 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
158 ////
46 int32_t SetOption(PP_TCPSocket_Option_Dev name, 159 int32_t SetOption(PP_TCPSocket_Option_Dev name,
47 const Var& value, 160 const Var& value,
48 const CompletionCallback& callback); 161 const CompletionCallback& callback);
49 }; 162 };
50 163
51 } // namespace pp 164 } // namespace pp
52 165
53 #endif // PPAPI_CPP_DEV_TCP_SOCKET_DEV_H_ 166 #endif // PPAPI_CPP_DEV_TCP_SOCKET_DEV_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/net_address_dev.h ('k') | ppapi/cpp/dev/udp_socket_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698