socket.cc (937B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "socket.h" 6 7 #include <algorithm> 8 #include <cassert> 9 #include <cstdint> 10 #include <cstring> 11 12 #include "prinrval.h" 13 #include "prio.h" 14 15 namespace TlsSocket { 16 17 int32_t DummyPrSocket::Read(PRFileDesc *fd, void *data, int32_t len) { 18 assert(data && len > 0); 19 20 int32_t amount = std::min(len, static_cast<int32_t>(len_)); 21 memcpy(data, buf_, amount); 22 23 buf_ += amount; 24 len_ -= amount; 25 26 return amount; 27 } 28 29 int32_t DummyPrSocket::Write(PRFileDesc *fd, const void *buf, int32_t length) { 30 return length; 31 } 32 33 int32_t DummyPrSocket::Recv(PRFileDesc *fd, void *buf, int32_t buflen, 34 int32_t flags, PRIntervalTime to) { 35 assert(flags == 0); 36 return Read(fd, buf, buflen); 37 } 38 39 } // namespace TlsSocket