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 | 22 |
1 files changed, 11 insertions, 11 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 @@ -773,11 +773,11 @@ data_available (GIOChannel *source, + 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; } @@ -788,6 +788,5 @@ data_available (GIOChannel *source, - if (bytes_read > 0) { - serial_debug (self, "<--", buf, bytes_read); - g_byte_array_append (priv->response, (const guint8 *) buf, bytes_read); - } + g_assert (bytes_read > 0); + serial_debug (self, "<--", buf, bytes_read); + g_byte_array_append (priv->response, (const guint8 *) buf, bytes_read); @@ -805,3 +804,4 @@ data_available (GIOChannel *source, } - } 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)); |