Wayland API 中的串行参数的用途是什么?
What's the purpose of the serial parameter in the Wayland API?
我最近一直在使用 Wayland 协议,许多函数都包含一个 unit32_t serial
参数。这是来自 wayland-client-protocol.h:
的示例
struct wl_shell_surface_listener {
/**
* ping client
*
* Ping a client to check if it is receiving events and sending
* requests. A client is expected to reply with a pong request.
*/
void (*ping)(void *data,
struct wl_shell_surface *wl_shell_surface,
uint32_t serial);
// ...
}
此参数的目的是让客户端用 pong
响应显示服务器,将 serial
的值传递给它。服务器会将通过 pong
接收到的 serial
与通过 ping 发送的 serial
进行比较。
还有许多其他函数包含这样的 serial
参数。此外,API 中其他函数的实现通常会在执行某些工作之前递增全局 wl_display->serial
属性 以获得新的 serial
值。我的问题是,这个 serial
参数的基本原理是什么,在一般意义上 ?它有名字吗?例如,这是 IPC 的事情,还是事件驱动/异步编程中的常见做法?它有点像异步方法调用的 XCB "cookie" 概念吗?是否在其他程序中发现了这种技术(请引用示例)?
另一个例子是 glut,见 glutTimerFunc
discussed here 作为 "common idiom for asynchronous invocation." 我很想知道这个成语是否有名字,以及在哪里(请引用好的)作为异步/偶数驱动编程中的最佳实践或技术进行讨论,例如延续或 "signals and slots." 或者,例如,共享资源计数如何只是整数,但我们认为它们是 "semaphores."
正如评论中 Hans Passant and Tom Zych 所述,参数是将一个异步调用与另一个异步调用区分开来。
我仍然很好奇更深层次的问题,即这种技术是否是异步/事件驱动软件中常用的一种技术,以及它是否有一个众所周知的名字。
您可能会发现 this 有帮助
Some actions that a Wayland client may perform require a trivial form
of authentication in the form of input event serials. For example, a
client which opens a popup (a context menu summoned with a right click
is one kind of popup) may want to "grab" all input events server-side
from the affected seat until the popup is dismissed. To prevent abuse
of this feature, the server can assign serials to each input event it
sends, and require the client to include one of these serials in the
request.
When the server receives such a request, it looks up the input event
associated with the given serial and makes a judgement call. If the
event was too long ago, or for the wrong surface, or wasn't the right
kind of event — for example, it could reject grabs when you wiggle the
mouse, but allow them when you click — it can reject the request.
From the server's perspective, they can simply send a incrementing
integer with each input event, and record the serials which are
considered valid for a particular use-case for later validation. The
client receives these serials from their input event handlers, and can
simply pass them back right away to perform the desired action.
我最近一直在使用 Wayland 协议,许多函数都包含一个 unit32_t serial
参数。这是来自 wayland-client-protocol.h:
struct wl_shell_surface_listener {
/**
* ping client
*
* Ping a client to check if it is receiving events and sending
* requests. A client is expected to reply with a pong request.
*/
void (*ping)(void *data,
struct wl_shell_surface *wl_shell_surface,
uint32_t serial);
// ...
}
此参数的目的是让客户端用 pong
响应显示服务器,将 serial
的值传递给它。服务器会将通过 pong
接收到的 serial
与通过 ping 发送的 serial
进行比较。
还有许多其他函数包含这样的 serial
参数。此外,API 中其他函数的实现通常会在执行某些工作之前递增全局 wl_display->serial
属性 以获得新的 serial
值。我的问题是,这个 serial
参数的基本原理是什么,在一般意义上 ?它有名字吗?例如,这是 IPC 的事情,还是事件驱动/异步编程中的常见做法?它有点像异步方法调用的 XCB "cookie" 概念吗?是否在其他程序中发现了这种技术(请引用示例)?
另一个例子是 glut,见 glutTimerFunc
discussed here 作为 "common idiom for asynchronous invocation." 我很想知道这个成语是否有名字,以及在哪里(请引用好的)作为异步/偶数驱动编程中的最佳实践或技术进行讨论,例如延续或 "signals and slots." 或者,例如,共享资源计数如何只是整数,但我们认为它们是 "semaphores."
正如评论中 Hans Passant and Tom Zych 所述,参数是将一个异步调用与另一个异步调用区分开来。
我仍然很好奇更深层次的问题,即这种技术是否是异步/事件驱动软件中常用的一种技术,以及它是否有一个众所周知的名字。
您可能会发现 this 有帮助
Some actions that a Wayland client may perform require a trivial form of authentication in the form of input event serials. For example, a client which opens a popup (a context menu summoned with a right click is one kind of popup) may want to "grab" all input events server-side from the affected seat until the popup is dismissed. To prevent abuse of this feature, the server can assign serials to each input event it sends, and require the client to include one of these serials in the request.
When the server receives such a request, it looks up the input event associated with the given serial and makes a judgement call. If the event was too long ago, or for the wrong surface, or wasn't the right kind of event — for example, it could reject grabs when you wiggle the mouse, but allow them when you click — it can reject the request.
From the server's perspective, they can simply send a incrementing integer with each input event, and record the serials which are considered valid for a particular use-case for later validation. The client receives these serials from their input event handlers, and can simply pass them back right away to perform the desired action.