| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 10 matching lines...) Expand all Loading... |
| 21 return err == 0; | 21 return err == 0; |
| 22 } | 22 } |
| 23 | 23 |
| 24 intptr_t Socket::Available(intptr_t fd) { | 24 intptr_t Socket::Available(intptr_t fd) { |
| 25 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); | 25 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); |
| 26 return client_socket->Available(); | 26 return client_socket->Available(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 30 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 31 ASSERT(reinterpret_cast<Handle*>(fd)->is_client_socket()); | 31 Handle* handle = reinterpret_cast<Handle*>(fd); |
| 32 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); | 32 return handle->Read(buffer, num_bytes); |
| 33 return client_socket->Read(buffer, num_bytes); | |
| 34 } | 33 } |
| 35 | 34 |
| 36 | 35 |
| 37 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 36 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
| 38 ASSERT(reinterpret_cast<Handle*>(fd)->is_client_socket()); | 37 Handle* handle = reinterpret_cast<Handle*>(fd); |
| 39 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); | 38 return handle->Write(buffer, num_bytes); |
| 40 return client_socket->Write(buffer, num_bytes); | |
| 41 } | 39 } |
| 42 | 40 |
| 43 | 41 |
| 44 intptr_t Socket::GetPort(intptr_t fd) { | 42 intptr_t Socket::GetPort(intptr_t fd) { |
| 45 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); | 43 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); |
| 46 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); | 44 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); |
| 47 struct sockaddr_in socket_address; | 45 struct sockaddr_in socket_address; |
| 48 socklen_t size = sizeof(socket_address); | 46 socklen_t size = sizeof(socket_address); |
| 49 if (getsockname(socket_handle->socket(), | 47 if (getsockname(socket_handle->socket(), |
| 50 reinterpret_cast<struct sockaddr *>(&socket_address), | 48 reinterpret_cast<struct sockaddr *>(&socket_address), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 status = listen(s, backlog); | 136 status = listen(s, backlog); |
| 139 if (status == SOCKET_ERROR) { | 137 if (status == SOCKET_ERROR) { |
| 140 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError()); | 138 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError()); |
| 141 closesocket(s); | 139 closesocket(s); |
| 142 return -1; | 140 return -1; |
| 143 } | 141 } |
| 144 | 142 |
| 145 ListenSocket* listen_socket = new ListenSocket(s); | 143 ListenSocket* listen_socket = new ListenSocket(s); |
| 146 return reinterpret_cast<intptr_t>(listen_socket); | 144 return reinterpret_cast<intptr_t>(listen_socket); |
| 147 } | 145 } |
| OLD | NEW |