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