update servicepoint library
This commit is contained in:
parent
44ef4bb6d7
commit
f7cb5546b3
8 changed files with 116 additions and 141 deletions
|
@ -1,35 +1,33 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::errors::ServicePointError;
|
||||
use std::{
|
||||
net::UdpSocket,
|
||||
sync::Arc
|
||||
};
|
||||
use servicepoint::UdpSocketExt;
|
||||
use crate::{
|
||||
command::Command,
|
||||
errors::ServicePointError
|
||||
};
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Connection {
|
||||
actual: servicepoint::Connection,
|
||||
actual: UdpSocket,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl Connection {
|
||||
#[uniffi::constructor]
|
||||
pub fn new(host: String) -> Result<Arc<Self>, ServicePointError> {
|
||||
servicepoint::Connection::open(host)
|
||||
UdpSocket::bind_connect(host)
|
||||
.map(|actual| Arc::new(Connection { actual }))
|
||||
.map_err(|err| ServicePointError::IoError {
|
||||
error: err.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn new_fake() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
actual: servicepoint::Connection::Fake,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
|
||||
self.actual.send(command.actual.clone()).map_err(|err| {
|
||||
self.actual.send_command(command.actual.clone()).ok_or_else(|| {
|
||||
ServicePointError::IoError {
|
||||
error: format!("{err:?}"),
|
||||
error: "send failed".to_string(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue