diff options
author | Dan Williams <dcbw@redhat.com> | 2012-11-26 17:05:52 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-11-27 09:56:25 -0600 |
commit | 8772d63389b97a65bcace9fe0b54175a6adab9fe (patch) | |
tree | c00e9dc98fb1b9b9048240dad641714710e31ab3 | |
parent | a7167b93b9f077e063024754ad2d566fc65f76b4 (diff) |
serial-port: stop reading data if the serial port was closed
If a response processor closed the port, don't try to read any
more data from it. Move the priv->watch_id check to the
while condition so the loop terminates before calling
g_io_channel_read_chars() again, which caused a warning since
the underlying file descriptor was already closed.
Also, bytes_read will never be less than zero (it's unsigned),
so skip the bytes_read > 0 check and just assert that this
condition is true.
-rw-r--r-- | src/mm-serial-port.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/mm-serial-port.c b/src/mm-serial-port.c index ce2dfebd..acfec4ca 100644 --- a/src/mm-serial-port.c +++ b/src/mm-serial-port.c @@ -771,25 +771,24 @@ data_available (GIOChannel *source, do { GError *err = NULL; + bytes_read = 0; status = g_io_channel_read_chars (source, buf, SERIAL_BUF_SIZE, &bytes_read, &err); if (status == G_IO_STATUS_ERROR) { - if (err && err->message) - g_warning ("%s", err->message); + if (err && err->message) { + g_warning ("(%s) read error: %s", + mm_port_get_device (MM_PORT (self)), + err->message); + } g_clear_error (&err); - - /* Serial port is closed; we're done */ - if (priv->watch_id == 0) - break; } /* If no bytes read, just let g_io_channel wait for more data */ if (bytes_read == 0) break; - if (bytes_read > 0) { + g_assert (bytes_read > 0); serial_debug (self, "<--", buf, bytes_read); g_byte_array_append (priv->response, (const guint8 *) buf, bytes_read); - } /* Make sure the response doesn't grow too long */ if ((priv->response->len > SERIAL_BUF_SIZE) && priv->spew_control) { @@ -803,7 +802,8 @@ data_available (GIOChannel *source, priv->n_consecutive_timeouts = 0; mm_serial_port_got_response (self, err); } - } while (bytes_read == SERIAL_BUF_SIZE || status == G_IO_STATUS_AGAIN); + } while ( (bytes_read == SERIAL_BUF_SIZE || status == G_IO_STATUS_AGAIN) + && (priv->watch_id > 0)); return TRUE; } |