| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_socket_win.h" | 5 #include "device/bluetooth/bluetooth_socket_win.h" |
| 6 | 6 |
| 7 #include <objbase.h> | 7 #include <objbase.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 | 189 |
| 190 if (!supports_rfcomm_) { | 190 if (!supports_rfcomm_) { |
| 191 // TODO(youngki) add support for L2CAP sockets as well. | 191 // TODO(youngki) add support for L2CAP sockets as well. |
| 192 error_callback.Run(kL2CAPNotSupported); | 192 error_callback.Run(kL2CAPNotSupported); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 | 195 |
| 196 std::unique_ptr<net::TCPSocket> scoped_socket( | 196 std::unique_ptr<net::TCPSocket> scoped_socket( |
| 197 new net::TCPSocket(NULL, net::NetLog::Source())); | 197 new net::TCPSocket(NULL, NULL, net::NetLog::Source())); |
| 198 net::EnsureWinsockInit(); | 198 net::EnsureWinsockInit(); |
| 199 SOCKET socket_fd = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); | 199 SOCKET socket_fd = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); |
| 200 SOCKADDR_BTH sa; | 200 SOCKADDR_BTH sa; |
| 201 ZeroMemory(&sa, sizeof(sa)); | 201 ZeroMemory(&sa, sizeof(sa)); |
| 202 sa.addressFamily = AF_BTH; | 202 sa.addressFamily = AF_BTH; |
| 203 sa.port = rfcomm_channel_; | 203 sa.port = rfcomm_channel_; |
| 204 sa.btAddr = bth_addr_; | 204 sa.btAddr = bth_addr_; |
| 205 | 205 |
| 206 // TODO(rpaquay): Condider making this call non-blocking. | 206 // TODO(rpaquay): Condider making this call non-blocking. |
| 207 int status = connect(socket_fd, reinterpret_cast<SOCKADDR*>(&sa), sizeof(sa)); | 207 int status = connect(socket_fd, reinterpret_cast<SOCKADDR*>(&sa), sizeof(sa)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 LOG(WARNING) << "Failed to start service: create socket, " | 254 LOG(WARNING) << "Failed to start service: create socket, " |
| 255 << "winsock err=" << WSAGetLastError(); | 255 << "winsock err=" << WSAGetLastError(); |
| 256 PostErrorCompletion(error_callback, kFailedToCreateSocket); | 256 PostErrorCompletion(error_callback, kFailedToCreateSocket); |
| 257 return; | 257 return; |
| 258 } | 258 } |
| 259 | 259 |
| 260 // Note that |socket_fd| belongs to a non-TCP address family (i.e. AF_BTH), | 260 // Note that |socket_fd| belongs to a non-TCP address family (i.e. AF_BTH), |
| 261 // TCPSocket methods that involve address could not be called. So bind() | 261 // TCPSocket methods that involve address could not be called. So bind() |
| 262 // is called on |socket_fd| directly. | 262 // is called on |socket_fd| directly. |
| 263 std::unique_ptr<net::TCPSocket> scoped_socket( | 263 std::unique_ptr<net::TCPSocket> scoped_socket( |
| 264 new net::TCPSocket(NULL, net::NetLog::Source())); | 264 new net::TCPSocket(NULL, NULL, net::NetLog::Source())); |
| 265 scoped_socket->AdoptListenSocket(socket_fd); | 265 scoped_socket->AdoptListenSocket(socket_fd); |
| 266 | 266 |
| 267 SOCKADDR_BTH sa; | 267 SOCKADDR_BTH sa; |
| 268 struct sockaddr* sock_addr = reinterpret_cast<struct sockaddr*>(&sa); | 268 struct sockaddr* sock_addr = reinterpret_cast<struct sockaddr*>(&sa); |
| 269 int sock_addr_len = sizeof(sa); | 269 int sock_addr_len = sizeof(sa); |
| 270 ZeroMemory(&sa, sock_addr_len); | 270 ZeroMemory(&sa, sock_addr_len); |
| 271 sa.addressFamily = AF_BTH; | 271 sa.addressFamily = AF_BTH; |
| 272 sa.port = rfcomm_channel ? rfcomm_channel : BT_PORT_ANY; | 272 sa.port = rfcomm_channel ? rfcomm_channel : BT_PORT_ANY; |
| 273 if (bind(socket_fd, sock_addr, sock_addr_len) < 0) { | 273 if (bind(socket_fd, sock_addr, sock_addr_len) < 0) { |
| 274 LOG(WARNING) << "Failed to start service: create socket, " | 274 LOG(WARNING) << "Failed to start service: create socket, " |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 | 390 |
| 391 scoped_refptr<BluetoothSocketWin> peer_socket = | 391 scoped_refptr<BluetoothSocketWin> peer_socket = |
| 392 CreateBluetoothSocket(ui_task_runner(), socket_thread()); | 392 CreateBluetoothSocket(ui_task_runner(), socket_thread()); |
| 393 peer_socket->SetTCPSocket(std::move(accept_socket)); | 393 peer_socket->SetTCPSocket(std::move(accept_socket)); |
| 394 success_callback.Run(peer_device, peer_socket); | 394 success_callback.Run(peer_device, peer_socket); |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace device | 397 } // namespace device |
| OLD | NEW |