Struct wayland_commons::socket::BufferedSocket [−][src]
An adapter around a raw Socket that directly handles buffering and conversion from/to wayland messages
Implementations
impl BufferedSocket
[src]
pub fn new(socket: Socket) -> BufferedSocket
[src]
Wrap a Socket into a Buffered Socket
pub fn get_socket(&mut self) -> &mut Socket
[src]
Get direct access to the underlying socket
pub fn into_socket(self) -> Socket
[src]
Retrieve ownership of the underlying Socket
Any leftover content in the internal buffers will be lost
pub fn flush(&mut self) -> NixResult<()>
[src]
Flush the contents of the outgoing buffer into the socket
pub fn write_message(&mut self, msg: &Message) -> NixResult<()>
[src]
Write a message to the outgoing buffer
This method may flush the internal buffer if necessary (if it is full).
If the message is too big to fit in the buffer, the error Error::Sys(E2BIG)
will be returned.
pub fn fill_incoming_buffers(&mut self) -> NixResult<()>
[src]
Try to fill the incoming buffers of this socket, to prepare a new round of parsing.
pub fn read_one_message<F>(
&mut self,
signature: F
) -> Result<Message, MessageParseError> where
F: FnMut(u32, u16) -> Option<&'static [ArgumentType]>,
[src]
&mut self,
signature: F
) -> Result<Message, MessageParseError> where
F: FnMut(u32, u16) -> Option<&'static [ArgumentType]>,
Read and deserialize a single message from the incoming buffers socket
This method requires one closure that given an object id and an opcode,
must provide the signature of the associated request/event, in the form of
a &'static [ArgumentType]
. If it returns None
, meaning that
the couple object/opcode does not exist, an error will be returned.
There are 3 possibilities of return value:
Ok(Ok(msg))
: no error occurred, this is the messageOk(Err(e))
: either a malformed message was encountered or we need more data, in the latter case you need to try callingfill_incoming_buffers()
.Err(e)
: an I/O error occurred reading from the socked, details are ine
(this can be a “wouldblock” error, which just means that no message is available to read)
pub fn read_messages<F1, F2>(
&mut self,
signature: F1,
callback: F2
) -> NixResult<Result<usize, MessageParseError>> where
F1: FnMut(u32, u16) -> Option<&'static [ArgumentType]>,
F2: FnMut(Message) -> bool,
[src]
&mut self,
signature: F1,
callback: F2
) -> NixResult<Result<usize, MessageParseError>> where
F1: FnMut(u32, u16) -> Option<&'static [ArgumentType]>,
F2: FnMut(Message) -> bool,
Read and deserialize messages from the socket
This method requires two closures:
- The first one, given an object id and an opcode, must provide
the signature of the associated request/event, in the form of
a
&'static [ArgumentType]
. If it returnsNone
, meaning that the couple object/opcode does not exist, the parsing will be prematurely interrupted and this method will return aMessageParseError::Malformed
error. - The second closure is charged to process the parsed message. If it
returns
false
, the iteration will be prematurely stopped.
In both cases of early stopping, the remaining unused data will be left in the buffers, and will start to be processed at the next call of this method.
There are 3 possibilities of return value:
Ok(Ok(n))
: no error occurred,n
messages where processedOk(Err(MessageParseError::Malformed))
: a malformed message was encountered (this is a protocol error and is supposed to be fatal to the connection).Err(e)
: an I/O error occurred reading from the socked, details are ine
(this can be a “wouldblock” error, which just means that no message is available to read)
Auto Trait Implementations
impl RefUnwindSafe for BufferedSocket
impl Send for BufferedSocket
impl Sync for BufferedSocket
impl Unpin for BufferedSocket
impl UnwindSafe for BufferedSocket
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,