summaryrefslogtreecommitdiffstats
path: root/net/udp
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/udp
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/udp')
-rw-r--r--net/udp/udp_socket_libevent.cc71
-rw-r--r--net/udp/udp_socket_win.cc18
2 files changed, 20 insertions, 69 deletions
diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc
index 15a149b96..0396ea9 100644
--- a/net/udp/udp_socket_libevent.cc
+++ b/net/udp/udp_socket_libevent.cc
@@ -29,55 +29,6 @@
namespace net {
-namespace {
-
-// 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 EMSGSIZE:
- return ERR_MSG_TOO_BIG;
- case ENOTCONN:
- return ERR_SOCKET_NOT_CONNECTED;
- case 0:
- return OK;
- default:
- LOG(WARNING) << "Unknown error " << os_error
- << " mapped to net::ERR_FAILED";
- return ERR_FAILED;
- }
-}
-
-} // namespace
-
-//-----------------------------------------------------------------------------
-
UDPSocketLibevent::UDPSocketLibevent(net::NetLog* net_log,
const net::NetLog::Source& source)
: socket_(kInvalidSocket),
@@ -138,7 +89,7 @@ int UDPSocketLibevent::GetPeerAddress(IPEndPoint* address) const {
socklen_t addr_len = sizeof(addr_storage);
struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage);
if (getpeername(socket_, addr, &addr_len))
- return MapPosixError(errno);
+ return MapSystemError(errno);
scoped_ptr<IPEndPoint> address(new IPEndPoint());
if (!address->FromSockAddr(addr, addr_len))
return ERR_FAILED;
@@ -160,7 +111,7 @@ int UDPSocketLibevent::GetLocalAddress(IPEndPoint* address) const {
socklen_t addr_len = sizeof(addr_storage);
struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage);
if (getsockname(socket_, addr, &addr_len))
- return MapPosixError(errno);
+ return MapSystemError(errno);
scoped_ptr<IPEndPoint> address(new IPEndPoint());
if (!address->FromSockAddr(addr, addr_len))
return ERR_FAILED;
@@ -188,7 +139,7 @@ int UDPSocketLibevent::Read(IOBuffer* buf,
socket_, true, MessageLoopForIO::WATCH_READ,
&read_socket_watcher_, &read_watcher_)) {
PLOG(ERROR) << "WatchFileDescriptor failed on read";
- return MapPosixError(errno);
+ return MapSystemError(errno);
}
read_buf_ = buf;
@@ -230,13 +181,13 @@ int UDPSocketLibevent::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;
@@ -260,7 +211,7 @@ int UDPSocketLibevent::Connect(const IPEndPoint& address) {
rv = HANDLE_EINTR(connect(socket_, addr, addr_len));
if (rv < 0)
- return MapPosixError(errno);
+ return MapSystemError(errno);
remote_address_.reset(new IPEndPoint(address));
return rv;
@@ -281,7 +232,7 @@ int UDPSocketLibevent::Bind(const IPEndPoint& address) {
rv = bind(socket_, addr, addr_len);
if (rv < 0)
- return MapPosixError(errno);
+ return MapSystemError(errno);
local_address_.reset(new IPEndPoint(address));
return rv;
@@ -323,9 +274,9 @@ void UDPSocketLibevent::DidCompleteRead() {
int UDPSocketLibevent::CreateSocket(const IPEndPoint& address) {
socket_ = socket(address.GetFamily(), SOCK_DGRAM, 0);
if (socket_ == kInvalidSocket)
- return MapPosixError(errno);
+ return MapSystemError(errno);
if (SetNonBlocking(socket_)) {
- const int err = MapPosixError(errno);
+ const int err = MapSystemError(errno);
Close();
return err;
}
@@ -338,7 +289,7 @@ void UDPSocketLibevent::DidCompleteWrite() {
static base::StatsCounter write_bytes("udp.write_bytes");
write_bytes.Add(result);
} else {
- result = MapPosixError(errno);
+ result = MapSystemError(errno);
}
if (result != ERR_IO_PENDING) {
@@ -374,7 +325,7 @@ int UDPSocketLibevent::InternalRead(IOBuffer* buf, int buf_len) {
result = ERR_FAILED;
}
} else {
- result = MapPosixError(errno);
+ result = MapSystemError(errno);
}
return result;
}
diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc
index a7af53e..a34fb0c 100644
--- a/net/udp/udp_socket_win.cc
+++ b/net/udp/udp_socket_win.cc
@@ -86,7 +86,7 @@ int UDPSocketWin::GetPeerAddress(IPEndPoint* address) const {
int addr_len = sizeof(addr_storage);
struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage);
if (getpeername(socket_, addr, &addr_len))
- return MapWinsockError(WSAGetLastError());
+ return MapSystemError(WSAGetLastError());
scoped_ptr<IPEndPoint> address(new IPEndPoint());
if (!address->FromSockAddr(addr, addr_len))
return ERR_FAILED;
@@ -108,7 +108,7 @@ int UDPSocketWin::GetLocalAddress(IPEndPoint* address) const {
socklen_t addr_len = sizeof(addr_storage);
struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage);
if (getsockname(socket_, addr, &addr_len))
- return MapWinsockError(WSAGetLastError());
+ return MapSystemError(WSAGetLastError());
scoped_ptr<IPEndPoint> address(new IPEndPoint());
if (!address->FromSockAddr(addr, addr_len))
return ERR_FAILED;
@@ -187,7 +187,7 @@ int UDPSocketWin::Connect(const IPEndPoint& address) {
rv = connect(socket_, addr, addr_len);
if (rv < 0)
- return MapWinsockError(WSAGetLastError());
+ return MapSystemError(WSAGetLastError());
remote_address_.reset(new IPEndPoint(address));
return rv;
@@ -208,7 +208,7 @@ int UDPSocketWin::Bind(const IPEndPoint& address) {
rv = bind(socket_, addr, addr_len);
if (rv < 0)
- return MapWinsockError(WSAGetLastError());
+ return MapSystemError(WSAGetLastError());
local_address_.reset(new IPEndPoint(address));
return rv;
@@ -218,7 +218,7 @@ int UDPSocketWin::CreateSocket(const IPEndPoint& address) {
socket_ = WSASocket(address.GetFamily(), SOCK_DGRAM, IPPROTO_UDP, NULL, 0,
WSA_FLAG_OVERLAPPED);
if (socket_ == INVALID_SOCKET)
- return MapWinsockError(WSAGetLastError());
+ return MapSystemError(WSAGetLastError());
return OK;
}
@@ -249,7 +249,7 @@ void UDPSocketWin::DidCompleteRead() {
BOOL ok = WSAGetOverlappedResult(socket_, &read_overlapped_,
&num_bytes, FALSE, &flags);
WSAResetEvent(read_overlapped_.hEvent);
- int result = ok ? num_bytes : MapWinsockError(WSAGetLastError());
+ int result = ok ? num_bytes : MapSystemError(WSAGetLastError());
if (ok) {
if (!ProcessSuccessfulRead(num_bytes))
result = ERR_FAILED;
@@ -278,7 +278,7 @@ void UDPSocketWin::DidCompleteWrite() {
BOOL ok = WSAGetOverlappedResult(socket_, &write_overlapped_,
&num_bytes, FALSE, &flags);
WSAResetEvent(write_overlapped_.hEvent);
- int result = ok ? num_bytes : MapWinsockError(WSAGetLastError());
+ int result = ok ? num_bytes : MapSystemError(WSAGetLastError());
if (ok)
ProcessSuccessfulWrite(num_bytes);
write_iobuffer_ = NULL;
@@ -320,7 +320,7 @@ int UDPSocketWin::InternalRead(IOBuffer* buf, int buf_len) {
} else {
int os_error = WSAGetLastError();
if (os_error != WSA_IO_PENDING)
- return MapWinsockError(os_error);
+ return MapSystemError(os_error);
}
read_watcher_.StartWatching(read_overlapped_.hEvent, &read_delegate_);
return ERR_IO_PENDING;
@@ -357,7 +357,7 @@ int UDPSocketWin::InternalWrite(IOBuffer* buf, int buf_len) {
} else {
int os_error = WSAGetLastError();
if (os_error != WSA_IO_PENDING)
- return MapWinsockError(os_error);
+ return MapSystemError(os_error);
}
write_watcher_.StartWatching(write_overlapped_.hEvent, &write_delegate_);