[PATCH wayland] server: Make serial number 0 mean invalid

Derek Foreman derekf at osg.samsung.com
Wed Sep 30 08:59:05 PDT 2015


Having an invalid serial number is quite useful - for example, we can
have protocol requests that optionally take a serial number or 0
instead of having two similar requests.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---

Well, let's see where this goes ;)

I've seen a few times now when having an invalid serial number would be
helpful, is it too late to do this?  Are we going to break anything?

Anything currently doing math on serial numbers can be wrong by one if one
of the serial numbers has wrapped around - this probably doesn't matter?

I do wonder if we should have a wl_serial_compare() as part of wayland
but the semantics are tricky (a big serial and a small serial may actually
have happened quite close to eachother if the small happened after a
wrap around).

I think the usual comparisons of interest are equality and "is A less than B
within (arbitrary distance to compensate for wrap-around)".  I think strcmp()
like semantics won't necessarily be good here because we don't usually need
something to tell us "b happened before a", more "these almost certainly
happened in the order specified in the function call".

Where do we go from here?

 src/wayland-server.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 0f04f66..e9e02a6 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -826,7 +826,7 @@ wl_display_create(void)
 	wl_signal_init(&display->destroy_signal);
 
 	display->id = 1;
-	display->serial = 0;
+	display->serial = 1;
 
 	wl_array_init(&display->additional_shm_formats);
 
@@ -979,6 +979,9 @@ wl_display_next_serial(struct wl_display *display)
 {
 	display->serial++;
 
+	if (display->serial == 0)
+		display->serial++;
+
 	return display->serial;
 }
 
-- 
2.5.3



More information about the wayland-devel mailing list