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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 PPB_TCPServerSocket_Shared::~PPB_TCPServerSocket_Shared() { | 29 PPB_TCPServerSocket_Shared::~PPB_TCPServerSocket_Shared() { |
30 } | 30 } |
31 | 31 |
32 thunk::PPB_TCPServerSocket_Private_API* | 32 thunk::PPB_TCPServerSocket_Private_API* |
33 PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() { | 33 PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() { |
34 return this; | 34 return this; |
35 } | 35 } |
36 | 36 |
37 int32_t PPB_TCPServerSocket_Shared::Listen(const PP_NetAddress_Private* addr, | 37 int32_t PPB_TCPServerSocket_Shared::Listen( |
38 int32_t backlog, | 38 const PP_NetAddress_Private* addr, |
39 PP_CompletionCallback callback) { | 39 int32_t backlog, |
| 40 scoped_refptr<TrackedCallback> callback) { |
40 if (!addr) | 41 if (!addr) |
41 return PP_ERROR_BADARGUMENT; | 42 return PP_ERROR_BADARGUMENT; |
42 if (!callback.func) | |
43 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
44 if (state_ != BEFORE_LISTENING) | 43 if (state_ != BEFORE_LISTENING) |
45 return PP_ERROR_FAILED; | 44 return PP_ERROR_FAILED; |
46 if (TrackedCallback::IsPending(listen_callback_)) | 45 if (TrackedCallback::IsPending(listen_callback_)) |
47 return PP_ERROR_INPROGRESS; // Can only have one pending request. | 46 return PP_ERROR_INPROGRESS; // Can only have one pending request. |
48 | 47 |
49 listen_callback_ = new TrackedCallback(this, callback); | 48 listen_callback_ = callback; |
50 // Send the request, the browser will call us back via ListenACK | 49 // Send the request, the browser will call us back via ListenACK |
51 SendListen(*addr, backlog); | 50 SendListen(*addr, backlog); |
52 return PP_OK_COMPLETIONPENDING; | 51 return PP_OK_COMPLETIONPENDING; |
53 } | 52 } |
54 | 53 |
55 int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket, | 54 int32_t PPB_TCPServerSocket_Shared::Accept( |
56 PP_CompletionCallback callback) { | 55 PP_Resource* tcp_socket, |
| 56 scoped_refptr<TrackedCallback> callback) { |
57 if (!tcp_socket) | 57 if (!tcp_socket) |
58 return PP_ERROR_BADARGUMENT; | 58 return PP_ERROR_BADARGUMENT; |
59 if (!callback.func) | |
60 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
61 | 59 |
62 if (state_ != LISTENING) | 60 if (state_ != LISTENING) |
63 return PP_ERROR_FAILED; | 61 return PP_ERROR_FAILED; |
64 if (TrackedCallback::IsPending(accept_callback_)) | 62 if (TrackedCallback::IsPending(accept_callback_)) |
65 return PP_ERROR_INPROGRESS; | 63 return PP_ERROR_INPROGRESS; |
66 | 64 |
67 tcp_socket_buffer_ = tcp_socket; | 65 tcp_socket_buffer_ = tcp_socket; |
68 accept_callback_ = new TrackedCallback(this, callback); | 66 accept_callback_ = callback; |
69 | 67 |
70 SendAccept(); | 68 SendAccept(); |
71 return PP_OK_COMPLETIONPENDING; | 69 return PP_OK_COMPLETIONPENDING; |
72 } | 70 } |
73 | 71 |
74 void PPB_TCPServerSocket_Shared::StopListening() { | 72 void PPB_TCPServerSocket_Shared::StopListening() { |
75 if (state_ == CLOSED) | 73 if (state_ == CLOSED) |
76 return; | 74 return; |
77 | 75 |
78 state_ = CLOSED; | 76 state_ = CLOSED; |
(...skipping 18 matching lines...) Expand all Loading... |
97 | 95 |
98 if (status == PP_OK) { | 96 if (status == PP_OK) { |
99 socket_id_ = socket_id; | 97 socket_id_ = socket_id; |
100 state_ = LISTENING; | 98 state_ = LISTENING; |
101 } | 99 } |
102 | 100 |
103 TrackedCallback::ClearAndRun(&listen_callback_, status); | 101 TrackedCallback::ClearAndRun(&listen_callback_, status); |
104 } | 102 } |
105 | 103 |
106 } // namespace ppapi | 104 } // namespace ppapi |
OLD | NEW |