mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
update response namespace
This commit is contained in:
parent
70fc128c29
commit
4767929050
19 changed files with 59 additions and 50 deletions
|
|
@ -1,11 +1,17 @@
|
|||
pub mod error;
|
||||
pub mod response;
|
||||
|
||||
pub use error::Error;
|
||||
pub use response::Response;
|
||||
|
||||
use gio::{
|
||||
prelude::TlsConnectionExt, IOStream, NetworkAddress, SocketConnection, TlsCertificate,
|
||||
TlsClientConnection,
|
||||
prelude::{IOStreamExt, OutputStreamExt, TlsConnectionExt},
|
||||
Cancellable, IOStream, NetworkAddress, SocketConnection, TlsCertificate, TlsClientConnection,
|
||||
};
|
||||
use glib::{
|
||||
object::{Cast, IsA, ObjectExt},
|
||||
Bytes, Priority,
|
||||
};
|
||||
use glib::object::{Cast, IsA, ObjectExt};
|
||||
|
||||
pub struct Connection {
|
||||
pub socket_connection: SocketConnection,
|
||||
|
|
@ -51,6 +57,40 @@ impl Connection {
|
|||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Make new request to available `Connection`
|
||||
/// * callback with new `Response` on success or `Error` on failure
|
||||
pub fn request_async(
|
||||
self,
|
||||
query: String,
|
||||
priority: Priority,
|
||||
cancellable: Cancellable,
|
||||
callback: impl Fn(Result<Response, Error>) + 'static,
|
||||
) {
|
||||
self.tls_client_connection
|
||||
.output_stream()
|
||||
.write_bytes_async(
|
||||
&Bytes::from(format!("{query}\r\n").as_bytes()),
|
||||
priority,
|
||||
Some(&cancellable.clone()),
|
||||
move |result| match result {
|
||||
Ok(_) => Response::from_connection_async(
|
||||
self,
|
||||
priority,
|
||||
cancellable,
|
||||
move |result| {
|
||||
callback(match result {
|
||||
Ok(response) => Ok(response),
|
||||
Err(e) => Err(Error::Response(e)),
|
||||
})
|
||||
},
|
||||
),
|
||||
Err(e) => callback(Err(Error::Stream(e))),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get [IOStream](https://docs.gtk.org/gio/class.IOStream.html)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue