summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-15 20:46:32 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-15 20:46:32 +0000
commit051e4ecafeb6da960517224bdd0348dae7e43784 (patch)
treefe54348a4cd34c6d6bc6fad3d013788349729b27 /net/socket
parenta82151cc51eab71162a356a8b9f83885d9386ef8 (diff)
downloadchromium_src-051e4ecafeb6da960517224bdd0348dae7e43784.zip
chromium_src-051e4ecafeb6da960517224bdd0348dae7e43784.tar.gz
chromium_src-051e4ecafeb6da960517224bdd0348dae7e43784.tar.bz2
Move MapWinsockError() and MapPosixError() to net_errors.h.
Added new net::MapSystemError() that is now used in place of MapWinsockError() and MapPosixError() BUG=None TEST=compiles Review URL: http://codereview.chromium.org/6694032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/tcp_client_socket_libevent.cc57
-rw-r--r--net/socket/tcp_client_socket_win.cc14
2 files changed, 16 insertions, 55 deletions
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 7282fd4..c94276b 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -69,45 +69,6 @@ void SetTCPKeepAlive(int fd) {
#endif
}
-// Convert values from <errno.h> to values from "net/base/net_errors.h"
-int MapPosixError(int os_error) {
- // There are numerous posix error codes, but these are the ones we thus far
- // find interesting.
- switch (os_error) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- return ERR_IO_PENDING;
- case EACCES:
- return ERR_ACCESS_DENIED;
- case ENETDOWN:
- return ERR_INTERNET_DISCONNECTED;
- case ETIMEDOUT:
- return ERR_TIMED_OUT;
- case ECONNRESET:
- case ENETRESET: // Related to keep-alive
- case EPIPE:
- return ERR_CONNECTION_RESET;
- case ECONNABORTED:
- return ERR_CONNECTION_ABORTED;
- case ECONNREFUSED:
- return ERR_CONNECTION_REFUSED;
- case EHOSTUNREACH:
- case EHOSTDOWN:
- case ENETUNREACH:
- return ERR_ADDRESS_UNREACHABLE;
- case EADDRNOTAVAIL:
- return ERR_ADDRESS_INVALID;
- case 0:
- return OK;
- default:
- LOG(WARNING) << "Unknown error " << os_error
- << " mapped to net::ERR_FAILED";
- return ERR_FAILED;
- }
-}
-
int MapConnectError(int os_error) {
switch (os_error) {
case EACCES:
@@ -115,7 +76,7 @@ int MapConnectError(int os_error) {
case ETIMEDOUT:
return ERR_CONNECTION_TIMED_OUT;
default: {
- int net_error = MapPosixError(os_error);
+ int net_error = MapSystemError(os_error);
if (net_error == ERR_FAILED)
return ERR_CONNECTION_FAILED; // More specific than ERR_FAILED.
@@ -253,7 +214,7 @@ int TCPClientSocketLibevent::DoConnect() {
// Create a non-blocking socket.
connect_os_error_ = CreateSocket(current_ai_);
if (connect_os_error_)
- return MapPosixError(connect_os_error_);
+ return MapSystemError(connect_os_error_);
// Connect the socket.
if (!use_tcp_fastopen_) {
@@ -280,7 +241,7 @@ int TCPClientSocketLibevent::DoConnect() {
&write_watcher_)) {
connect_os_error_ = errno;
DVLOG(1) << "WatchFileDescriptor failed: " << connect_os_error_;
- return MapPosixError(connect_os_error_);
+ return MapSystemError(connect_os_error_);
}
return ERR_IO_PENDING;
@@ -395,14 +356,14 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf,
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
DVLOG(1) << "read failed, errno " << errno;
- return MapPosixError(errno);
+ return MapSystemError(errno);
}
if (!MessageLoopForIO::current()->WatchFileDescriptor(
socket_, true, MessageLoopForIO::WATCH_READ,
&read_socket_watcher_, &read_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on read, errno " << errno;
- return MapPosixError(errno);
+ return MapSystemError(errno);
}
read_buf_ = buf;
@@ -433,13 +394,13 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
return nwrite;
}
if (errno != EAGAIN && errno != EWOULDBLOCK)
- return MapPosixError(errno);
+ return MapSystemError(errno);
if (!MessageLoopForIO::current()->WatchFileDescriptor(
socket_, true, MessageLoopForIO::WATCH_WRITE,
&write_socket_watcher_, &write_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno;
- return MapPosixError(errno);
+ return MapSystemError(errno);
}
write_buf_ = buf;
@@ -610,7 +571,7 @@ void TCPClientSocketLibevent::DidCompleteRead() {
LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, result,
read_buf_->data());
} else {
- result = MapPosixError(errno);
+ result = MapSystemError(errno);
}
if (result != ERR_IO_PENDING) {
@@ -637,7 +598,7 @@ void TCPClientSocketLibevent::DidCompleteWrite() {
LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, result,
write_buf_->data());
} else {
- result = MapPosixError(errno);
+ result = MapSystemError(errno);
}
if (result != ERR_IO_PENDING) {
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index 6d733fa..d33bd40 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -37,7 +37,7 @@ int MapConnectError(int os_error) {
case WSAETIMEDOUT:
return ERR_CONNECTION_TIMED_OUT;
default: {
- int net_error = MapWinsockError(os_error);
+ int net_error = MapSystemError(os_error);
if (net_error == ERR_FAILED)
return ERR_CONNECTION_FAILED; // More specific than ERR_FAILED.
@@ -316,7 +316,7 @@ int TCPClientSocketWin::DoConnect() {
connect_os_error_ = CreateSocket(ai);
if (connect_os_error_ != 0)
- return MapWinsockError(connect_os_error_);
+ return MapSystemError(connect_os_error_);
DCHECK(!core_);
core_ = new Core(this);
@@ -526,7 +526,7 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
} else {
int os_error = WSAGetLastError();
if (os_error != WSA_IO_PENDING)
- return MapWinsockError(os_error);
+ return MapSystemError(os_error);
}
core_->WatchForRead();
waiting_read_ = true;
@@ -578,7 +578,7 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
} else {
int os_error = WSAGetLastError();
if (os_error != WSA_IO_PENDING)
- return MapWinsockError(os_error);
+ return MapSystemError(os_error);
}
core_->WatchForWrite();
waiting_write_ = true;
@@ -743,7 +743,7 @@ void TCPClientSocketWin::DidCompleteConnect() {
if (rv == SOCKET_ERROR) {
NOTREACHED();
os_error = WSAGetLastError();
- result = MapWinsockError(os_error);
+ result = MapSystemError(os_error);
} else if (events.lNetworkEvents & FD_CONNECT) {
os_error = events.iErrorCode[FD_CONNECT_BIT];
result = MapConnectError(os_error);
@@ -776,7 +776,7 @@ void TCPClientSocketWin::DidCompleteRead() {
LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes,
core_->read_buffer_.buf);
}
- DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError()));
+ DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError()));
}
void TCPClientSocketWin::DidCompleteWrite() {
@@ -789,7 +789,7 @@ void TCPClientSocketWin::DidCompleteWrite() {
waiting_write_ = false;
int rv;
if (!ok) {
- rv = MapWinsockError(WSAGetLastError());
+ rv = MapSystemError(WSAGetLastError());
} else {
rv = static_cast<int>(num_bytes);
if (rv > core_->write_buffer_length_ || rv < 0) {