mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Add adapter_close to stop TCP stack
This commit is contained in:
@@ -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