| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "nacl_io/socket/udp_node.h" | 5 #include "nacl_io/socket/udp_node.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // We assume that transmits will always complete. If the upstream | 89 // We assume that transmits will always complete. If the upstream |
| 90 // actually back pressures, enough to prevent the Send callback | 90 // actually back pressures, enough to prevent the Send callback |
| 91 // from triggering, this resource may never go away. | 91 // from triggering, this resource may never go away. |
| 92 ScopedSocketNode node_; | 92 ScopedSocketNode node_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 class UdpRecvWork : public UdpWork { | 95 class UdpRecvWork : public UdpWork { |
| 96 public: | 96 public: |
| 97 explicit UdpRecvWork(const ScopedUdpEventEmitter& emitter) | 97 explicit UdpRecvWork(const ScopedUdpEventEmitter& emitter) |
| 98 : UdpWork(emitter) { | 98 : UdpWork(emitter) { |
| 99 data_ = new char[kMaxPacketSize]; | |
| 100 } | 99 } |
| 101 | 100 |
| 102 ~UdpRecvWork() { delete[] data_; } | |
| 103 | |
| 104 virtual bool Start(int32_t val) { | 101 virtual bool Start(int32_t val) { |
| 105 AUTO_LOCK(emitter_->GetLock()); | 102 AUTO_LOCK(emitter_->GetLock()); |
| 106 UdpNode* stream = static_cast<UdpNode*>(emitter_->stream()); | 103 UdpNode* stream = static_cast<UdpNode*>(emitter_->stream()); |
| 107 | 104 |
| 108 // Does the stream exist, and can it recv? | 105 // Does the stream exist, and can it recv? |
| 109 if (NULL == stream || !stream->TestStreamFlags(SSF_CAN_RECV)) | 106 if (NULL == stream || !stream->TestStreamFlags(SSF_CAN_RECV)) |
| 110 return false; | 107 return false; |
| 111 | 108 |
| 112 // Check if we are already receiving. | 109 // Check if we are already receiving. |
| 113 if (stream->TestStreamFlags(SSF_RECVING)) | 110 if (stream->TestStreamFlags(SSF_RECVING)) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 packet->Copy(data_, length_error, addr_); | 136 packet->Copy(data_, length_error, addr_); |
| 140 emitter_->WriteRXPacket_Locked(packet); | 137 emitter_->WriteRXPacket_Locked(packet); |
| 141 stream->ClearStreamFlags(SSF_RECVING); | 138 stream->ClearStreamFlags(SSF_RECVING); |
| 142 stream->QueueInput(); | 139 stream->QueueInput(); |
| 143 } else { | 140 } else { |
| 144 stream->SetError_Locked(length_error); | 141 stream->SetError_Locked(length_error); |
| 145 } | 142 } |
| 146 } | 143 } |
| 147 | 144 |
| 148 private: | 145 private: |
| 149 char* data_; | 146 char data_[kMaxPacketSize]; |
| 150 PP_Resource addr_; | 147 PP_Resource addr_; |
| 151 }; | 148 }; |
| 152 | 149 |
| 153 UdpNode::UdpNode(Filesystem* filesystem) | 150 UdpNode::UdpNode(Filesystem* filesystem) |
| 154 : SocketNode(filesystem), | 151 : SocketNode(filesystem), |
| 155 emitter_(new UdpEventEmitter(kDefaultFifoSize, kDefaultFifoSize)) { | 152 emitter_(new UdpEventEmitter(kDefaultFifoSize, kDefaultFifoSize)) { |
| 156 emitter_->AttachStream(this); | 153 emitter_->AttachStream(this); |
| 157 } | 154 } |
| 158 | 155 |
| 159 void UdpNode::Destroy() { | 156 void UdpNode::Destroy() { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 int capped_len = static_cast<int32_t>(std::min<int>(len, kMaxPacketSize)); | 295 int capped_len = static_cast<int32_t>(std::min<int>(len, kMaxPacketSize)); |
| 299 Packet* packet = new Packet(filesystem_->ppapi()); | 296 Packet* packet = new Packet(filesystem_->ppapi()); |
| 300 packet->Copy(buf, capped_len, addr); | 297 packet->Copy(buf, capped_len, addr); |
| 301 | 298 |
| 302 emitter_->WriteTXPacket_Locked(packet); | 299 emitter_->WriteTXPacket_Locked(packet); |
| 303 *out_len = capped_len; | 300 *out_len = capped_len; |
| 304 return 0; | 301 return 0; |
| 305 } | 302 } |
| 306 | 303 |
| 307 } // namespace nacl_io | 304 } // namespace nacl_io |
| OLD | NEW |