daemon: make TCP default if not HAVE_UNIX_SOCKETS

This commit is contained in:
Matthias Ringwald 2018-08-14 21:13:53 +02:00
parent 33845bfee4
commit 42963ecee0
2 changed files with 19 additions and 0 deletions

View File

@ -87,6 +87,16 @@ static int socket_packet_handler(connection_t *connection, uint16_t packet_type,
// init BTstack library // init BTstack library
int bt_open(void){ int bt_open(void){
#ifndef HAVE_UNIX_SOCKETS
// without unix sockets, default to TCP
if (!daemon_tcp_address){
daemon_tcp_address = "127.0.0.1";
}
if (!daemon_tcp_port){
daemon_tcp_port = BTSTACK_PORT;
}
#endif
socket_connection_init(); socket_connection_init();
socket_connection_register_packet_callback(socket_packet_handler); socket_connection_register_packet_callback(socket_packet_handler);
@ -95,7 +105,9 @@ int bt_open(void){
if (daemon_tcp_address) { if (daemon_tcp_address) {
btstack_connection = socket_connection_open_tcp(daemon_tcp_address,daemon_tcp_port); btstack_connection = socket_connection_open_tcp(daemon_tcp_address,daemon_tcp_port);
} else { } else {
#ifdef HAVE_UNIX_SOCKETS
btstack_connection = socket_connection_open_unix(); btstack_connection = socket_connection_open_unix();
#endif
} }
if (!btstack_connection) return -1; if (!btstack_connection) return -1;

View File

@ -1955,6 +1955,11 @@ int main (int argc, char * const * argv){
} }
} }
#ifndef HAVE_UNIX_SOCKETS
// TCP is default if there are no unix sockets
tcp_flag = 1;
#endif
if (tcp_flag){ if (tcp_flag){
printf("BTstack Daemon started on port %u\n", BTSTACK_PORT); printf("BTstack Daemon started on port %u\n", BTSTACK_PORT);
} else { } else {
@ -2096,7 +2101,9 @@ int main (int argc, char * const * argv){
if (tcp_flag) { if (tcp_flag) {
socket_connection_create_tcp(BTSTACK_PORT); socket_connection_create_tcp(BTSTACK_PORT);
} else { } else {
#ifdef HAVE_UNIX_SOCKETS
socket_connection_create_unix(BTSTACK_UNIX); socket_connection_create_unix(BTSTACK_UNIX);
#endif
} }
#endif #endif
socket_connection_register_packet_callback(&daemon_client_handler); socket_connection_register_packet_callback(&daemon_client_handler);