pub struct BluetoothSocket { /* private fields */ }
Expand description
Manages the Bluetooth socket and IO streams. It uses a read buffer and a background thread,
because the timeout of the Java InputStream
from the BluetoothSocket
cannot be set.
The read timeout defaults to 0 (it does not block).
Reference: https://developer.android.com/develop/connectivity/bluetooth/transfer-data
Implementations§
Source§impl BluetoothSocket
impl BluetoothSocket
Sourcepub fn is_connected(&self) -> Result<bool, Error>
pub fn is_connected(&self) -> Result<bool, Error>
Gets the connection status of this socket.
Sourcepub fn connect(&mut self) -> Result<(), Error>
pub fn connect(&mut self) -> Result<(), Error>
Attempts to connect to a remote device. When connected, it creates a
backgrond thread for reading data, which terminates itself on disconnection.
Do not reuse the socket after disconnection, because the underlying OS
implementation is probably incapable of reconnecting the device, just like
java.net.Socket
.
Sourcepub fn len_available(&self) -> usize
pub fn len_available(&self) -> usize
Returns number of available bytes that can be read without blocking.
Sourcepub fn clear_read_buf(&mut self)
pub fn clear_read_buf(&mut self)
Clears the managed read buffer used by the Rust side background thread.
Sourcepub fn set_read_timeout(&mut self, timeout: Duration)
pub fn set_read_timeout(&mut self, timeout: Duration)
Sets timeout for the std::io::Read
implementation.
Sourcepub fn set_read_callback(&mut self, f: impl Fn(Option<usize>) + 'static + Send)
pub fn set_read_callback(&mut self, f: impl Fn(Option<usize>) + 'static + Send)
Sets or replaces the callback to be invoked from the background thread when
new data becomes available or the socket is disconnected. The length of newly
arrived data instead of the length of available data in the read buffer will
be passed to the callback (or None
if it is disconnected).
Trait Implementations§
Source§impl Drop for BluetoothSocket
impl Drop for BluetoothSocket
Source§impl Read for BluetoothSocket
impl Read for BluetoothSocket
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Write for BluetoothSocket
impl Write for BluetoothSocket
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)