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

Side by Side Diff: runtime/bin/socket.h

Issue 14217013: Attempt to fix strict align issue. (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 #ifndef BIN_SOCKET_H_ 5 #ifndef BIN_SOCKET_H_
6 #define BIN_SOCKET_H_ 6 #define BIN_SOCKET_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 static int16_t FromType(int type) { 49 static int16_t FromType(int type) {
50 if (type == TYPE_ANY) return AF_UNSPEC; 50 if (type == TYPE_ANY) return AF_UNSPEC;
51 if (type == TYPE_IPV4) return AF_INET; 51 if (type == TYPE_IPV4) return AF_INET;
52 ASSERT(type == TYPE_IPV6 && "Invalid type"); 52 ASSERT(type == TYPE_IPV6 && "Invalid type");
53 return AF_INET6; 53 return AF_INET6;
54 } 54 }
55 55
56 static void SetAddrPort(struct sockaddr_storage* addr, intptr_t port) { 56 static void SetAddrPort(struct sockaddr_storage* addr, intptr_t port) {
57 sock_addr_ sock_addr; 57 if (addr->ss_family == AF_INET) {
58 sock_addr.storage = addr; 58 GetAsSockAddrIn(GetAsSockAddr(addr))->sin_port = htons(port);
59 if (sock_addr.storage->ss_family == AF_INET) {
60 sock_addr.in->sin_port = htons(port);
61 } else { 59 } else {
62 sock_addr.in6->sin6_port = htons(port); 60 GetAsSockAddrIn6(GetAsSockAddr(addr))->sin6_port = htons(port);
63 } 61 }
64 } 62 }
65 63
66 static intptr_t GetAddrPort(struct sockaddr_storage* addr) { 64 static intptr_t GetAddrPort(struct sockaddr_storage* addr) {
67 sock_addr_ sock_addr; 65 if (addr->ss_family == AF_INET) {
68 sock_addr.storage = addr; 66 return ntohs(GetAsSockAddrIn(GetAsSockAddr(addr))->sin_port);
69 if (sock_addr.storage->ss_family == AF_INET) {
70 return ntohs(sock_addr.in->sin_port);
71 } else { 67 } else {
72 return ntohs(sock_addr.in6->sin6_port); 68 return ntohs(GetAsSockAddrIn6(GetAsSockAddr(addr))->sin6_port);
73 } 69 }
74 } 70 }
75 71
76 static struct sockaddr* GetAsSockAddr(struct sockaddr_storage* addr) { 72 static struct sockaddr* GetAsSockAddr(struct sockaddr_storage* addr) {
77 sock_addr_ sock_addr; 73 uint8_t* data = reinterpret_cast<uint8_t*>(addr);
78 sock_addr.storage = addr; 74 return reinterpret_cast<struct sockaddr*>(data);
79 return sock_addr.addr;
80 } 75 }
81 76
82 static struct sockaddr_in* GetAsSockAddrIn(struct sockaddr* addr) { 77 static struct sockaddr_in* GetAsSockAddrIn(struct sockaddr* addr) {
83 sock_addr_ sock_addr; 78 uint8_t* data = reinterpret_cast<uint8_t*>(addr);
84 sock_addr.addr = addr; 79 return reinterpret_cast<struct sockaddr_in*>(data);
85 return sock_addr.in;
86 } 80 }
87 81
88 static struct sockaddr_in6* GetAsSockAddrIn6(struct sockaddr* addr) { 82 static struct sockaddr_in6* GetAsSockAddrIn6(struct sockaddr* addr) {
89 sock_addr_ sock_addr; 83 uint8_t* data = reinterpret_cast<uint8_t*>(addr);
90 sock_addr.addr = addr; 84 return reinterpret_cast<struct sockaddr_in6*>(data);
91 return sock_addr.in6;
92 } 85 }
93 86
94 private: 87 private:
95 union sock_addr_ { 88 union sock_addr_ {
96 struct sockaddr_storage* storage; 89 struct sockaddr_storage* storage;
97 struct sockaddr_in* in; 90 struct sockaddr_in* in;
98 struct sockaddr_in6* in6; 91 struct sockaddr_in6* in6;
99 struct sockaddr* addr; 92 struct sockaddr* addr;
100 }; 93 };
101 94
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // -5: invalid bindAddress 178 // -5: invalid bindAddress
186 static intptr_t CreateBindListen(sockaddr_storage addr, 179 static intptr_t CreateBindListen(sockaddr_storage addr,
187 intptr_t port, 180 intptr_t port,
188 intptr_t backlog); 181 intptr_t backlog);
189 182
190 DISALLOW_ALLOCATION(); 183 DISALLOW_ALLOCATION();
191 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket); 184 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket);
192 }; 185 };
193 186
194 #endif // BIN_SOCKET_H_ 187 #endif // BIN_SOCKET_H_
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