Updating trunk VERSION from 1014.0 to 1015.0
[chromium-blink-merge.git] / net / curvecp / curvecp_client_socket.cc
blob52711744daeb8949aa2c9836a1d6d1b885cc0ff3
1 // Copyright (c) 2011 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.
5 #include "net/base/ip_endpoint.h"
6 #include "net/base/net_errors.h"
7 #include "net/base/sys_addrinfo.h"
8 #include "net/curvecp/curvecp_client_socket.h"
9 #include "net/curvecp/messenger.h"
11 namespace net {
13 CurveCPClientSocket::CurveCPClientSocket(const AddressList& addresses,
14 net::NetLog* net_log,
15 const net::NetLog::Source& source)
16 : addresses_(addresses),
17 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
18 messenger_(&packetizer_) {
21 CurveCPClientSocket::~CurveCPClientSocket() {
24 int CurveCPClientSocket::Connect(const CompletionCallback& callback) {
25 return packetizer_.Connect(addresses_, &messenger_, callback);
28 void CurveCPClientSocket::Disconnect() {
29 // TODO(mbelshe): DCHECK that we're connected.
30 // Record the ConnectionKey so that we can disconnect it properly.
31 // Do we need a close() on the messenger?
32 // packetizer_.Close();
35 bool CurveCPClientSocket::IsConnected() const {
36 // TODO(mbelshe): return packetizer_.IsConnected();
37 return false;
40 bool CurveCPClientSocket::IsConnectedAndIdle() const {
41 // TODO(mbelshe): return packetizer_.IsConnectedAndIdle();
42 return false;
45 int CurveCPClientSocket::GetPeerAddress(AddressList* address) const {
46 IPEndPoint endpoint;
47 int rv = packetizer_.GetPeerAddress(&endpoint);
48 if (rv < 0)
49 return rv;
50 struct sockaddr_storage sockaddr;
51 size_t sockaddr_length = sizeof(sockaddr);
52 bool success = endpoint.ToSockAddr(
53 reinterpret_cast<struct sockaddr*>(&sockaddr), &sockaddr_length);
54 if (!success)
55 return ERR_FAILED;
56 struct addrinfo ai;
57 memset(&ai, 0, sizeof(ai));
58 memcpy(&ai.ai_addr, &sockaddr, sockaddr_length);
59 ai.ai_addrlen = sockaddr_length;
60 *address = AddressList::CreateByCopying(&ai);
61 return OK;
64 int CurveCPClientSocket::GetLocalAddress(IPEndPoint* address) const {
65 NOTIMPLEMENTED();
66 return ERR_FAILED;
69 const BoundNetLog& CurveCPClientSocket::NetLog() const {
70 return net_log_;
73 void CurveCPClientSocket::SetSubresourceSpeculation() {
74 // This is ridiculous.
77 void CurveCPClientSocket::SetOmniboxSpeculation() {
78 // This is ridiculous.
81 bool CurveCPClientSocket::WasEverUsed() const {
82 // This is ridiculous.
83 return true;
86 bool CurveCPClientSocket::UsingTCPFastOpen() const {
87 // This is ridiculous.
88 return false;
91 int64 CurveCPClientSocket::NumBytesRead() const {
92 return -1;
95 base::TimeDelta CurveCPClientSocket::GetConnectTimeMicros() const {
96 return base::TimeDelta::FromMicroseconds(-1);
99 int CurveCPClientSocket::Read(IOBuffer* buf,
100 int buf_len,
101 const CompletionCallback& callback) {
102 return messenger_.Read(buf, buf_len, callback);
105 int CurveCPClientSocket::Write(IOBuffer* buf,
106 int buf_len,
107 const CompletionCallback& callback) {
108 return messenger_.Write(buf, buf_len, callback);
111 bool CurveCPClientSocket::SetReceiveBufferSize(int32 size) {
112 return true;
115 bool CurveCPClientSocket::SetSendBufferSize(int32 size) {
116 return true;
119 } // namespace net