OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h" | 5 #include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 | 11 |
12 namespace ppapi { | 12 namespace ppapi { |
13 | 13 |
14 PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared(PP_Instance instance) | 14 PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared(PP_Instance instance) |
15 : Resource(OBJECT_IS_IMPL, instance), | 15 : Resource(OBJECT_IS_IMPL, instance), |
16 real_socket_id_(0), | 16 real_socket_id_(0), |
17 temp_socket_id_(GenerateTempSocketID()), | |
18 state_(BEFORE_LISTENING), | 17 state_(BEFORE_LISTENING), |
19 tcp_socket_buffer_(NULL) { | 18 tcp_socket_buffer_(NULL) { |
20 } | 19 } |
21 | 20 |
22 PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared( | 21 PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared( |
23 const HostResource& resource) | 22 const HostResource& resource) |
24 : Resource(OBJECT_IS_PROXY, resource), | 23 : Resource(OBJECT_IS_PROXY, resource), |
25 real_socket_id_(0), | 24 real_socket_id_(0), |
26 temp_socket_id_(GenerateTempSocketID()), | |
27 state_(BEFORE_LISTENING), | 25 state_(BEFORE_LISTENING), |
28 tcp_socket_buffer_(NULL) { | 26 tcp_socket_buffer_(NULL) { |
29 } | 27 } |
30 | 28 |
31 PPB_TCPServerSocket_Shared::~PPB_TCPServerSocket_Shared() { | 29 PPB_TCPServerSocket_Shared::~PPB_TCPServerSocket_Shared() { |
32 } | 30 } |
33 | 31 |
34 thunk::PPB_TCPServerSocket_Private_API* | 32 thunk::PPB_TCPServerSocket_Private_API* |
35 PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() { | 33 PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() { |
36 return this; | 34 return this; |
37 } | 35 } |
38 | 36 |
39 int32_t PPB_TCPServerSocket_Shared::Listen(const PP_NetAddress_Private* addr, | 37 int32_t PPB_TCPServerSocket_Shared::Listen(const PP_NetAddress_Private* addr, |
40 int32_t backlog, | 38 int32_t backlog, |
41 PP_CompletionCallback callback) { | 39 PP_CompletionCallback callback) { |
42 if (!addr) | 40 if (!addr) |
43 return PP_ERROR_BADARGUMENT; | 41 return PP_ERROR_BADARGUMENT; |
44 if (!callback.func) | 42 if (!callback.func) |
45 return PP_ERROR_BLOCKS_MAIN_THREAD; | 43 return PP_ERROR_BLOCKS_MAIN_THREAD; |
46 if (state_ != BEFORE_LISTENING) | 44 if (state_ != BEFORE_LISTENING) |
47 return PP_ERROR_FAILED; | 45 return PP_ERROR_FAILED; |
48 if (TrackedCallback::IsPending(listen_callback_)) | 46 if (TrackedCallback::IsPending(listen_callback_)) |
49 return PP_ERROR_INPROGRESS; // Can only have one pending request. | 47 return PP_ERROR_INPROGRESS; // Can only have one pending request. |
50 | 48 |
51 listen_callback_ = new TrackedCallback(this, callback); | 49 listen_callback_ = new TrackedCallback(this, callback); |
52 // Send the request, the browser will call us back via ListenACK | 50 // Send the request, the browser will call us back via ListenACK |
53 SendListen(temp_socket_id_, *addr, backlog); | 51 SendListen(*addr, backlog); |
54 return PP_OK_COMPLETIONPENDING; | 52 return PP_OK_COMPLETIONPENDING; |
55 } | 53 } |
56 | 54 |
57 int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket, | 55 int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket, |
58 PP_CompletionCallback callback) { | 56 PP_CompletionCallback callback) { |
59 if (!tcp_socket) | 57 if (!tcp_socket) |
60 return PP_ERROR_BADARGUMENT; | 58 return PP_ERROR_BADARGUMENT; |
61 if (!callback.func) | 59 if (!callback.func) |
62 return PP_ERROR_BLOCKS_MAIN_THREAD; | 60 return PP_ERROR_BLOCKS_MAIN_THREAD; |
63 | 61 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 96 } |
99 | 97 |
100 if (status == PP_OK) { | 98 if (status == PP_OK) { |
101 real_socket_id_ = real_socket_id; | 99 real_socket_id_ = real_socket_id; |
102 state_ = LISTENING; | 100 state_ = LISTENING; |
103 } | 101 } |
104 | 102 |
105 TrackedCallback::ClearAndRun(&listen_callback_, status); | 103 TrackedCallback::ClearAndRun(&listen_callback_, status); |
106 } | 104 } |
107 | 105 |
108 uint32 PPB_TCPServerSocket_Shared::GenerateTempSocketID() { | |
109 static uint32 socket_id = 0; | |
110 return socket_id++; | |
111 } | |
112 | |
113 } // namespace ppapi | 106 } // namespace ppapi |
OLD | NEW |