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"
13 CurveCPClientSocket::CurveCPClientSocket(const AddressList
& addresses
,
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();
40 bool CurveCPClientSocket::IsConnectedAndIdle() const {
41 // TODO(mbelshe): return packetizer_.IsConnectedAndIdle();
45 int CurveCPClientSocket::GetPeerAddress(AddressList
* address
) const {
47 int rv
= packetizer_
.GetPeerAddress(&endpoint
);
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
);
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
);
64 int CurveCPClientSocket::GetLocalAddress(IPEndPoint
* address
) const {
69 const BoundNetLog
& CurveCPClientSocket::NetLog() const {
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.
86 bool CurveCPClientSocket::UsingTCPFastOpen() const {
87 // This is ridiculous.
91 int64
CurveCPClientSocket::NumBytesRead() const {
95 base::TimeDelta
CurveCPClientSocket::GetConnectTimeMicros() const {
96 return base::TimeDelta::FromMicroseconds(-1);
99 int CurveCPClientSocket::Read(IOBuffer
* buf
,
101 const CompletionCallback
& callback
) {
102 return messenger_
.Read(buf
, buf_len
, callback
);
105 int CurveCPClientSocket::Write(IOBuffer
* buf
,
107 const CompletionCallback
& callback
) {
108 return messenger_
.Write(buf
, buf_len
, callback
);
111 bool CurveCPClientSocket::SetReceiveBufferSize(int32 size
) {
115 bool CurveCPClientSocket::SetSendBufferSize(int32 size
) {