aboutsummaryrefslogtreecommitdiff
path: root/src/mm-serial-port.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2011-04-08 15:42:28 -0500
committerDan Williams <dcbw@redhat.com>2011-04-08 15:42:28 -0500
commit273f4203d4eeda3614d76bcdbda537ed76feef35 (patch)
treea57a64b52a0107902481ee8b56044bde2f86e847 /src/mm-serial-port.c
parent2640baefa417612cd26fe3c826634c91d50e0917 (diff)
serial: send entire command in one write if send_delay is 0 (chromium:13506)
Avoids additional USB latency and groups the whole command into one USB packet. BUG=chromium-os:13506
Diffstat (limited to 'src/mm-serial-port.c')
-rw-r--r--src/mm-serial-port.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mm-serial-port.c b/src/mm-serial-port.c
index 7f10beb1..f05a1aea 100644
--- a/src/mm-serial-port.c
+++ b/src/mm-serial-port.c
@@ -373,7 +373,7 @@ mm_serial_port_process_command (MMSerialPort *self,
{
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (self);
const guint8 *p;
- int status;
+ int status, expected_status, send_len;
if (priv->fd < 0) {
g_set_error_literal (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED,
@@ -393,14 +393,24 @@ mm_serial_port_process_command (MMSerialPort *self,
serial_debug (self, "-->", (const char *) info->command->data, info->command->len);
}
+ if (priv->send_delay == 0) {
+ /* Send the whole command in one write */
+ send_len = expected_status = info->command->len;
+ p = info->command->data;
+ } else {
+ /* Send just one byte of the command */
+ send_len = expected_status = 1;
+ p = &info->command->data[info->idx];
+ }
+
/* Send a single byte of the command */
- p = &info->command->data[info->idx];
errno = 0;
- status = write (priv->fd, p, 1);
- if (status == 1)
- info->idx++;
- else if (status < 0) {
- if (errno == EAGAIN) {
+ status = write (priv->fd, p, send_len);
+ if (status > 0)
+ info->idx += status;
+ else {
+ /* Error or no bytes written */
+ if (errno == EAGAIN || status == 0) {
info->eagain_count--;
if (info->eagain_count <= 0) {
g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED,