[PATCH 3/6] read a complete input event as guaranteed by Linux kernel
Guillem Jover
guillem.jover at nokia.com
Fri Oct 31 17:29:10 PDT 2008
Do not support partial event reads, as Linux kernel guarantees to always
provide a complete event on reads.
---
hald/linux/addons/addon-input.c | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/hald/linux/addons/addon-input.c b/hald/linux/addons/addon-input.c
index b2ed992..548df9f 100644
--- a/hald/linux/addons/addon-input.c
+++ b/hald/linux/addons/addon-input.c
@@ -166,7 +166,6 @@ typedef struct _InputData InputData;
struct _InputData
{
struct input_event event;
- gsize offset;
gboolean button_has_state;
gboolean button_state;
char udi[1]; /*variable size*/
@@ -188,19 +187,15 @@ event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
return FALSE;
- /** tbh, we can probably assume every time we read we have a whole
- * event availiable, but hey..*/
+ /* The kernel guarantees to always provide a complete event. */
while (g_io_channel_read_chars (channel,
- ((gchar*)&input_data->event) + input_data->offset,
- sizeof(struct input_event) - input_data->offset,
+ ((gchar*)&input_data->event),
+ sizeof (struct input_event),
&read_bytes, &gerror) == G_IO_STATUS_NORMAL) {
- if (input_data->offset + read_bytes < sizeof (struct input_event)) {
- input_data->offset = input_data->offset + read_bytes;
- HAL_DEBUG (("incomplete read"));
- return TRUE;
- } else {
- input_data->offset = 0;
+ if (read_bytes < sizeof (struct input_event)) {
+ HAL_ERROR (("incomplete input event read"));
+ return FALSE;
}
if (input_data->button_has_state &&
@@ -338,7 +333,6 @@ add_device (LibHalContext *ctx,
if (data->button_has_state)
data->button_state = libhal_ps_get_bool (properties, "button.state.value");
- data->offset = 0;
eventfp = open(device_file, O_RDONLY | O_NONBLOCK);
if (!eventfp) {
HAL_ERROR(("Unable to open %s for reading", device_file));
--
1.6.0.2
More information about the hal
mailing list