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/fifo_packet.h" | 5 #include "nacl_io/socket/fifo_packet.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 cur_bytes_ -= out->len(); | 62 cur_bytes_ -= out->len(); |
63 return out; | 63 return out; |
64 } | 64 } |
65 | 65 |
66 void FIFOPacket::WritePacket(Packet* packet) { | 66 void FIFOPacket::WritePacket(Packet* packet) { |
67 cur_bytes_ += packet->len(); | 67 cur_bytes_ += packet->len(); |
68 packets_.push_front(packet); | 68 packets_.push_front(packet); |
69 } | 69 } |
70 | 70 |
| 71 size_t FIFOPacket::Read(void* buf, size_t len) { |
| 72 Packet* packet = ReadPacket(); |
| 73 if (!packet) |
| 74 return 0; |
| 75 |
| 76 size_t bytes = packet->len(); |
| 77 if (bytes > len) |
| 78 bytes = len; |
| 79 memcpy(buf, packet->buffer(), bytes); |
| 80 |
| 81 delete packet; |
| 82 return bytes; |
| 83 } |
| 84 |
| 85 size_t FIFOPacket::Write(const void* buf, size_t len) { |
| 86 if (len > WriteAvailable()) |
| 87 return 0; |
| 88 |
| 89 Packet* packet = new Packet(NULL); |
| 90 packet->Copy(buf, len, 0); |
| 91 WritePacket(packet); |
| 92 return len; |
| 93 } |
| 94 |
71 } // namespace nacl_io | 95 } // namespace nacl_io |
OLD | NEW |