From 92062b88a83272371039c23f559036253683ca11 Mon Sep 17 00:00:00 2001 From: "mila@ringwald.ch" Date: Thu, 23 Oct 2014 09:50:11 +0000 Subject: [PATCH] extracted rfcomm_cen_send_packet_now method --- src/rfcomm.c | 14 +++++++++----- src/rfcomm.h | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/rfcomm.c b/src/rfcomm.c index 6861d6fa1..007fae667 100644 --- a/src/rfcomm.c +++ b/src/rfcomm.c @@ -1987,13 +1987,11 @@ void rfcomm_register_packet_handler(void (*handler)(void * connection, uint8_t p app_packet_handler = handler; } -// send packet over specific channel -int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ - +int rfcomm_can_send_packet_now(uint16_t rfcomm_cid){ rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid); if (!channel){ log_error("rfcomm_send_internal cid 0x%02x doesn't exist!", rfcomm_cid); - return 0; + return 1; } if (!channel->credits_outgoing){ @@ -2012,7 +2010,13 @@ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ } // log_info("rfcomm_send_internal: len %u... outgoing credits %u, l2cap credit %us, granted %u", // len, channel->credits_outgoing, channel->multiplexer->l2cap_credits, channel->packets_granted); - + return 0; +} + +// send packet over specific channel +int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ + int err = rfcomm_can_send_packet_now(); + if (err) return err; // send might cause l2cap to emit new credits, update counters first channel->credits_outgoing--; diff --git a/src/rfcomm.h b/src/rfcomm.h index ca5afe6a2..104908a9e 100644 --- a/src/rfcomm.h +++ b/src/rfcomm.h @@ -405,6 +405,9 @@ void rfcomm_decline_connection_internal(uint16_t rfcomm_cid); // Grant more incoming credits to the remote side for the given RFCOMM channel identifier. void rfcomm_grant_credits(uint16_t rfcomm_cid, uint8_t credits); +// Chekcs if RFCOMM can send packet. If yes returns 0, otherwise returns an error code. +int rfcomm_can_send_packet_now(uint16_t rfcomm_cid); + // Sends RFCOMM data packet to the RFCOMM channel with given identifier. int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len);