mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add adapter_close to stop TCP stack
This commit is contained in:
@@ -53,6 +53,14 @@ class Adapter {
|
||||
return Ok(ReadWrite::adopt(s));
|
||||
}
|
||||
|
||||
Result<void, FfiError> close() {
|
||||
FfiError e(::adapter_close(handle_.get()));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private:
|
||||
explicit Adapter(AdapterHandle* h) noexcept : handle_(h) {}
|
||||
AdapterPtr handle_{};
|
||||
|
||||
@@ -6,45 +6,49 @@
|
||||
namespace IdeviceFFI {
|
||||
|
||||
Result<void, FfiError> AdapterStream::close() {
|
||||
if (!h_)
|
||||
if (!h_) {
|
||||
return Ok();
|
||||
}
|
||||
|
||||
FfiError e(::adapter_stream_close(h_));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
h_ = nullptr;
|
||||
return Ok();
|
||||
|
||||
FfiError e(::adapter_close(h_));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
h_ = nullptr;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Result<void, FfiError> AdapterStream::send(const uint8_t *data, size_t len) {
|
||||
if (!h_)
|
||||
return Err(FfiError::NotConnected());
|
||||
FfiError e(::adapter_send(h_, data, len));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
return Ok();
|
||||
Result<void, FfiError> AdapterStream::send(const uint8_t* data, size_t len) {
|
||||
if (!h_) {
|
||||
return Err(FfiError::NotConnected());
|
||||
}
|
||||
FfiError e(::adapter_send(h_, data, len));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Result<std::vector<uint8_t>, FfiError> AdapterStream::recv(size_t max_hint) {
|
||||
if (!h_)
|
||||
return Err(FfiError::NotConnected());
|
||||
if (!h_) {
|
||||
return Err(FfiError::NotConnected());
|
||||
}
|
||||
|
||||
if (max_hint == 0)
|
||||
max_hint = 2048;
|
||||
if (max_hint == 0) {
|
||||
max_hint = 2048;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> out(max_hint);
|
||||
size_t actual = 0;
|
||||
std::vector<uint8_t> out(max_hint);
|
||||
size_t actual = 0;
|
||||
|
||||
FfiError e(::adapter_recv(h_, out.data(), &actual, out.size()));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
FfiError e(::adapter_recv(h_, out.data(), &actual, out.size()));
|
||||
if (e) {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
out.resize(actual);
|
||||
return Ok(std::move(out));
|
||||
out.resize(actual);
|
||||
return Ok(std::move(out));
|
||||
}
|
||||
|
||||
} // namespace IdeviceFFI
|
||||
|
||||
Reference in New Issue
Block a user