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

Side by Side 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: Remove event friends, rename EventListenerPoll 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_
6 #define LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_
7
8 #include <poll.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11
12 #include "nacl_io/event_emitter.h"
13 #include "nacl_io/fifo_packet.h"
14
15 #include "sdk_util/auto_lock.h"
16
17 namespace nacl_io {
18
19 class EventEmitterPacket;
20 typedef sdk_util::ScopedRef<EventEmitterPacket> ScopedEmitterPacket;
21
22 class EventEmitterPacket : public EventEmitter {
23 public:
24 EventEmitterPacket(size_t rsize, size_t wsize)
25 : rfifo_(NULL),
26 wfifo_(NULL),
27 event_status_(0) {
28
29 rsize = std::max<size_t>(1, rsize);
30 fifo_ = new FIFOPacket(rsize);
31
32 wsize = std::max<size_t>(1, wsize);
33 fifo_ = new FIFOPacket(wsize);
34
35 UpdateStatusLocked();
36 }
37
38 ~EventEmitterPipe() {
39 delete rfifo_;
40 delete wfifo_;
41 }
42
43 virtual uint32_t GetEventStatus() {
44 return event_status_;
45 }
46
47 Packet* ReadTXPacket_Locked() {
binji 2013/09/12 01:47:57 why TXPacket? ReadPacket is easier to read...
noelallen1 2013/09/12 23:19:03 There are two FIFOs, an incoming and and outgoing.
48 Packet* packet = rfifo_->Read();
49
50 UpdateStatusLocked();
binji 2013/09/12 01:47:57 _Locked?
noelallen1 2013/09/12 23:19:03 Done.
51 return packet;
52 }
53
54 uint32_t WriteTXPacket_Locked(Packet* packet) {
55 uint32_t result = rfifo_->Write(packet);
56
57 UpdateStatusLocked();
58 return result;
59 }
60
61 protected:
62 void UpdateStatus_Locked() {
63 uint32_t old_status = event_status_;
64
65 if (!rfifo_->IsEmpty()) {
66 event_status_ |= POLLIN;
67 } else {
68 event_status_ &= ~POLLIN;
69 }
70
71 if (!wfifo_->IsFull()) {
72 event_status_ |= POLLOUT;
73 } else {
74 event_status_ &= ~POLLOUT;
75 }
76
77 uint32_t raise_status = event_status_ & ~old_status;
78 if (raise_status)
79 RaiseEvents_Locked(raise_status);
80 }
81
82 FIFOPacket* rfifo_;
83 FIFOPacket* wfifo_;
84 uint32_t event_status_;
85 };
86
87 } // namespace nacl_io
88
89 #endif // LIBRARIES_NACL_IO_EVENT_EMITTER_PIPE_H_
90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698