| 30 | } |
| 31 | |
| 32 | int SocketBluetooth::connect () |
| 33 | { |
| 34 | WSADATA wsadata; |
| 35 | int res = WSAStartup (MAKEWORD (2, 2), &wsadata); |
| 36 | if (res != 0) |
| 37 | { |
| 38 | return (int)SocketBluetoothReturnCodes::CONNECT_ERROR; |
| 39 | } |
| 40 | |
| 41 | int status = SOCKET_ERROR; |
| 42 | socket_bt = socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); |
| 43 | if (socket_bt == INVALID_SOCKET) |
| 44 | { |
| 45 | return (int)SocketBluetoothReturnCodes::CONNECT_ERROR; |
| 46 | } |
| 47 | SOCKADDR_BTH addr = {0}; |
| 48 | int addr_size = sizeof (SOCKADDR_BTH); |
| 49 | char mac_addr_c[40]; |
| 50 | strncpy (mac_addr_c, mac_addr.c_str (), 40); |
| 51 | status = WSAStringToAddress (mac_addr_c, AF_BTH, NULL, (LPSOCKADDR)&addr, &addr_size); |
| 52 | if (status == SOCKET_ERROR) |
| 53 | { |
| 54 | close (); |
| 55 | return (int)SocketBluetoothReturnCodes::CONNECT_ERROR; |
| 56 | } |
| 57 | addr.port = this->port; |
| 58 | |
| 59 | status = ::connect (socket_bt, (LPSOCKADDR)&addr, addr_size); |
| 60 | if (status == SOCKET_ERROR) |
| 61 | { |
| 62 | close (); |
| 63 | return (int)SocketBluetoothReturnCodes::CONNECT_ERROR; |
| 64 | } |
| 65 | unsigned long enable_non_blocking = 1; |
| 66 | status = ioctlsocket (socket_bt, FIONBIO, &enable_non_blocking); |
| 67 | |
| 68 | if (status == SOCKET_ERROR) |
| 69 | { |
| 70 | close (); |
| 71 | return (int)SocketBluetoothReturnCodes::CONNECT_ERROR; |
| 72 | } |
| 73 | return (int)SocketBluetoothReturnCodes::STATUS_OK; |
| 74 | } |
| 75 | |
| 76 | int SocketBluetooth::send (const char *data, int size) |
| 77 | { |
no outgoing calls
no test coverage detected