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

Unified Diff: ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc

Issue 9283022: Exposed Listen and Accept methods to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Sync. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
diff --git a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
new file mode 100644
index 0000000000000000000000000000000000000000..284db1ec4134f4c0ff73be8919e7531f4ce92a07
--- /dev/null
+++ b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h"
+
+#include <cstddef>
+
+#include "base/logging.h"
+#include "ppapi/c/pp_errors.h"
+
+namespace ppapi {
+
+PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared(PP_Instance instance)
+ : Resource(OBJECT_IS_IMPL, instance),
+ real_socket_id_(0),
+ temp_socket_id_(GenerateTempSocketID()),
+ state_(BEFORE_LISTENING),
+ tcp_socket_buffer_(NULL) {
+}
+
+PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared(
+ const HostResource& resource)
+ : Resource(OBJECT_IS_PROXY, resource),
+ real_socket_id_(0),
+ temp_socket_id_(GenerateTempSocketID()),
+ state_(BEFORE_LISTENING),
+ tcp_socket_buffer_(NULL) {
+}
+
+PPB_TCPServerSocket_Shared::~PPB_TCPServerSocket_Shared() {
+}
+
+thunk::PPB_TCPServerSocket_Private_API*
+PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() {
+ return this;
+}
+
+int32_t PPB_TCPServerSocket_Shared::Listen(const PP_NetAddress_Private* addr,
+ int32_t backlog,
+ PP_CompletionCallback callback) {
+ if (!addr)
+ return PP_ERROR_BADARGUMENT;
+ if (!callback.func)
+ return PP_ERROR_BLOCKS_MAIN_THREAD;
+ if (state_ != BEFORE_LISTENING)
+ return PP_ERROR_FAILED;
+ if (TrackedCallback::IsPending(listen_callback_))
+ return PP_ERROR_INPROGRESS; // Can only have one pending request.
+
+ listen_callback_ = new TrackedCallback(this, callback);
+ // Send the request, the browser will call us back via ListenACK
+ SendListen(temp_socket_id_, *addr, backlog);
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket,
+ PP_CompletionCallback callback) {
+ if (!tcp_socket)
+ return PP_ERROR_BADARGUMENT;
+ if (!callback.func)
+ return PP_ERROR_BLOCKS_MAIN_THREAD;
+
+ if (state_ != LISTENING)
+ return PP_ERROR_FAILED;
+ if (TrackedCallback::IsPending(accept_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ tcp_socket_buffer_ = tcp_socket;
+ accept_callback_ = new TrackedCallback(this, callback);
+
+ SendAccept();
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void PPB_TCPServerSocket_Shared::StopListening() {
+ if (state_ == CLOSED)
+ return;
+
+ state_ = CLOSED;
+
+ SendStopListening();
+ real_socket_id_ = 0;
+
+ if (listen_callback_.get())
+ listen_callback_->PostAbort();
+ if (accept_callback_.get())
+ accept_callback_->PostAbort();
+ tcp_socket_buffer_ = NULL;
+}
+
+void PPB_TCPServerSocket_Shared::OnListenCompleted(uint32 real_socket_id,
+ int32_t status) {
+ if (state_ != BEFORE_LISTENING ||
+ !TrackedCallback::IsPending(listen_callback_)) {
+ NOTREACHED();
+ return;
+ }
+
+ if (status == PP_OK) {
+ real_socket_id_ = real_socket_id;
+ state_ = LISTENING;
+ }
+
+ TrackedCallback::ClearAndRun(&listen_callback_, status);
+}
+
+uint32 PPB_TCPServerSocket_Shared::GenerateTempSocketID() {
+ static uint32 socket_id = 0;
+ return socket_id++;
+}
+
+} // namespace ppapi
« no previous file with comments | « ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698