Not used anywhere, so no need to keep it around anymore.
Also dropping the BytesReadable vector, which is unused now.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Existing client-state hook isn't sufficient for this, and so easy to
be extended cleanly (*1). Adding a new callback is trivial and cheap,
so preferring this way, instead of trying to tweak the existing hook
for something it's never been designed for.
*1) see discussion here: https://github.com/X11Libre/xserver/pull/1077
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
arc4random_buf() is a pretty standard libc function on Unix'oid platforms,
but not all our targets have it, thus we need a fallback there. Currently we
have GenerateRandomData(), which either just wraps arc4random_buf() or provides
some fallback implementation.
For those cases it's easier to just implement missing functions directly
instead of having custom wrapper functions. So, drop GenerateRandomData()
in favor of arc4random_buf() and provide fallback implementation for where
it is missing.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
We need to undef this win32 symbol, otherwise it's conflicting with our
`CreateWindow` fields.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
size_t is unsigned, but might have different sizes depending on CPU arch,
so casting it to unsigned long, so we can safely use %ld.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Since everything's running via Writev() methods now, the now unused Write()
methods can all be dropped.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Now that all WriteV() methods are operating on single buffer instead ofiovec's,
we don't need the complicated _XSERVTransWriteV() anymore, but instead can
write directly to the socket/fd.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Since they're only called with a one-element iovec, we can use a single
buffer pointer straight away, thus making it quite the same as the old
Write() methods.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
_XSERVTransWrite() is only intended as frontend, for xtrans consumers to
call in here. And upcoming commits will change that function to call the
Writev() method instead of Write(), so we would end up in infinite
recursing if we'd still it it here.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Refactor _XSERVTransWriteV() to call write() on Unix and instead drop
the WRITEV() macro.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Adding helper safe_strlen() that's also checking for NULL pointer
and returning 0 in this case.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
The global (exported) serverGeneration field is `unsigned long`, while
many other places copy it and compare it two other integer types, eg.
plain `int` (which is signed). Even if it's unlikely ever reaching such
high number of generations that it will ever make trouble, it's still
a good idea to clean this up and use the same type everywhere.
For clearity, introducing a typedef `x_server_generation_t` which is
used everywhere, instead of raw `unsigned long`.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This function was badly broken, among other things doing a
use after free, a NULL-pointer dereferrence, and not doing
what it was supposed to do.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
Flushclient implicitly cast the result from a write-like call
to size_t, which turned it's error return value, -1,
into a large positive value, breaking the surrounding error-checking code.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
Since FlushClient only writes the data in the client's buffer,
with no extra data or padding, we only write at most as many bytes
as there are in the client buffer.
we just have to set oco->count to notWritten, the amount we still
have to write.
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
Since nothing on WIN32 (mingw) targets is calling uname() anymore,
this compat code is now obsolete.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Simplify DefineSelf() by using xhostname(). Neither need to
care about OS specifics here, nor take care of zero-terminating the
hostname string - xhostname() is already doing this.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Now that we have the OS layer xhostname() wrapper, we don't need the
_XSERVTransGetHostname() function anymore.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Simplify set_font_authorizations() by using xhostname(). Neither need to
care about OS specifics here, nor take care of zero-terminating the
hostname string - xhostname() is already doing this.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This little helper does the OS specific part for gethostname()
calls. It's putting the result into a fixed-length struct and making
sure it's properly filled and the string is always zero-terminated.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
FlushClient() does drops the output buffer, when it becomes empty.
This previously wasn't any problem and actually intented, because we've
returned from the write path directly after FlushClient() was called.
But now we've changed the call order, so it's called from within
OutputBufferMakeRoom(), so we need to make sure we always got valid
output buffer before trying to access it.
For the future, we should think about whether dropping output buffers
really makes sense at all. Instead we could leave them as they are
(over the client's lifetime) and maybe just trim when they've went
too big.
Fixes: 1c13cfa6ca
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reducing the ifdef-zoo a bit by moving the platform specific socket
close calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling close().
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reducing the ifdef-zoo a bit by moving the platform specific socket
ioctl calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling ioctl().
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Reduce the ifdef-zoo a bit by moving win32 specific socket layer init
into a separate function (that's no-op on non-win32).
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
A socket() call either returns a valid socket fd or -1, there's no need for
trying to check whether the returned fd is out of the OS's allowed range
of fd's, because if it would, the kernel would return error anyways.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Since nobody's passing in extra data here anymore, this function
can be radically simplified now.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Move up the check for broken/NULL transport connection in order to
simplify the code a bit more.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
First step for simplifying the output path - this is really complicated now:
FlushClient() is called in two cases:
a) we really need to send out critical data (eg. critical events now),
here we have no extra data
b) going to write new data in the output buffer, but it's already full
here we do have extra data
In case b) (only called from WriteToClient()) we're first trying to write out
as much as we can, and if there's still not enough room, the buffer is resized.
The write-out path is a complex look trying to write buffered data first, then
the new data. That's even more complex since using writev() with 3 pieces
(old buffer, new data, padding), and considering each of those could be written
just partially.
By the way, there's really no need that the new data is strictly written
along with the already buffered one - practically that's not even any actual
performance optimization - so it's just making things unncessarily complicated.
Therefore reduce it to what's really needed: ensure enough room in the output
buffer (and potentially flush out or resize the buffer). In a later, remove the
whole extra data part from FlushClient(), as it's not needed anymore.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's such a cold and rarely used path, we really don't need writev() for
efficiency, so instead doing two trivial write()'s. And the complex size
calculation as well as extra padding isn't necessary, if we just make
the string of size 4*n.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
On WIN32 we need to include winsock2.h, but we can't include misc.h here
becaues it pulling in X11 headers that are conflicting with win32 headers.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Instead of redefining existing standard libc symbols, pick another symbol
that's mapped to the corresponding platform specific function.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
The only option left is TRANS_NONBLOCKING, and we only enable and
never disable it. Thus trim down the code into one function for
exactly that.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's not used anywhere, so no need to keep it around anymore.
We can also dispose the corresponding connection driver's procs here.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Win32 does not have utsname(), but gethostname(), so we need a separate
implementation of _XSERVTransGetHostname() here.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
It's better coding style to include the header with prototypes for
our own functions directly, instead of relying on it being included
indirectly.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>