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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/socket/fifo_packet.cc

Issue 1679643002: nacl_io: Add SOCK_DGRAM support to socketpair() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review feedback Created 4 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 unified diff | Download patch
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698