mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-25 16:43:28 +00:00
defined socket_connection_retry_parked_random() to re-dispatch packets previously received
This commit is contained in:
parent
9f63451023
commit
1e67635ac4
@ -79,7 +79,7 @@ typedef struct packet_header {
|
||||
|
||||
typedef enum {
|
||||
SOCKET_W4_HEADER,
|
||||
SOCKET_W4_DATA,
|
||||
SOCKET_W4_DATA
|
||||
} SOCKET_STATE;
|
||||
|
||||
struct connection {
|
||||
@ -167,6 +167,7 @@ void static socket_connection_emit_nr_connections(){
|
||||
|
||||
int socket_connection_hci_process(struct data_source *ds) {
|
||||
connection_t *conn = (connection_t *) ds;
|
||||
|
||||
int bytes_read = read(ds->fd, &conn->buffer[conn->bytes_read], conn->bytes_to_read);
|
||||
if (bytes_read <= 0){
|
||||
// connection broken (no particular channel, no date yet)
|
||||
@ -186,6 +187,8 @@ int socket_connection_hci_process(struct data_source *ds) {
|
||||
if (conn->bytes_to_read > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dispatch_err;
|
||||
switch (conn->state){
|
||||
case SOCKET_W4_HEADER:
|
||||
conn->state = SOCKET_W4_DATA;
|
||||
@ -193,8 +196,12 @@ int socket_connection_hci_process(struct data_source *ds) {
|
||||
break;
|
||||
case SOCKET_W4_DATA:
|
||||
// dispatch packet !!! connection, type, channel, data, size
|
||||
(*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2),
|
||||
dispatch_err = (*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2),
|
||||
&conn->buffer[sizeof(packet_header_t)], READ_BT_16( conn->buffer, 4));
|
||||
|
||||
if (dispatch_err) {
|
||||
// conn->state = SOCKET_W4_DISPATCH;
|
||||
}
|
||||
// reset state machine
|
||||
socket_connection_init_statemachine(conn);
|
||||
break;
|
||||
@ -302,7 +309,6 @@ int socket_connection_create_launchd(){
|
||||
launch_data_t sockets_dict, checkin_response;
|
||||
launch_data_t checkin_request;
|
||||
launch_data_t listening_fd_array;
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
* Register ourselves with launchd.
|
||||
@ -363,6 +369,7 @@ int socket_connection_create_launchd(){
|
||||
|
||||
// although used in Apple examples, it creates a malloc warning
|
||||
// launch_data_free(checkin_response);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -520,3 +527,17 @@ int socket_connection_close_unix(connection_t * connection){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* try to dispatch packet for all "parked" connections. start at random point for fairness
|
||||
* if dispatch is successful, a connection is added again to run loop
|
||||
*/
|
||||
void socket_connection_retry_parked_random(){
|
||||
// re-try dispatching packet
|
||||
// int dispatch_err = (*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2),
|
||||
// &conn->buffer[sizeof(packet_header_t)], READ_BT_16( conn->buffer, 4));
|
||||
// if (dispatch_err) return 0;
|
||||
//
|
||||
// add this socket to the run_loop again
|
||||
// run_loop_add_data_source( &conn->ds );
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,9 @@ connection_t * socket_connection_open_unix();
|
||||
*/
|
||||
int socket_connection_close_unix(connection_t *connection);
|
||||
|
||||
|
||||
/**
|
||||
* set packet handler for all auto-accepted connections
|
||||
* -- packet_callback @return: 0 == OK/NO ERROR
|
||||
*/
|
||||
void socket_connection_register_packet_callback( int (*packet_callback)(connection_t *connection, uint16_t packet_type, uint16_t channel, uint8_t *data, uint16_t length) );
|
||||
|
||||
@ -100,3 +100,9 @@ void socket_connection_send_packet(connection_t *connection, uint16_t packet_typ
|
||||
* send event data to all clients
|
||||
*/
|
||||
void socket_connection_send_packet_all(uint16_t type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
/**
|
||||
* try to dispatch packet for all "parked" connections. start at random point for fairness
|
||||
* if dispatch is successful, a connection is added again to run loop
|
||||
*/
|
||||
void socket_connection_retry_parked_random();
|
||||
|
Loading…
x
Reference in New Issue
Block a user