OLD | NEW |
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 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 int GetType() { | 59 int GetType() { |
60 if (addr_.ss.ss_family == AF_INET6) return TYPE_IPV6; | 60 if (addr_.ss.ss_family == AF_INET6) return TYPE_IPV6; |
61 return TYPE_IPV4; | 61 return TYPE_IPV4; |
62 } | 62 } |
63 | 63 |
64 const char* as_string() const { return as_string_; } | 64 const char* as_string() const { return as_string_; } |
65 const RawAddr& addr() const { return addr_; } | 65 const RawAddr& addr() const { return addr_; } |
66 | 66 |
67 static intptr_t GetAddrLength(const RawAddr* addr) { | 67 static intptr_t GetAddrLength(const RawAddr* addr) { |
| 68 ASSERT(addr->ss.ss_family == AF_INET || addr->ss.ss_family == AF_INET6); |
68 return addr->ss.ss_family == AF_INET6 ? | 69 return addr->ss.ss_family == AF_INET6 ? |
69 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); | 70 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); |
70 } | 71 } |
71 | 72 |
72 static int16_t FromType(int type) { | 73 static int16_t FromType(int type) { |
73 if (type == TYPE_ANY) return AF_UNSPEC; | 74 if (type == TYPE_ANY) return AF_UNSPEC; |
74 if (type == TYPE_IPV4) return AF_INET; | 75 if (type == TYPE_IPV4) return AF_INET; |
75 ASSERT(type == TYPE_IPV6 && "Invalid type"); | 76 ASSERT(type == TYPE_IPV6 && "Invalid type"); |
76 return AF_INET6; | 77 return AF_INET6; |
77 } | 78 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 enum SocketRequest { | 164 enum SocketRequest { |
164 kLookupRequest = 0, | 165 kLookupRequest = 0, |
165 kListInterfacesRequest = 1, | 166 kListInterfacesRequest = 1, |
166 kReverseLookupRequest = 2, | 167 kReverseLookupRequest = 2, |
167 }; | 168 }; |
168 | 169 |
169 static bool Initialize(); | 170 static bool Initialize(); |
170 static intptr_t Available(intptr_t fd); | 171 static intptr_t Available(intptr_t fd); |
171 static int Read(intptr_t fd, void* buffer, intptr_t num_bytes); | 172 static int Read(intptr_t fd, void* buffer, intptr_t num_bytes); |
172 static int Write(intptr_t fd, const void* buffer, intptr_t num_bytes); | 173 static int Write(intptr_t fd, const void* buffer, intptr_t num_bytes); |
| 174 static int SendTo( |
| 175 intptr_t fd, const void* buffer, intptr_t num_bytes, RawAddr addr); |
| 176 static int RecvFrom( |
| 177 intptr_t fd, void* buffer, intptr_t num_bytes, RawAddr* addr); |
173 static intptr_t Create(RawAddr addr); | 178 static intptr_t Create(RawAddr addr); |
174 static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port); | 179 static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port); |
175 static intptr_t CreateConnect(RawAddr addr, | 180 static intptr_t CreateConnect(RawAddr addr, |
176 const intptr_t port); | 181 const intptr_t port); |
| 182 static intptr_t CreateBindDatagram( |
| 183 RawAddr* addr, intptr_t port, bool reuseAddress); |
177 static intptr_t GetPort(intptr_t fd); | 184 static intptr_t GetPort(intptr_t fd); |
178 static SocketAddress* GetRemotePeer(intptr_t fd, intptr_t* port); | 185 static SocketAddress* GetRemotePeer(intptr_t fd, intptr_t* port); |
179 static void GetError(intptr_t fd, OSError* os_error); | 186 static void GetError(intptr_t fd, OSError* os_error); |
180 static int GetType(intptr_t fd); | 187 static int GetType(intptr_t fd); |
181 static intptr_t GetStdioHandle(intptr_t num); | 188 static intptr_t GetStdioHandle(intptr_t num); |
182 static void Close(intptr_t fd); | 189 static void Close(intptr_t fd); |
183 static bool SetNonBlocking(intptr_t fd); | 190 static bool SetNonBlocking(intptr_t fd); |
184 static bool SetBlocking(intptr_t fd); | 191 static bool SetBlocking(intptr_t fd); |
| 192 static bool GetNoDelay(intptr_t fd, bool* enabled); |
185 static bool SetNoDelay(intptr_t fd, bool enabled); | 193 static bool SetNoDelay(intptr_t fd, bool enabled); |
| 194 static bool GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled); |
| 195 static bool SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled); |
| 196 static bool GetMulticastHops(intptr_t fd, intptr_t protocol, int* value); |
| 197 static bool SetMulticastHops(intptr_t fd, intptr_t protocol, int value); |
| 198 static bool GetBroadcast(intptr_t fd, bool* value); |
| 199 static bool SetBroadcast(intptr_t fd, bool value); |
| 200 static bool JoinMulticast( |
| 201 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex); |
| 202 static bool LeaveMulticast( |
| 203 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex); |
186 | 204 |
187 // Perform a hostname lookup. Returns a AddressList of SocketAddress's. | 205 // Perform a hostname lookup. Returns a AddressList of SocketAddress's. |
188 static AddressList<SocketAddress>* LookupAddress(const char* host, | 206 static AddressList<SocketAddress>* LookupAddress(const char* host, |
189 int type, | 207 int type, |
190 OSError** os_error); | 208 OSError** os_error); |
| 209 |
191 static bool ReverseLookup(RawAddr addr, | 210 static bool ReverseLookup(RawAddr addr, |
192 char* host, | 211 char* host, |
193 intptr_t host_len, | 212 intptr_t host_len, |
194 OSError** os_error); | 213 OSError** os_error); |
195 | 214 |
196 static bool ParseAddress(int type, const char* address, RawAddr* addr); | 215 static bool ParseAddress(int type, const char* address, RawAddr* addr); |
| 216 static bool FormatNumericAddress(RawAddr* addr, char* address, int len); |
197 | 217 |
198 // List interfaces. Returns a AddressList of InterfaceSocketAddress's. | 218 // List interfaces. Returns a AddressList of InterfaceSocketAddress's. |
199 static AddressList<InterfaceSocketAddress>* ListInterfaces( | 219 static AddressList<InterfaceSocketAddress>* ListInterfaces( |
200 int type, | 220 int type, |
201 OSError** os_error); | 221 OSError** os_error); |
202 | 222 |
203 static CObject* LookupRequest(const CObjectArray& request); | 223 static CObject* LookupRequest(const CObjectArray& request); |
204 static CObject* ListInterfacesRequest(const CObjectArray& request); | 224 static CObject* ListInterfacesRequest(const CObjectArray& request); |
205 static CObject* ReverseLookupRequest(const CObjectArray& request); | 225 static CObject* ReverseLookupRequest(const CObjectArray& request); |
206 | 226 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 258 |
239 private: | 259 private: |
240 DISALLOW_ALLOCATION(); | 260 DISALLOW_ALLOCATION(); |
241 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket); | 261 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket); |
242 }; | 262 }; |
243 | 263 |
244 } // namespace bin | 264 } // namespace bin |
245 } // namespace dart | 265 } // namespace dart |
246 | 266 |
247 #endif // BIN_SOCKET_H_ | 267 #endif // BIN_SOCKET_H_ |
OLD | NEW |