| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <winsock2.h> | 5 #include <winsock2.h> |
| 6 #include <ws2tcpip.h> | 6 #include <ws2tcpip.h> |
| 7 #include <mswsock.h> | 7 #include <mswsock.h> |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (getsockname(socket_handle->socket(), | 47 if (getsockname(socket_handle->socket(), |
| 48 reinterpret_cast<struct sockaddr *>(&socket_address), | 48 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 49 &size)) { | 49 &size)) { |
| 50 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 50 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| 51 return 0; | 51 return 0; |
| 52 } | 52 } |
| 53 return ntohs(socket_address.sin_port); | 53 return ntohs(socket_address.sin_port); |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 intptr_t Socket::GetRemotePort(intptr_t fd) { |
| 58 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); |
| 59 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); |
| 60 struct sockaddr_in socket_address; |
| 61 socklen_t size = sizeof(socket_address); |
| 62 if (getpeername(socket_handle->socket(), |
| 63 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 64 &size)) { |
| 65 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
| 66 return 0; |
| 67 } |
| 68 return ntohs(socket_address.sin_port); |
| 69 } |
| 70 |
| 71 |
| 57 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { | 72 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { |
| 58 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); | 73 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); |
| 59 if (s == INVALID_SOCKET) { | 74 if (s == INVALID_SOCKET) { |
| 60 return -1; | 75 return -1; |
| 61 } | 76 } |
| 62 | 77 |
| 63 linger l; | 78 linger l; |
| 64 l.l_onoff = 1; | 79 l.l_onoff = 1; |
| 65 l.l_linger = 10; | 80 l.l_linger = 10; |
| 66 int status = setsockopt(s, | 81 int status = setsockopt(s, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (status == SOCKET_ERROR) { | 235 if (status == SOCKET_ERROR) { |
| 221 DWORD rc = WSAGetLastError(); | 236 DWORD rc = WSAGetLastError(); |
| 222 closesocket(s); | 237 closesocket(s); |
| 223 SetLastError(rc); | 238 SetLastError(rc); |
| 224 return -1; | 239 return -1; |
| 225 } | 240 } |
| 226 | 241 |
| 227 ListenSocket* listen_socket = new ListenSocket(s); | 242 ListenSocket* listen_socket = new ListenSocket(s); |
| 228 return reinterpret_cast<intptr_t>(listen_socket); | 243 return reinterpret_cast<intptr_t>(listen_socket); |
| 229 } | 244 } |
| OLD | NEW |