mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
return connection in result
This commit is contained in:
parent
8df7af44b5
commit
788b792167
3 changed files with 42 additions and 36 deletions
|
|
@ -60,7 +60,7 @@ impl Client {
|
|||
priority: Priority,
|
||||
cancellable: Cancellable,
|
||||
certificate: Option<TlsCertificate>,
|
||||
callback: impl FnOnce(Result<Response, Error>) + 'static,
|
||||
callback: impl FnOnce(Result<(Response, Connection), Error>) + 'static,
|
||||
) {
|
||||
// Begin new connection
|
||||
// * [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) required for valid
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ impl Connection {
|
|||
request: Request,
|
||||
priority: Priority,
|
||||
cancellable: Cancellable,
|
||||
callback: impl FnOnce(Result<Response, Error>) + 'static,
|
||||
callback: impl FnOnce(Result<(Response, Self), Error>) + 'static,
|
||||
) {
|
||||
let output_stream = self.stream().output_stream();
|
||||
output_stream.clone().write_async(
|
||||
|
|
@ -67,14 +67,17 @@ impl Connection {
|
|||
Some(&cancellable.clone()),
|
||||
move |result| match result {
|
||||
Ok(_) => match request {
|
||||
Request::Gemini { .. } => {
|
||||
Response::from_connection_async(self, priority, cancellable, |result| {
|
||||
Request::Gemini { .. } => Response::from_connection_async(
|
||||
self,
|
||||
priority,
|
||||
cancellable,
|
||||
|result, connection| {
|
||||
callback(match result {
|
||||
Ok(response) => Ok(response),
|
||||
Ok(response) => Ok((response, connection)),
|
||||
Err(e) => Err(Error::Response(e)),
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
),
|
||||
Request::Titan { data, .. } => output_stream.write_bytes_async(
|
||||
&data,
|
||||
priority,
|
||||
|
|
@ -84,9 +87,9 @@ impl Connection {
|
|||
self,
|
||||
priority,
|
||||
cancellable,
|
||||
|result| {
|
||||
|result, connection| {
|
||||
callback(match result {
|
||||
Ok(response) => Ok(response),
|
||||
Ok(response) => Ok((response, connection)),
|
||||
Err(e) => Err(Error::Response(e)),
|
||||
})
|
||||
},
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl Response {
|
|||
connection: Connection,
|
||||
priority: Priority,
|
||||
cancellable: Cancellable,
|
||||
callback: impl FnOnce(Result<Self, Error>) + 'static,
|
||||
callback: impl FnOnce(Result<Self, Error>, Connection) + 'static,
|
||||
) {
|
||||
from_stream_async(
|
||||
Vec::with_capacity(HEADER_LEN),
|
||||
|
|
@ -44,7 +44,8 @@ impl Response {
|
|||
cancellable,
|
||||
priority,
|
||||
|result| {
|
||||
callback(match result {
|
||||
callback(
|
||||
match result {
|
||||
Ok(buffer) => match buffer.first() {
|
||||
Some(byte) => match byte {
|
||||
1 => match Input::from_utf8(&buffer) {
|
||||
|
|
@ -72,7 +73,9 @@ impl Response {
|
|||
None => Err(Error::Protocol),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
})
|
||||
},
|
||||
connection,
|
||||
)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue