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

Unified Diff: runtime/bin/socket_linux.cc

Issue 13856013: Try to avoid GCC strict-aliasing error (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 1672ab9787b913666a8c5a9b5ad4d9c7e7895109..fb0cd41c8c9b252172015df2fd3118f367cabe68 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -19,20 +19,22 @@
#include "bin/socket.h"
-#define SOCKADDR_STORAGE_SET_PORT(addr, port) \
- if (addr.ss_family == AF_INET) { \
- reinterpret_cast<struct sockaddr_in*>(&addr)->sin_port = htons(port); \
- } else { \
- reinterpret_cast<struct sockaddr_in6*>(&addr)->sin6_port = htons(port); \
- }
-
-
#define SOCKADDR_STORAGE_GET_PORT(addr) \
addr.ss_family == AF_INET ? \
ntohs(reinterpret_cast<struct sockaddr_in*>(&addr)->sin_port) : \
ntohs(reinterpret_cast<struct sockaddr_in6*>(&addr)->sin6_port)
+static void SetPort(sockaddr_storage* addr, int port) {
+ char* ptr = reinterpret_cast<char*>(addr);
+ if (addr->ss_family == AF_INET) {
+ reinterpret_cast<struct sockaddr_in*>(ptr)->sin_port = htons(port);
+ } else { \
+ reinterpret_cast<struct sockaddr_in6*>(ptr)->sin6_port = htons(port);
+ }
+}
+
+
SocketAddress::SocketAddress(struct addrinfo* addrinfo) {
ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(addrinfo->ai_addr);
@@ -65,7 +67,7 @@ intptr_t Socket::CreateConnect(sockaddr_storage addr, const intptr_t port) {
FDUtils::SetCloseOnExec(fd);
Socket::SetNonBlocking(fd);
- SOCKADDR_STORAGE_SET_PORT(addr, port);
+ SetPort(&addr, port);
intptr_t result = TEMP_FAILURE_RETRY(
connect(fd,
reinterpret_cast<struct sockaddr*>(&addr),
@@ -240,7 +242,7 @@ intptr_t ServerSocket::CreateBindListen(sockaddr_storage addr,
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)));
}
- SOCKADDR_STORAGE_SET_PORT(addr, port);
+ SetPort(&addr, port);
if (TEMP_FAILURE_RETRY(
bind(fd,
reinterpret_cast<struct sockaddr*>(&addr),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698