1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sync_socket.h"
11 #include <sys/types.h>
13 #include "base/notreached.h"
18 bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
22 void SyncSocket::Close() {
26 size_t SyncSocket::Send(const void* buffer, size_t length) {
27 const ssize_t bytes_written = write(handle(), buffer, length);
28 return bytes_written > 0 ? static_cast<size_t>(bytes_written) : 0;
31 size_t SyncSocket::Receive(void* buffer, size_t length) {
32 const ssize_t bytes_read = read(handle(), buffer, length);
33 return bytes_read > 0 ? static_cast<size_t>(bytes_read) : 0;
36 size_t SyncSocket::ReceiveWithTimeout(void* buffer, size_t length, TimeDelta) {
41 size_t SyncSocket::Peek() {
46 bool SyncSocket::IsValid() const {
47 return handle_.is_valid();
50 SyncSocket::Handle SyncSocket::handle() const {
54 SyncSocket::Handle SyncSocket::Release() {
55 return handle_.release();
58 size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
59 return SyncSocket::Send(buffer, length);
62 bool CancelableSyncSocket::Shutdown() {
68 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a,
69 CancelableSyncSocket* socket_b) {
70 return SyncSocket::CreatePair(socket_a, socket_b);