| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); | 60 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); |
| 61 struct sockaddr_in socket_address; | 61 struct sockaddr_in socket_address; |
| 62 socklen_t size = sizeof(socket_address); | 62 socklen_t size = sizeof(socket_address); |
| 63 if (getpeername(socket_handle->socket(), | 63 if (getpeername(socket_handle->socket(), |
| 64 reinterpret_cast<struct sockaddr *>(&socket_address), | 64 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 65 &size)) { | 65 &size)) { |
| 66 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); | 66 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 if (inet_ntop(socket_address.sin_family, | 69 if (inet_ntop(socket_address.sin_family, |
| 70 reinterpret_cast<const void *>(&socket_address.sin_addr), | 70 reinterpret_cast<void *>(&socket_address.sin_addr), |
| 71 host, | 71 host, |
| 72 INET_ADDRSTRLEN) == NULL) { | 72 INET_ADDRSTRLEN) == NULL) { |
| 73 fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno)); | 73 fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno)); |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 *port = ntohs(socket_address.sin_port); | 76 *port = ntohs(socket_address.sin_port); |
| 77 return true; | 77 return true; |
| 78 | 78 } |
| 79 | 79 |
| 80 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { | 80 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { |
| 81 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); | 81 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); |
| 82 if (s == INVALID_SOCKET) { | 82 if (s == INVALID_SOCKET) { |
| 83 return -1; | 83 return -1; |
| 84 } | 84 } |
| 85 | 85 |
| 86 linger l; | 86 linger l; |
| 87 l.l_onoff = 1; | 87 l.l_onoff = 1; |
| 88 l.l_linger = 10; | 88 l.l_linger = 10; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (status == SOCKET_ERROR) { | 243 if (status == SOCKET_ERROR) { |
| 244 DWORD rc = WSAGetLastError(); | 244 DWORD rc = WSAGetLastError(); |
| 245 closesocket(s); | 245 closesocket(s); |
| 246 SetLastError(rc); | 246 SetLastError(rc); |
| 247 return -1; | 247 return -1; |
| 248 } | 248 } |
| 249 | 249 |
| 250 ListenSocket* listen_socket = new ListenSocket(s); | 250 ListenSocket* listen_socket = new ListenSocket(s); |
| 251 return reinterpret_cast<intptr_t>(listen_socket); | 251 return reinterpret_cast<intptr_t>(listen_socket); |
| 252 } | 252 } |
| OLD | NEW |