mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
extract socket_connection_launchd_register_fd_array, support 2 sockets in launchd, work around malloc warning
This commit is contained in:
parent
3810b62576
commit
91f5bcb531
@ -203,9 +203,11 @@ int socket_connection_hci_process(struct data_source *ds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int socket_connection_accept(struct data_source *socket_ds) {
|
static int socket_connection_accept(struct data_source *socket_ds) {
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
socklen_t slen = sizeof(ss);
|
||||||
|
|
||||||
/* New connection coming in! */
|
/* New connection coming in! */
|
||||||
int fd = accept(socket_ds->fd, NULL, NULL);
|
int fd = accept(socket_ds->fd, (struct sockaddr *)&ss, &slen);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("accept");
|
perror("accept");
|
||||||
return 0;
|
return 0;
|
||||||
@ -269,10 +271,32 @@ int socket_connection_create_tcp(int port){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_LAUNCHD
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register listening sockets with our run loop
|
||||||
|
*/
|
||||||
|
void socket_connection_launchd_register_fd_array(launch_data_t listening_fd_array){
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < launch_data_array_get_count(listening_fd_array); i++) {
|
||||||
|
// get fd
|
||||||
|
launch_data_t tempi = launch_data_array_get_index (listening_fd_array, i);
|
||||||
|
int listening_fd = launch_data_get_fd(tempi);
|
||||||
|
launch_data_free (tempi);
|
||||||
|
printf("file descriptor = %u\n",(unsigned int) i+1, listening_fd);
|
||||||
|
|
||||||
|
// create data_source_t for fd
|
||||||
|
data_source_t *ds = malloc( sizeof(data_source_t));
|
||||||
|
if (ds == NULL) return;
|
||||||
|
ds->process = socket_connection_accept;
|
||||||
|
ds->fd = listening_fd;
|
||||||
|
run_loop_add_data_source(ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create socket data_source for socket specified by launchd configuration
|
* create socket data_source for socket specified by launchd configuration
|
||||||
*/
|
*/
|
||||||
#ifdef USE_LAUNCHD
|
|
||||||
int socket_connection_create_launchd(){
|
int socket_connection_create_launchd(){
|
||||||
|
|
||||||
launch_data_t sockets_dict, checkin_response;
|
launch_data_t sockets_dict, checkin_response;
|
||||||
@ -315,38 +339,30 @@ int socket_connection_create_launchd(){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (launch_data_dict_get_count(sockets_dict) > 1) {
|
// if (launch_data_dict_get_count(sockets_dict) > 1) {
|
||||||
fprintf(stderr,"Some sockets will be ignored!");
|
// fprintf(stderr,"Some sockets will be ignored!");
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the dictionary value from the key "Listeners"
|
* Get the dictionary value from the key "Listeners"
|
||||||
*/
|
*/
|
||||||
listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners");
|
listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners");
|
||||||
if (NULL == listening_fd_array) {
|
if (listening_fd_array) {
|
||||||
fprintf(stderr,"No known sockets found to answer requests on!");
|
// fprintf(stderr,"Listeners...\n");
|
||||||
return -1;
|
socket_connection_launchd_register_fd_array( listening_fd_array );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register listening sockets with our run loop
|
* Get the dictionary value from the key "Listeners"
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < launch_data_array_get_count(listening_fd_array); i++) {
|
listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners2");
|
||||||
// get fd
|
if (listening_fd_array) {
|
||||||
launch_data_t tempi = launch_data_array_get_index (listening_fd_array, i);
|
// fprintf(stderr,"Listeners2...\n");
|
||||||
int listening_fd = launch_data_get_fd(tempi);
|
socket_connection_launchd_register_fd_array( listening_fd_array );
|
||||||
launch_data_free (tempi);
|
}
|
||||||
printf("%u. file descriptor = %u\n",(unsigned int) i+1, listening_fd);
|
|
||||||
|
|
||||||
// create data_source_t for fd
|
|
||||||
data_source_t *ds = malloc( sizeof(data_source_t));
|
|
||||||
if (ds == NULL) return -1;
|
|
||||||
ds->process = socket_connection_accept;
|
|
||||||
ds->fd = listening_fd;
|
|
||||||
run_loop_add_data_source(ds);
|
|
||||||
}
|
|
||||||
|
|
||||||
launch_data_free(checkin_response);
|
// although used in Apple examples, it creates a malloc warning
|
||||||
|
// launch_data_free(checkin_response);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user