Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket.cc

Issue 10790137: Adds socket.getInfo to the socket API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adds tests Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/socket/tcp_socket.h" 5 #include "chrome/browser/extensions/api/socket/tcp_socket.h"
6 6
7 #include "chrome/browser/extensions/api/api_resource.h" 7 #include "chrome/browser/extensions/api/api_resource.h"
8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
9 #include "net/base/address_list.h" 9 #include "net/base/address_list.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return false; 133 return false;
134 return socket_->SetKeepAlive(enable, delay); 134 return socket_->SetKeepAlive(enable, delay);
135 } 135 }
136 136
137 bool TCPSocket::SetNoDelay(bool no_delay) { 137 bool TCPSocket::SetNoDelay(bool no_delay) {
138 if (!socket_.get()) 138 if (!socket_.get())
139 return false; 139 return false;
140 return socket_->SetNoDelay(no_delay); 140 return socket_->SetNoDelay(no_delay);
141 } 141 }
142 142
143 bool TCPSocket::IsTCPSocket() {
144 return true;
145 }
146
147 bool TCPSocket::GetPeerAddress(net::IPEndPoint* address) {
148 return !socket_->GetPeerAddress(address);
149 }
150
151 bool TCPSocket::GetLocalAddress(net::IPEndPoint* address) {
152 return !socket_->GetLocalAddress(address);
153 }
154
155
143 int TCPSocket::WriteImpl(net::IOBuffer* io_buffer, 156 int TCPSocket::WriteImpl(net::IOBuffer* io_buffer,
144 int io_buffer_size, 157 int io_buffer_size,
145 const net::CompletionCallback& callback) { 158 const net::CompletionCallback& callback) {
146 if (!socket_.get() || !socket_->IsConnected()) 159 if (!socket_.get() || !socket_->IsConnected())
147 return net::ERR_SOCKET_NOT_CONNECTED; 160 return net::ERR_SOCKET_NOT_CONNECTED;
148 else 161 else
149 return socket_->Write(io_buffer, io_buffer_size, callback); 162 return socket_->Write(io_buffer, io_buffer_size, callback);
150 } 163 }
151 164
152 void TCPSocket::OnConnectComplete(int result) { 165 void TCPSocket::OnConnectComplete(int result) {
153 DCHECK(!connect_callback_.is_null()); 166 DCHECK(!connect_callback_.is_null());
154 DCHECK(!is_connected_); 167 DCHECK(!is_connected_);
155 is_connected_ = result == net::OK; 168 is_connected_ = result == net::OK;
156 connect_callback_.Run(result); 169 connect_callback_.Run(result);
157 connect_callback_.Reset(); 170 connect_callback_.Reset();
158 } 171 }
159 172
160 void TCPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 173 void TCPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
161 int result) { 174 int result) {
162 DCHECK(!read_callback_.is_null()); 175 DCHECK(!read_callback_.is_null());
163 read_callback_.Run(result, io_buffer); 176 read_callback_.Run(result, io_buffer);
164 read_callback_.Reset(); 177 read_callback_.Reset();
165 } 178 }
166 179
167 } // namespace extensions 180 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698