Add functions to look up req and handle sizes
Useful for FFI bindings. Closes #370.
This commit is contained in:
parent
5f38ba1a89
commit
f09f7bc6a8
12
include/uv.h
12
include/uv.h
@ -382,6 +382,18 @@ struct uv_handle_s {
|
||||
UV_HANDLE_FIELDS
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns size of various handle types, useful for FFI
|
||||
* bindings to allocate correct memory without copying struct
|
||||
* definitions
|
||||
*/
|
||||
UV_EXTERN size_t uv_handle_size(uv_handle_type type);
|
||||
|
||||
/*
|
||||
* Returns size of request types, useful for dynamic lookup with FFI
|
||||
*/
|
||||
UV_EXTERN size_t uv_req_size(uv_req_type type);
|
||||
|
||||
/*
|
||||
* Returns 1 if the prepare/check/idle/timer handle has been started, 0
|
||||
* otherwise. For other handle types this always returns 1.
|
||||
|
||||
@ -32,6 +32,25 @@
|
||||
#include "ares/inet_net_pton.h"
|
||||
#include "ares/inet_ntop.h"
|
||||
|
||||
#define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);
|
||||
|
||||
size_t uv_handle_size(uv_handle_type type) {
|
||||
switch (type) {
|
||||
UV_HANDLE_TYPE_MAP(XX)
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t uv_req_size(uv_req_type type) {
|
||||
switch(type) {
|
||||
UV_REQ_TYPE_MAP(XX)
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#undef XX
|
||||
|
||||
size_t uv_strlcpy(char* dst, const char* src, size_t size) {
|
||||
size_t n;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user