2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2018-07-17 01:06:24 -07:00
|
|
|
|
|
|
|
|
#include "wpi/uv/Handle.h"
|
|
|
|
|
|
|
|
|
|
using namespace wpi::uv;
|
|
|
|
|
|
|
|
|
|
Handle::~Handle() noexcept {
|
2018-10-16 00:38:48 -07:00
|
|
|
if (!m_closed && m_uv_handle->type != UV_UNKNOWN_HANDLE) {
|
2021-05-01 07:04:14 -07:00
|
|
|
uv_close(m_uv_handle, [](uv_handle_t* uv_handle) { std::free(uv_handle); });
|
2018-07-17 01:06:24 -07:00
|
|
|
} else {
|
2021-05-01 07:04:14 -07:00
|
|
|
std::free(m_uv_handle);
|
2018-07-17 01:06:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Handle::Close() noexcept {
|
|
|
|
|
if (!IsClosing()) {
|
|
|
|
|
uv_close(m_uv_handle, [](uv_handle_t* handle) {
|
|
|
|
|
Handle& h = *static_cast<Handle*>(handle->data);
|
|
|
|
|
h.closed();
|
|
|
|
|
h.Release(); // free ourselves
|
|
|
|
|
});
|
|
|
|
|
m_closed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Handle::AllocBuf(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
|
|
|
|
|
auto& h = *static_cast<Handle*>(handle->data);
|
|
|
|
|
*buf = h.m_allocBuf(size);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void Handle::DefaultFreeBuf(Buffer& buf) {
|
|
|
|
|
buf.Deallocate();
|
|
|
|
|
}
|