OLD | NEW |
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/net_address.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; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 UDPSocket_Dev& operator=(const UDPSocket_Dev& other); | 59 UDPSocket_Dev& operator=(const UDPSocket_Dev& other); |
60 | 60 |
61 /// Static function for determining whether the browser supports the required | 61 /// Static function for determining whether the browser supports the required |
62 /// <code>PPB_UDPSocket_Dev</code> interface. | 62 /// <code>PPB_UDPSocket_Dev</code> interface. |
63 /// | 63 /// |
64 /// @return true if the interface is available, false otherwise. | 64 /// @return true if the interface is available, false otherwise. |
65 static bool IsAvailable(); | 65 static bool IsAvailable(); |
66 | 66 |
67 /// Binds to the given address. | 67 /// Binds to the given address. |
68 /// | 68 /// |
69 /// @param[in] addr A <code>NetAddress_Dev</code> object. | 69 /// @param[in] addr A <code>NetAddress</code> object. |
70 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 70 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
71 /// completion. | 71 /// completion. |
72 /// | 72 /// |
73 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 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 | 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 | 75 /// required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be |
76 /// returned if the address is already in use. | 76 /// returned if the address is already in use. |
77 int32_t Bind(const NetAddress_Dev& addr, | 77 int32_t Bind(const NetAddress& addr, |
78 const CompletionCallback& callback); | 78 const CompletionCallback& callback); |
79 | 79 |
80 /// Get the address that the socket has bound to. It can only be called after | 80 /// Get the address that the socket has bound to. It can only be called after |
81 /// a successful <code>Bind()</code> call. | 81 /// a successful <code>Bind()</code> call. |
82 /// | 82 /// |
83 /// @return A <code>NetAddress_Dev</code> object. The object will be null | 83 /// @return A <code>NetAddress</code> object. The object will be null |
84 /// (i.e., is_null() returns true) on failure. | 84 /// (i.e., is_null() returns true) on failure. |
85 NetAddress_Dev GetBoundAddress(); | 85 NetAddress GetBoundAddress(); |
86 | 86 |
87 /// Receives data from the socket and stores the source address. It can only | 87 /// Receives data from the socket and stores the source address. It can only |
88 /// be called after a successful <code>Bind()</code> call. | 88 /// be called after a successful <code>Bind()</code> call. |
89 /// | 89 /// |
90 /// <strong>Caveat:</strong> You should be careful about the lifetime of | 90 /// <strong>Caveat:</strong> You should be careful about the lifetime of |
91 /// <code>buffer</code>. Typically you will use a | 91 /// <code>buffer</code>. Typically you will use a |
92 /// <code>CompletionCallbackFactory</code> to scope callbacks to the lifetime | 92 /// <code>CompletionCallbackFactory</code> to scope callbacks to the lifetime |
93 /// of your class. When your class goes out of scope, the callback factory | 93 /// of your class. When your class goes out of scope, the callback factory |
94 /// will not actually cancel the operation, but will rather just skip issuing | 94 /// will not actually cancel the operation, but will rather just skip issuing |
95 /// the callback on your class. This means that if the underlying | 95 /// the callback on your class. This means that if the underlying |
96 /// <code>PPB_UDPSocket_Dev</code> resource outlives your class, the browser | 96 /// <code>PPB_UDPSocket_Dev</code> resource outlives your class, the browser |
97 /// will still try to write into your buffer when the operation completes. | 97 /// will still try to write into your buffer when the operation completes. |
98 /// The buffer must be kept valid until then to avoid memory corruption. | 98 /// The buffer must be kept valid until then to avoid memory corruption. |
99 /// If you want to release the buffer while the <code>RecvFrom()</code> call | 99 /// If you want to release the buffer while the <code>RecvFrom()</code> call |
100 /// is still pending, you should call <code>Close()</code> to ensure that the | 100 /// is still pending, you should call <code>Close()</code> to ensure that the |
101 /// buffer won't be accessed in the future. | 101 /// buffer won't be accessed in the future. |
102 /// | 102 /// |
103 /// @param[out] buffer The buffer to store the received data on success. It | 103 /// @param[out] buffer The buffer to store the received data on success. It |
104 /// must be at least <code>num_bytes</code> big. | 104 /// must be at least <code>num_bytes</code> big. |
105 /// @param[in] num_bytes The number of bytes to read. | 105 /// @param[in] num_bytes The number of bytes to read. |
106 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be | 106 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
107 /// called upon completion. | 107 /// called upon completion. |
108 /// | 108 /// |
109 /// @return A non-negative number on success to indicate how many bytes have | 109 /// @return A non-negative number on success to indicate how many bytes have |
110 /// been received; otherwise, an error code from <code>pp_errors.h</code>. | 110 /// been received; otherwise, an error code from <code>pp_errors.h</code>. |
111 int32_t RecvFrom( | 111 int32_t RecvFrom( |
112 char* buffer, | 112 char* buffer, |
113 int32_t num_bytes, | 113 int32_t num_bytes, |
114 const CompletionCallbackWithOutput<NetAddress_Dev>& callback); | 114 const CompletionCallbackWithOutput<NetAddress>& callback); |
115 | 115 |
116 /// Sends data to a specific destination. It can only be called after a | 116 /// Sends data to a specific destination. It can only be called after a |
117 /// successful <code>Bind()</code> call. | 117 /// successful <code>Bind()</code> call. |
118 /// | 118 /// |
119 /// @param[in] buffer The buffer containing the data to send. | 119 /// @param[in] buffer The buffer containing the data to send. |
120 /// @param[in] num_bytes The number of bytes to send. | 120 /// @param[in] num_bytes The number of bytes to send. |
121 /// @param[in] addr A <code>NetAddress_Dev</code> object holding the | 121 /// @param[in] addr A <code>NetAddress</code> object holding the target |
122 /// target address. | 122 /// address. |
123 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | 123 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
124 /// completion. | 124 /// completion. |
125 /// | 125 /// |
126 /// @return A non-negative number on success to indicate how many bytes have | 126 /// @return A non-negative number on success to indicate how many bytes have |
127 /// been sent; otherwise, an error code from <code>pp_errors.h</code>. | 127 /// been sent; otherwise, an error code from <code>pp_errors.h</code>. |
128 /// <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have | 128 /// <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have |
129 /// required permissions. | 129 /// required permissions. |
130 int32_t SendTo(const char* buffer, | 130 int32_t SendTo(const char* buffer, |
131 int32_t num_bytes, | 131 int32_t num_bytes, |
132 const NetAddress_Dev& addr, | 132 const NetAddress& addr, |
133 const CompletionCallback& callback); | 133 const CompletionCallback& callback); |
134 | 134 |
135 /// Cancels all pending reads and writes, and closes the socket. Any pending | 135 /// Cancels all pending reads and writes, and closes the socket. Any pending |
136 /// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if | 136 /// callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if |
137 /// pending IO was interrupted. After a call to this method, any output | 137 /// pending IO was interrupted. After a call to this method, any output |
138 /// paramters passed into previous <code>RecvFrom()</code> calls won't be | 138 /// paramters passed into previous <code>RecvFrom()</code> calls won't be |
139 /// accessed. It is not valid to call <code>Bind()</code> again. | 139 /// accessed. It is not valid to call <code>Bind()</code> again. |
140 /// | 140 /// |
141 /// The socket is implicitly closed if it is destroyed, so you are not | 141 /// The socket is implicitly closed if it is destroyed, so you are not |
142 /// required to call this method. | 142 /// required to call this method. |
(...skipping 10 matching lines...) Expand all Loading... |
153 /// | 153 /// |
154 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | 154 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
155 int32_t SetOption(PP_UDPSocket_Option_Dev name, | 155 int32_t SetOption(PP_UDPSocket_Option_Dev name, |
156 const Var& value, | 156 const Var& value, |
157 const CompletionCallback& callback); | 157 const CompletionCallback& callback); |
158 }; | 158 }; |
159 | 159 |
160 } // namespace pp | 160 } // namespace pp |
161 | 161 |
162 #endif // PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ | 162 #endif // PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ |
OLD | NEW |