[asterisk-addons-commits] mnicholson: branch mnicholson/chan-mobile-refactor r747 - /team/mnicholson/ch...
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Mon Jan 26 12:53:26 CST 2009
Author: mnicholson
Date: Mon Jan 26 12:53:25 2009
New Revision: 747
URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=747
Log:
Added rfcomm_write_full() and reimplemented rfcomm_write() using it.
Also rfcomm_write() returns -1 on error and 0 on success now.
Modified:
team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
Modified: team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
URL: http://svn.digium.com/svn-view/asterisk-addons/team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c?view=diff&rev=747&r1=746&r2=747
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Mon Jan 26 12:53:25 2009
@@ -218,6 +218,7 @@
static int rfcomm_connect(bdaddr_t src, bdaddr_t dst, int remote_channel);
static int rfcomm_write(int rsock, char *buf);
+static int rfcomm_write_full(int rsock, char *buf, size_t count);
static int rfcomm_wait(int rsock, int *ms);
static ssize_t rfcomm_read(int rsock, char *buf, size_t count);
@@ -1011,27 +1012,51 @@
}
+/*
+ * \brief Write to an rfcomm socket.
+ * \param rsock the socket to write to
+ * \param buf the null terminated buffer to write
+ *
+ * This function will write characters from buf. The buffer must be null
+ * terminated.
+ *
+ * \retval -1 error
+ * \retval 0 success
+ */
static int rfcomm_write(int rsock, char *buf)
{
-
- char *p;
- ssize_t num_write;
- int len;
-
- ast_debug(1, "rfcomm_write() (%d) [%s]\n", rsock, buf);
- len = strlen(buf);
- p = buf;
- while (len > 0) {
- if ((num_write = write(rsock, p, len)) == -1) {
+ return rfcomm_write_full(rsock, buf, strlen(buf));
+}
+
+
+/*
+ * \brief Write to an rfcomm socket.
+ * \param rsock the socket to write to
+ * \param buf the buffer to write
+ * \param count the number of characters from the buffer to write
+ *
+ * This function will write count characters from buf. It will always write
+ * count chars unless it encounters an error.
+ *
+ * \retval -1 error
+ * \retval 0 success
+ */
+static int rfcomm_write_full(int rsock, char *buf, size_t count)
+{
+ char *p = buf;
+ ssize_t out_count;
+
+ ast_debug(1, "rfcomm_write() (%d) [%.*s]\n", rsock, count, buf);
+ while (count > 0) {
+ if ((out_count = write(rsock, p, count)) == -1) {
ast_debug(1, "rfcomm_write() error [%d]\n", errno);
- return 0;
- }
- len -= num_write;
- p += num_write;
- }
-
- return 1;
-
+ return -1;
+ }
+ count -= out_count;
+ p += out_count;
+ }
+
+ return 0;
}
/*
@@ -1338,7 +1363,7 @@
brsf = nsmode = 0;
- if (!rfcomm_write(pvt->rfcomm_socket, "AT+BRSF=4\r"))
+ if (rfcomm_write(pvt->rfcomm_socket, "AT+BRSF=4\r"))
monitor = 0;
while (monitor) {
@@ -1647,7 +1672,7 @@
pvt->state = MBL_STATE_IDLE;
} else if (pvt->state == MBL_STATE_DIAL) {
snprintf(buf, sizeof(buf), "ATD%s;\r", pvt->dial_number);
- if (!rfcomm_write(pvt->rfcomm_socket, buf)) {
+ if (rfcomm_write(pvt->rfcomm_socket, buf)) {
ast_log(LOG_ERROR, "Dial failed on %s state %d\n", pvt->owner->name, pvt->state);
ast_queue_control(pvt->owner, AST_CONTROL_CONGESTION);
pvt->state = MBL_STATE_IDLE;
More information about the asterisk-addons-commits
mailing list