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

Side by Side Diff: runtime/bin/socket_linux.cc

Issue 14426004: Anoher 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 9 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 10 #include <stdlib.h> // NOLINT
11 #include <string.h> // NOLINT 11 #include <string.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 12 #include <sys/stat.h> // NOLINT
13 #include <unistd.h> // NOLINT 13 #include <unistd.h> // NOLINT
14 #include <netinet/tcp.h> // NOLINT 14 #include <netinet/tcp.h> // NOLINT
15 15
16 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/log.h" 18 #include "bin/log.h"
19 #include "bin/socket.h" 19 #include "bin/socket.h"
20 20
21 21
22 #define SOCKADDR_STORAGE_GET_PORT(addr) \ 22 #define SOCKADDR_STORAGE_GET_PORT(addr) \
23 addr.ss_family == AF_INET ? \ 23 addr.ss_family == AF_INET ? \
24 ntohs(reinterpret_cast<struct sockaddr_in*>(&addr)->sin_port) : \ 24 ntohs(reinterpret_cast<struct sockaddr_in*>(&addr)->sin_port) : \
25 ntohs(reinterpret_cast<struct sockaddr_in6*>(&addr)->sin6_port) 25 ntohs(reinterpret_cast<struct sockaddr_in6*>(&addr)->sin6_port)
26 26
27 27
28 typedef union {
29 struct sockaddr sa;
30 struct sockaddr_in sa_in;
31 struct sockaddr_in6 sa_in6;
32 struct sockaddr_storage sa_stor;
33 } address;
34
35
28 static void SetPort(sockaddr_storage* addr, int port) { 36 static void SetPort(sockaddr_storage* addr, int port) {
29 char* ptr = reinterpret_cast<char*>(addr); 37 address* ptr = reinterpret_cast<address*>(addr);
30 if (addr->ss_family == AF_INET) { 38 if (ptr->sa_stor.ss_family == AF_INET) {
31 reinterpret_cast<struct sockaddr_in*>(ptr)->sin_port = htons(port); 39 ptr->sa_in.sin_port = htons(port);
32 } else { \ 40 } else { \
33 reinterpret_cast<struct sockaddr_in6*>(ptr)->sin6_port = htons(port); 41 ptr->sa_in6.sin6_port = htons(port);
34 } 42 }
35 } 43 }
36 44
37 45
38 SocketAddress::SocketAddress(struct addrinfo* addrinfo) { 46 SocketAddress::SocketAddress(struct addrinfo* addrinfo) {
39 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 47 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
40 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(addrinfo->ai_addr); 48 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(addrinfo->ai_addr);
41 const char* result = inet_ntop(addrinfo->ai_family, 49 const char* result = inet_ntop(addrinfo->ai_family,
42 &sockaddr->sin_addr, 50 &sockaddr->sin_addr,
43 as_string_, 51 as_string_,
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 bool Socket::SetNoDelay(intptr_t fd, bool enabled) { 324 bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
317 int on = enabled ? 1 : 0; 325 int on = enabled ? 1 : 0;
318 return TEMP_FAILURE_RETRY(setsockopt(fd, 326 return TEMP_FAILURE_RETRY(setsockopt(fd,
319 SOL_TCP, 327 SOL_TCP,
320 TCP_NODELAY, 328 TCP_NODELAY,
321 reinterpret_cast<char *>(&on), 329 reinterpret_cast<char *>(&on),
322 sizeof(on))) == 0; 330 sizeof(on))) == 0;
323 } 331 }
324 332
325 #endif // defined(TARGET_OS_LINUX) 333 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« 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