Allow missing socketType in SocketInfo if socket is not connected

BUG=242261

Review URL: https://chromiumcodereview.appspot.com/15359007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203036 0039d316-1c4b-4281-b951-d872f2087c98
parent 2ff3ed41
......@@ -616,38 +616,40 @@ bool SocketGetInfoFunction::Prepare() {
}
void SocketGetInfoFunction::Work() {
api::socket::SocketInfo info;
Socket* socket = GetSocket(params_->socket_id);
if (socket) {
// This represents what we know about the socket, and does not call through
// to the system.
if (socket->GetSocketType() == Socket::TYPE_TCP)
info.socket_type = extensions::api::socket::SOCKET_TYPE_TCP;
else
info.socket_type = extensions::api::socket::SOCKET_TYPE_UDP;
info.connected = socket->IsConnected();
// Grab the peer address as known by the OS. This and the call below will
// always succeed while the socket is connected, even if the socket has
// been remotely closed by the peer; only reading the socket will reveal
// that it should be closed locally.
net::IPEndPoint peerAddress;
if (socket->GetPeerAddress(&peerAddress)) {
info.peer_address.reset(
new std::string(peerAddress.ToStringWithoutPort()));
info.peer_port.reset(new int(peerAddress.port()));
}
// Grab the local address as known by the OS.
net::IPEndPoint localAddress;
if (socket->GetLocalAddress(&localAddress)) {
info.local_address.reset(
new std::string(localAddress.ToStringWithoutPort()));
info.local_port.reset(new int(localAddress.port()));
}
} else {
if (!socket) {
error_ = kSocketNotFoundError;
return;
}
api::socket::SocketInfo info;
// This represents what we know about the socket, and does not call through
// to the system.
if (socket->GetSocketType() == Socket::TYPE_TCP)
info.socket_type = extensions::api::socket::SOCKET_TYPE_TCP;
else
info.socket_type = extensions::api::socket::SOCKET_TYPE_UDP;
info.connected = socket->IsConnected();
// Grab the peer address as known by the OS. This and the call below will
// always succeed while the socket is connected, even if the socket has
// been remotely closed by the peer; only reading the socket will reveal
// that it should be closed locally.
net::IPEndPoint peerAddress;
if (socket->GetPeerAddress(&peerAddress)) {
info.peer_address.reset(
new std::string(peerAddress.ToStringWithoutPort()));
info.peer_port.reset(new int(peerAddress.port()));
}
// Grab the local address as known by the OS.
net::IPEndPoint localAddress;
if (socket->GetLocalAddress(&localAddress)) {
info.local_address.reset(
new std::string(localAddress.ToStringWithoutPort()));
info.local_port.reset(new int(localAddress.port()));
}
SetResult(info.ToValue().release());
}
......
......@@ -55,8 +55,10 @@ var testSocketCreation = function() {
}
socket.destroy(socketInfo.socketId);
chrome.test.succeed();
socket.getInfo(socketInfo.socketId, function(info) {
chrome.test.assertEq(undefined, info);
chrome.test.succeed();
});
}
chrome.test.assertTrue(socketInfo.socketId > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment