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

Unified Diff: native_client_sdk/src/libraries/nacl_io/event_emitter_packet.h

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge emitter changes Created 7 years, 3 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: native_client_sdk/src/libraries/nacl_io/event_emitter_packet.h
diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter_packet.h b/native_client_sdk/src/libraries/nacl_io/event_emitter_packet.h
new file mode 100644
index 0000000000000000000000000000000000000000..2f5cd4c4d04e5cfc9ea98f9281f40427b83db5bd
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/event_emitter_packet.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2013 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.
+
+#ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_
+#define LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_
+
+#include <poll.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "nacl_io/event_emitter.h"
+#include "nacl_io/fifo_packet.h"
+
+#include "sdk_util/auto_lock.h"
+
+namespace nacl_io {
+
+class EventEmitterPacket;
+typedef sdk_util::ScopedRef<EventEmitterPacket> ScopedEmitterPacket;
+
+class EventEmitterPacket : public EventEmitter {
+ public:
+ EventEmitterPacket(size_t rsize, size_t wsize)
binji 2013/09/12 01:47:56 I'd prefer having a .cc file instead of defining t
noelallen1 2013/09/12 23:19:03 That's in the follow on.
+ : rfifo_(NULL),
+ wfifo_(NULL),
+ event_status_(0) {
+
+ rsize = std::max<size_t>(1, rsize);
+ fifo_ = new FIFOPacket(rsize);
binji 2013/09/12 01:47:56 Why allocate? If you define these as non-pointer
noelallen1 2013/09/12 23:19:03 I was allowing for more sharing in the parent clas
+
+ wsize = std::max<size_t>(1, wsize);
+ fifo_ = new FIFOPacket(wsize);
+
+ UpdateStatusLocked();
+ }
+
+ ~EventEmitterPipe() {
+ delete rfifo_;
+ delete wfifo_;
+ }
+
+ virtual uint32_t GetEventStatus() {
+ return event_status_;
+ }
+
+ Packet* ReadPacket() {
binji 2013/09/12 01:47:56 what's the ownership of the returned packet?
noelallen1 2013/09/12 23:19:03 I'll comment.
+ AUTO_LOCK(emitter_lock_);
+ Packet* packet = rfifo_->Read();
+
+ UpdateStatusLocked();
+ return packet;
+ }
+
+ uint32_t WritePacket(Packet* packet) {
binji 2013/09/12 01:47:56 ownership of passed packet?
noelallen1 2013/09/12 23:19:03 Done.
+ AUTO_LOCK(emitter_lock_);
+ uint32_t result = rfifo_->Write(packet);
+
+ UpdateStatusLocked();
+ return result;
+ }
+
+ protected:
+ void UpdateStatusLocked() {
+ uint32_t old_status = event_status_;
+
+ if (!rfifo_->IsEmpty()) {
+ event_status_ |= POLLIN;
+ } else {
+ event_status_ &= ~POLLIN;
+ }
+
+ if (!wfifo_->IsFull()) {
+ event_status_ |= POLLOUT;
+ } else {
+ event_status_ &= ~POLLOUT;
+ }
+
+ uint32_t raise_status = event_status_ & ~old_status;
+ if (raise_status)
+ RaiseEvents_Locked(raise_status);
+ }
+
+ FIFOPacket* rfifo_;
+ FIFOPacket* wfifo_;
+ uint32_t event_status_;
+};
+
+} // namespace nacl_io
+
+#endif // LIBRARIES_NACL_IO_EVENT_EMITTER_PIPE_H_
binji 2013/09/12 01:47:56 PACKET_H_
noelallen1 2013/09/12 23:19:03 Done.
+

Powered by Google App Engine
This is Rietveld 408576698