blob: 6d6405d23cd63114e96ad4a71ac1024cabc97d8e [file] [log] [blame]
[email protected]d0bac292012-02-29 16:10:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/sync_socket.h"
6
7#include <errno.h>
8#include <limits.h>
9#include <stdio.h>
10#include <sys/types.h>
11
12#include "base/file_util.h"
13#include "base/logging.h"
14
15
16namespace base {
17
18const SyncSocket::Handle SyncSocket::kInvalidHandle = -1;
19
20SyncSocket::SyncSocket() : handle_(kInvalidHandle) {
[email protected]d0bac292012-02-29 16:10:4521}
22
23SyncSocket::~SyncSocket() {
24}
25
26// static
27bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
28 return false;
29}
30
31bool SyncSocket::Close() {
[email protected]5cfa5222012-07-14 14:06:0632 if (handle_ != kInvalidHandle) {
33 if (close(handle_) < 0)
34 DPLOG(ERROR) << "close";
35 handle_ = -1;
36 }
37 return true;
[email protected]d0bac292012-02-29 16:10:4538}
39
40size_t SyncSocket::Send(const void* buffer, size_t length) {
[email protected]5cfa5222012-07-14 14:06:0641 // Not implemented since it's not needed by any client code yet.
42 return -1;
[email protected]d0bac292012-02-29 16:10:4543}
44
45size_t SyncSocket::Receive(void* buffer, size_t length) {
[email protected]5cfa5222012-07-14 14:06:0646 return read(handle_, buffer, length);
[email protected]d0bac292012-02-29 16:10:4547}
48
49size_t SyncSocket::Peek() {
[email protected]5cfa5222012-07-14 14:06:0650 return -1;
[email protected]d0bac292012-02-29 16:10:4551}
52
[email protected]5cfa5222012-07-14 14:06:0653CancelableSyncSocket::CancelableSyncSocket() {
54}
55
[email protected]d0bac292012-02-29 16:10:4556CancelableSyncSocket::CancelableSyncSocket(Handle handle)
57 : SyncSocket(handle) {
58}
59
[email protected]771fc8d2012-05-19 01:39:0560size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
[email protected]5cfa5222012-07-14 14:06:0661 return -1;
[email protected]771fc8d2012-05-19 01:39:0562}
63
[email protected]d0bac292012-02-29 16:10:4564bool CancelableSyncSocket::Shutdown() {
65 return false;
66}
67
68// static
69bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a,
70 CancelableSyncSocket* socket_b) {
71 return SyncSocket::CreatePair(socket_a, socket_b);
72}
73
74} // namespace base