Commit Graph

10 Commits

Author SHA1 Message Date
sesankm
5a0b736952 dix: rpcbuf: exporting x_rpcbuf_write_string_0t_pad for glx
Signed-off-by: sesankm <26676400+sesankm@users.noreply.github.com>
2025-09-12 19:36:21 +02:00
Enrico Weigelt, metux IT consult
975436f535 dix: rpcbuf: _X_EXPORT x_rpcbuf_write_CARD8s() for internal use
_X_EXPORT'ing x_rpcbuf_write_CARD8s() just for internal use (eg. glx),
it's *NOT* supposed to be called by any external modules/drivers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-04 11:10:23 +02:00
Enrico Weigelt, metux IT consult
61f9234ee8 dix: rpcbuf: _X_EXPORT some functions for internal use
_X_EXPORT'ing some x_rpcbuf_clear() and x_rpcbuf_write_CARD8s() just for
internal use (eg. glx) - those are *NOT* supposed to be called by any
external modules/drivers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-03 11:20:59 +02:00
Enrico Weigelt, metux IT consult
2aec9a0b73 dix: rpcbuf: add x_rpcbuf_write_CARD64() and x_rpcbuf_write_CARD64s()
Add functions for writing (and byte-swapping) CARD64 values.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-03 09:31:30 +02:00
Enrico Weigelt, metux IT consult
ed47ec4bcb dix: rpcbuf: don't clear memory unless requested explicitly
Instead of always zero'ing out the whole buffer at allocation time, only
do it where really necessary. Also adding x_rpcbuf_reserve0() for reserving
buffer space that's explicitly cleared.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 17:26:25 +02:00
Enrico Weigelt, metux IT consult
123652228e dix: rpcbuf: use x_rpcbuf_t instead of struct x_rpcbuf
Both are the same types, the `struct x_rpcbuf` still remains, but it
seems more clear to use the `x_rpcbuf_t` as the canonical name.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 17:26:25 +02:00
Enrico Weigelt, metux IT consult
8222ad2cfa dix: rpcbuf: add x_rpcbuf_write_string_0t_pad()
The existing x_rpcbuf_write_string() function is just writing the string w/o
trailing zero. It's for cases where the string length is known by other means
(eg. some header field). In cases where we also need the trailing zero written
(eg. when sending lists of strings) this isn't sufficient.

Thus introducing another variant of this function, which is always writing
a leading zero. Using this one, the string's characters will be followed
by 1, 2 or 3 zeros (and also be 32bit aligned)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 04:51:31 +02:00
Enrico Weigelt, metux IT consult
4efe7768f1 dix: rpcbuf: flag for auto-clear in error case
when the err_clear flag is set, the buffer memory will automatically
be free()ed when allocation failed. This allows simplificatoin of
caller's error pathes: the caller doesn't need to to call x_rpcbuf_clear()
anymore and eg. can directly return out.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 04:51:31 +02:00
Enrico Weigelt, metux IT consult
d90620f363 dix: rpcbuf: store allocation failure
Remember allocation failure in new `error` field, for easing error
handling in complex callers: those now don't need to check each single
return value, but can (try to) continue their normal operation and
check for error condition later.

For example we can turn this:

     for (....) {
        if (!x_rpcbuf_write_CARD16(&rpcbuf,...)) {
            [ various cleanups ]
            return BadAlloc;
        }
        if (!rpcbuf_write_CARD8s(&rpcbuf,...)) {
            [ various cleanups ]
            return BadAlloc;
        }
        [ more of this ]
    }
    ...

Into:

     for (....) {
        x_rpcbuf_write_CARD16(&rpcbuf,...));
        x_rpcbuf_write_CARD8s(&rpcbuf,...));
        [ more of this ]
    }
    ...

    if (&rpcbuf->error) {
        [ various cleanups ]
        return BadAlloc;
    }

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 04:51:31 +02:00
Enrico Weigelt, metux IT consult
7ed470c882 dix: add buffer helper for rpc payload assembly
Since so many request handlers have to assemble complex reply payloads,
we've got a lot complexity on counting the needed space and filling in
the data into the right places.

Thus adding a little dynamic buffer structure, where one just can append
data arbitrarily. The buffer will automatically allocate memory as-needed
and finally leave everything in a big memory block for later write-out.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 04:51:31 +02:00