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

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: Init and Accept calls are combined 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
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..af36005bc7327aad21dbd71fbb35df186628947d
--- /dev/null
+++ b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
@@ -0,0 +1,114 @@
+// 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 <cstring>
yzshen1 2012/02/14 00:42:04 why do we need cstring?
ygorshenin1 2012/02/14 09:34:44 Thanks, You're right. <cstring> isn't needed here.
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "ppapi/c/pp_errors.h"
+
+namespace ppapi {
+
+PPB_TCPServerSocket_Shared::PPB_TCPServerSocket_Shared(PP_Instance instance)
+ : Resource(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(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_ != LISTENING)
yzshen1 2012/02/14 00:42:04 (1) This is incorrect according to the API spec. C
+ 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

Powered by Google App Engine
This is Rietveld 408576698