client, protocol-native: Use macros for protocol version/flag access

This makes it easier to read and cleaner in general.
This commit is contained in:
Arun Raghavan 2016-04-25 18:12:39 +05:30 committed by Arun Raghavan
parent 8887f256e0
commit 7ac5390042
3 changed files with 18 additions and 12 deletions

View file

@ -504,17 +504,17 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
/* Starting with protocol version 13 the MSB of the version /* Starting with protocol version 13 the MSB of the version
tag reflects if shm is available for this connection or tag reflects if shm is available for this connection or
not. */ not. */
if (c->version >= 13) { if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 13) {
shm_on_remote = !!(c->version & 0x80000000U); shm_on_remote = !!(c->version & PA_PROTOCOL_FLAG_SHM);
/* Starting with protocol version 31, the second MSB of the version /* Starting with protocol version 31, the second MSB of the version
* tag reflects whether memfd is supported on the other PA end. */ * tag reflects whether memfd is supported on the other PA end. */
if (c->version >= 31) if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 31)
memfd_on_remote = !!(c->version & 0x40000000U); memfd_on_remote = !!(c->version & PA_PROTOCOL_FLAG_MEMFD);
/* Reserve the two most-significant _bytes_ of the version tag /* Reserve the two most-significant _bytes_ of the version tag
* for flags. */ * for flags. */
c->version &= 0x0000FFFFU; c->version &= PA_PROTOCOL_VERSION_MASK;
} }
pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION); pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION);
@ -629,8 +629,8 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
/* Starting with protocol version 13 we use the MSB of the version /* Starting with protocol version 13 we use the MSB of the version
* tag for informing the other side if we could do SHM or not. * tag for informing the other side if we could do SHM or not.
* Starting from version 31, second MSB is used to flag memfd support. */ * Starting from version 31, second MSB is used to flag memfd support. */
pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? 0x80000000U : 0) | pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? PA_PROTOCOL_FLAG_SHM : 0) |
(c->memfd_on_local ? 0x40000000 : 0)); (c->memfd_on_local ? PA_PROTOCOL_FLAG_MEMFD: 0));
pa_tagstruct_put_arbitrary(t, cookie, sizeof(cookie)); pa_tagstruct_put_arbitrary(t, cookie, sizeof(cookie));
#ifdef HAVE_CREDS #ifdef HAVE_CREDS

View file

@ -49,6 +49,12 @@
#define DEFAULT_TIMEOUT (30) #define DEFAULT_TIMEOUT (30)
#define PA_PROTOCOL_FLAG_MASK 0xFFFF0000U
#define PA_PROTOCOL_VERSION_MASK 0x0000FFFFU
#define PA_PROTOCOL_FLAG_SHM 0x80000000U
#define PA_PROTOCOL_FLAG_MEMFD 0x40000000U
struct pa_context { struct pa_context {
PA_REFCNT_DECLARE; PA_REFCNT_DECLARE;

View file

@ -2718,17 +2718,17 @@ static void command_auth(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_ta
/* Starting with protocol version 13 the MSB of the version tag /* Starting with protocol version 13 the MSB of the version tag
reflects if shm is available for this pa_native_connection or reflects if shm is available for this pa_native_connection or
not. */ not. */
if (c->version >= 13) { if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 13) {
shm_on_remote = !!(c->version & 0x80000000U); shm_on_remote = !!(c->version & PA_PROTOCOL_FLAG_SHM);
/* Starting with protocol version 31, the second MSB of the version /* Starting with protocol version 31, the second MSB of the version
* tag reflects whether memfd is supported on the other PA end. */ * tag reflects whether memfd is supported on the other PA end. */
if (c->version >= 31) if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 31)
memfd_on_remote = !!(c->version & 0x40000000U); memfd_on_remote = !!(c->version & PA_PROTOCOL_FLAG_MEMFD);
/* Reserve the two most-significant _bytes_ of the version tag /* Reserve the two most-significant _bytes_ of the version tag
* for flags. */ * for flags. */
c->version &= 0x0000FFFFU; c->version &= PA_PROTOCOL_VERSION_MASK;
} }
pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION); pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION);