| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (!supports_rfcomm_) { | 189 if (!supports_rfcomm_) { |
| 190 // TODO(youngki) add support for L2CAP sockets as well. | 190 // TODO(youngki) add support for L2CAP sockets as well. |
| 191 error_callback.Run(kL2CAPNotSupported); | 191 error_callback.Run(kL2CAPNotSupported); |
| 192 return; | 192 return; |
| 193 } | 193 } |
| 194 | 194 |
| 195 scoped_ptr<net::TCPSocket> scoped_socket( | 195 scoped_ptr<net::TCPSocket> scoped_socket( |
| 196 new net::TCPSocket(NULL, net::NetLog::Source())); | 196 new net::TCPSocket(NULL, NULL, net::NetLog::Source())); |
| 197 net::EnsureWinsockInit(); | 197 net::EnsureWinsockInit(); |
| 198 SOCKET socket_fd = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); | 198 SOCKET socket_fd = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); |
| 199 SOCKADDR_BTH sa; | 199 SOCKADDR_BTH sa; |
| 200 ZeroMemory(&sa, sizeof(sa)); | 200 ZeroMemory(&sa, sizeof(sa)); |
| 201 sa.addressFamily = AF_BTH; | 201 sa.addressFamily = AF_BTH; |
| 202 sa.port = rfcomm_channel_; | 202 sa.port = rfcomm_channel_; |
| 203 sa.btAddr = bth_addr_; | 203 sa.btAddr = bth_addr_; |
| 204 | 204 |
| 205 // TODO(rpaquay): Condider making this call non-blocking. | 205 // TODO(rpaquay): Condider making this call non-blocking. |
| 206 int status = connect(socket_fd, reinterpret_cast<SOCKADDR*>(&sa), sizeof(sa)); | 206 int status = connect(socket_fd, reinterpret_cast<SOCKADDR*>(&sa), sizeof(sa)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 LOG(WARNING) << "Failed to start service: create socket, " | 253 LOG(WARNING) << "Failed to start service: create socket, " |
| 254 << "winsock err=" << WSAGetLastError(); | 254 << "winsock err=" << WSAGetLastError(); |
| 255 PostErrorCompletion(error_callback, kFailedToCreateSocket); | 255 PostErrorCompletion(error_callback, kFailedToCreateSocket); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Note that |socket_fd| belongs to a non-TCP address family (i.e. AF_BTH), | 259 // Note that |socket_fd| belongs to a non-TCP address family (i.e. AF_BTH), |
| 260 // TCPSocket methods that involve address could not be called. So bind() | 260 // TCPSocket methods that involve address could not be called. So bind() |
| 261 // is called on |socket_fd| directly. | 261 // is called on |socket_fd| directly. |
| 262 scoped_ptr<net::TCPSocket> scoped_socket( | 262 scoped_ptr<net::TCPSocket> scoped_socket( |
| 263 new net::TCPSocket(NULL, net::NetLog::Source())); | 263 new net::TCPSocket(NULL, NULL, net::NetLog::Source())); |
| 264 scoped_socket->AdoptListenSocket(socket_fd); | 264 scoped_socket->AdoptListenSocket(socket_fd); |
| 265 | 265 |
| 266 SOCKADDR_BTH sa; | 266 SOCKADDR_BTH sa; |
| 267 struct sockaddr* sock_addr = reinterpret_cast<struct sockaddr*>(&sa); | 267 struct sockaddr* sock_addr = reinterpret_cast<struct sockaddr*>(&sa); |
| 268 int sock_addr_len = sizeof(sa); | 268 int sock_addr_len = sizeof(sa); |
| 269 ZeroMemory(&sa, sock_addr_len); | 269 ZeroMemory(&sa, sock_addr_len); |
| 270 sa.addressFamily = AF_BTH; | 270 sa.addressFamily = AF_BTH; |
| 271 sa.port = rfcomm_channel ? rfcomm_channel : BT_PORT_ANY; | 271 sa.port = rfcomm_channel ? rfcomm_channel : BT_PORT_ANY; |
| 272 if (bind(socket_fd, sock_addr, sock_addr_len) < 0) { | 272 if (bind(socket_fd, sock_addr, sock_addr_len) < 0) { |
| 273 LOG(WARNING) << "Failed to start service: create socket, " | 273 LOG(WARNING) << "Failed to start service: create socket, " |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 return; | 387 return; |
| 388 } | 388 } |
| 389 | 389 |
| 390 scoped_refptr<BluetoothSocketWin> peer_socket = | 390 scoped_refptr<BluetoothSocketWin> peer_socket = |
| 391 CreateBluetoothSocket(ui_task_runner(), socket_thread()); | 391 CreateBluetoothSocket(ui_task_runner(), socket_thread()); |
| 392 peer_socket->SetTCPSocket(std::move(accept_socket)); | 392 peer_socket->SetTCPSocket(std::move(accept_socket)); |
| 393 success_callback.Run(peer_device, peer_socket); | 393 success_callback.Run(peer_device, peer_socket); |
| 394 } | 394 } |
| 395 | 395 |
| 396 } // namespace device | 396 } // namespace device |
| OLD | NEW |