diff --git a/TODO.txt b/TODO.txt index be418a824..c20be1a3b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,6 +7,7 @@ NEXT: - BUG: bt_close crashes when used in CocoaTouch app - BUG: BTdaemon crashes on iPhone when CocoaTouch app is closed (sometimes) - BUG: malloc warning when BTdaemon is started by launchd +- Support TCP socket server on 13333 via launchd in addition to the unix socket - Provide BTstackManager Objective-C class - implement l2cap code - implement rfcomm code diff --git a/src/daemon.c b/src/daemon.c index c73d4228d..d77ba6400 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -343,14 +343,17 @@ int main (int argc, char * const * argv){ l2cap_init(); l2cap_register_event_packet_handler(daemon_event_handler); timeout.process = daemon_no_connections_timeout; - + +#ifdef USE_LAUNCHD + socket_connection_create_launchd(); +#else // create server if (tcp_flag) { socket_connection_create_tcp(BTSTACK_PORT); } else { socket_connection_create_unix(BTSTACK_UNIX); } - +#endif socket_connection_register_packet_callback(daemon_client_handler); // handle CTRL-c diff --git a/src/socket_connection.c b/src/socket_connection.c index eafb96ba5..ddbf749a0 100644 --- a/src/socket_connection.c +++ b/src/socket_connection.c @@ -270,11 +270,10 @@ int socket_connection_create_tcp(int port){ } /** - * create socket data_source for unix domain socket - * */ -int socket_connection_create_unix(char *path){ - + * create socket data_source for socket specified by launchd configuration + */ #ifdef USE_LAUNCHD +int socket_connection_create_launchd(){ launch_data_t sockets_dict, checkin_response; launch_data_t checkin_request; @@ -348,9 +347,14 @@ int socket_connection_create_unix(char *path){ } launch_data_free(checkin_response); +} +#endif -#else - +/** + * create socket data_source for unix domain socket + */ +int socket_connection_create_unix(char *path){ + // create data_source_t data_source_t *ds = malloc( sizeof(data_source_t)); if (ds == NULL) return -1; @@ -389,8 +393,6 @@ int socket_connection_create_unix(char *path){ run_loop_add_data_source(ds); -#endif - printf ("Server up and running ...\n"); return 0; } diff --git a/src/socket_connection.h b/src/socket_connection.h index bdc763a01..cf80da687 100644 --- a/src/socket_connection.h +++ b/src/socket_connection.h @@ -45,6 +45,11 @@ /** opaque connection type */ typedef struct connection connection_t; +/** + * create socket data_source for socket specified by launchd configuration + */ +int socket_connection_create_launchd(); + /** * create socket for incoming tcp connections */