Struct x11rb::rust_connection::RustConnection
source · pub struct RustConnection<S: Stream = DefaultStream> {
inner: Mutex<ConnectionInner>,
stream: S,
packet_reader: Mutex<PacketReader>,
reader_condition: Condvar,
setup: Setup,
extension_manager: Mutex<ExtensionManager>,
maximum_request_bytes: Mutex<MaxRequestBytes>,
id_allocator: Mutex<IdAllocator>,
}
Expand description
A connection to an X11 server implemented in pure rust
This type is generic over S
, which allows to use a generic stream to communicate with the
server. This stream can written to and read from, but it can also be polled, meaning that one
checks if new data can be read or written.
RustConnection
always used an internal buffer for reading, so R
does not need
to be buffered.
Fields§
§inner: Mutex<ConnectionInner>
§stream: S
§packet_reader: Mutex<PacketReader>
§reader_condition: Condvar
§setup: Setup
§extension_manager: Mutex<ExtensionManager>
§maximum_request_bytes: Mutex<MaxRequestBytes>
§id_allocator: Mutex<IdAllocator>
Implementations§
source§impl<S: Stream> RustConnection<S>
impl<S: Stream> RustConnection<S>
sourcepub fn connect_to_stream(stream: S, screen: usize) -> Result<Self, ConnectError>
pub fn connect_to_stream(stream: S, screen: usize) -> Result<Self, ConnectError>
Establish a new connection to the given streams.
read
is used for reading data from the X11 server and write
is used for writing.
screen
is the number of the screen that should be used. This function checks that a
screen with that number exists.
sourcepub fn connect_to_stream_with_auth_info(
stream: S,
screen: usize,
auth_name: Vec<u8>,
auth_data: Vec<u8>,
) -> Result<Self, ConnectError>
pub fn connect_to_stream_with_auth_info( stream: S, screen: usize, auth_name: Vec<u8>, auth_data: Vec<u8>, ) -> Result<Self, ConnectError>
Establish a new connection to the given streams.
read
is used for reading data from the X11 server and write
is used for writing.
screen
is the number of the screen that should be used. This function checks that a
screen with that number exists.
The parameters auth_name
and auth_data
are used for the members
authorization_protocol_name
and authorization_protocol_data
of the SetupRequest
that
is sent to the X11 server.
sourcepub fn for_connected_stream(
stream: S,
setup: Setup,
) -> Result<Self, ConnectError>
pub fn for_connected_stream( stream: S, setup: Setup, ) -> Result<Self, ConnectError>
Establish a new connection for an already connected stream.
The given stream
is used for communicating with the X11 server.
It is assumed that setup
was just received from the server. Thus, the first reply to a
request that is sent will have sequence number one.
sourcefn send_request(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<RawFdContainer>,
kind: ReplyFdKind,
) -> Result<SequenceNumber, ConnectionError>
fn send_request( &self, bufs: &[IoSlice<'_>], fds: Vec<RawFdContainer>, kind: ReplyFdKind, ) -> Result<SequenceNumber, ConnectionError>
Internal function for actually sending a request.
This function “does the actual work” for send_request_with_reply()
and
send_request_without_reply()
.
sourcefn send_sync<'a>(
&'a self,
inner: MutexGuard<'a, ConnectionInner>,
) -> Result<MutexGuard<'a, ConnectionInner>, Error>
fn send_sync<'a>( &'a self, inner: MutexGuard<'a, ConnectionInner>, ) -> Result<MutexGuard<'a, ConnectionInner>, Error>
Send a synchronisation packet to the X11 server.
This function sends a GetInputFocus
request to the X11 server and arranges for its reply
to be ignored. This ensures that a reply is expected (ConnectionInner.next_reply_expected
increases).
sourcefn write_all_vectored<'a>(
&'a self,
inner: MutexGuard<'a, ConnectionInner>,
bufs: &[IoSlice<'_>],
fds: Vec<RawFdContainer>,
) -> Result<MutexGuard<'a, ConnectionInner>>
fn write_all_vectored<'a>( &'a self, inner: MutexGuard<'a, ConnectionInner>, bufs: &[IoSlice<'_>], fds: Vec<RawFdContainer>, ) -> Result<MutexGuard<'a, ConnectionInner>>
Write a set of buffers on a writer
. May also read packets
from the server.
fn flush_impl<'a>( &'a self, inner: MutexGuard<'a, ConnectionInner>, ) -> Result<MutexGuard<'a, ConnectionInner>>
sourcefn read_packet_and_enqueue<'a>(
&'a self,
inner: MutexGuard<'a, ConnectionInner>,
mode: BlockingMode,
) -> Result<MutexGuard<'a, ConnectionInner>, Error>
fn read_packet_and_enqueue<'a>( &'a self, inner: MutexGuard<'a, ConnectionInner>, mode: BlockingMode, ) -> Result<MutexGuard<'a, ConnectionInner>, Error>
Read a packet from the connection.
This function waits for an X11 packet to be received. It drops the mutex protecting the
inner data while waiting for a packet so that other threads can make progress. For this
reason, you need to pass in a MutexGuard
to be dropped. This function locks the mutex
again and returns a new MutexGuard
.
Note: If mode
is BlockingMode::Blocking
, the lock on inner
will be temporarily
released. While sending a request, inner
must be kept locked to avoid sending the data
of different requests interleaved. So, when read_packet_and_enqueue
is called as part
of a write, it must always be done with mode
set to BlockingMode::NonBlocking
.