Improvements to language binding facilities
This commit is contained in:
@@ -25,9 +25,11 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef ZTS_ENABLE_PYTHON
|
||||
/* In some situations (Python comes to mind) a signal may not make its
|
||||
way to libzt, for this reason we make sure to define a custom signal handler
|
||||
that can at least process SIGTERMs */
|
||||
/**
|
||||
* In some situations (Python comes to mind) a signal may not make its
|
||||
* way to libzt, for this reason we make sure to define a custom signal
|
||||
* handler that can at least process SIGTERMs
|
||||
*/
|
||||
#define ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS 1
|
||||
#endif
|
||||
|
||||
@@ -842,7 +844,7 @@ struct zts_peer_list
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Python bits //
|
||||
// Python Bindings (Subset of regular socket API) //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef ZTS_ENABLE_PYTHON
|
||||
@@ -867,67 +869,15 @@ public:
|
||||
|
||||
extern PythonDirectorCallbackClass *_userEventCallback;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param fd
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int zts_sock_bind(int fd, int family, int type, PyObject *addro);
|
||||
int zts_py_bind(int fd, int family, int type, PyObject *addro);
|
||||
int zts_py_connect(int fd, int family, int type, PyObject *addro);
|
||||
PyObject * zts_py_accept(int fd);
|
||||
int zts_py_listen(int fd, int backlog);
|
||||
PyObject * zts_py_recv(int fd, int len, int flags);
|
||||
int zts_py_send(int fd, PyObject *buf, int len, int flags);
|
||||
int zts_py_close(int fd);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param fd
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int zts_sock_connect(int fd, int family, int type, PyObject *addro);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param fd
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
PyObject * zts_sock_accept(int fd);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param fd
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
PyObject * zts_sock_recv(int fd, int len, int flags);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param fd
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int zts_sock_send(int fd, PyObject *buf, int len, int flags);
|
||||
|
||||
#endif
|
||||
#endif // ZTS_ENABLE_PYTHON
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// ZeroTier Service Controls //
|
||||
@@ -1436,8 +1386,6 @@ struct zts_stats {
|
||||
struct zts_stats_proto nd6;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Return all statistical counters for all protocols (inefficient)
|
||||
*
|
||||
@@ -1455,6 +1403,8 @@ ZTS_API int ZTCALL zts_get_all_stats(struct zts_stats *statsDest);
|
||||
*/
|
||||
ZTS_API int ZTCALL zts_get_protocol_stats(int protocolType, void *protoStatsDest);
|
||||
|
||||
#endif // ZTS_ENABLE_STATS
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Socket API //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -135,9 +135,9 @@ int zts_start_with_identity(const char *key_pair_str, uint16_t key_buf_len,
|
||||
return ZTS_ERR_ARG;
|
||||
}
|
||||
Mutex::Lock _l(serviceLock);
|
||||
//#ifdef ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
#ifdef ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
_install_signal_handlers();
|
||||
//#endif // ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
#endif // ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
_lwip_driver_init();
|
||||
if (service || _getState(ZTS_STATE_NODE_RUNNING)) {
|
||||
// Service is already initialized
|
||||
@@ -254,9 +254,9 @@ int zts_start(const char *path, void (*callback)(void *), uint16_t port)
|
||||
#endif
|
||||
{
|
||||
Mutex::Lock _l(serviceLock);
|
||||
//#ifdef ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
#ifdef ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
_install_signal_handlers();
|
||||
//#endif // ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
#endif // ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
||||
_lwip_driver_init();
|
||||
if (service || _getState(ZTS_STATE_NODE_RUNNING)) {
|
||||
// Service is already initialized
|
||||
|
||||
@@ -259,7 +259,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_getsockopt(
|
||||
else {
|
||||
retval = zts_getsockopt(fd, level, optname, &optval_int, &optlen);
|
||||
}
|
||||
|
||||
|
||||
if (optname == SO_BROADCAST
|
||||
|| optname == SO_KEEPALIVE
|
||||
|| optname == SO_REUSEADDR
|
||||
@@ -307,7 +307,7 @@ JNIEXPORT jboolean JNICALL Java_com_zerotier_libzt_ZeroTier_getsockname(JNIEnv *
|
||||
struct zts_sockaddr_storage ss;
|
||||
zts_socklen_t addrlen = sizeof(struct zts_sockaddr_storage);
|
||||
int retval = zts_getsockname(fd, (struct zts_sockaddr *)&ss, &addrlen);
|
||||
ss2zta(env, &ss, addr);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -331,7 +331,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_getpeername(JNIEnv *env,
|
||||
{
|
||||
struct zts_sockaddr_storage ss;
|
||||
int retval = zts_getpeername(fd, (struct zts_sockaddr *)&ss, (zts_socklen_t*)sizeof(struct zts_sockaddr_storage));
|
||||
ss2zta(env, &ss, addr);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -391,7 +391,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_select(JNIEnv *env, jobj
|
||||
}
|
||||
if (exceptfds) {
|
||||
fdset2ztfdset(env, nfds, &_exceptfds, exceptfds);
|
||||
}
|
||||
}
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -438,7 +438,7 @@ JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_ioctl(
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (request == FIONREAD) {
|
||||
int bytesRemaining = 0;
|
||||
retval = zts_ioctl(fd, request, &bytesRemaining);
|
||||
retval = zts_ioctl(fd, request, &bytesRemaining);
|
||||
// set value in general object
|
||||
jclass c = env->GetObjectClass(argp);
|
||||
if (!c) {
|
||||
@@ -450,7 +450,7 @@ JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_ioctl(
|
||||
if (request == FIONBIO) {
|
||||
// TODO: double check
|
||||
int meaninglessVariable = 0;
|
||||
retval = zts_ioctl(fd, request, &meaninglessVariable);
|
||||
retval = zts_ioctl(fd, request, &meaninglessVariable);
|
||||
}
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -472,12 +472,12 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_send(
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_send(fd, data, env->GetArrayLength(buf), flags);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t zts_sendto(int fd, const void *buf, size_t len, int flags,
|
||||
ssize_t zts_sendto(int fd, const void *buf, size_t len, int flags,
|
||||
const struct zts_sockaddr *addr,zts_socklen_t addrlen)
|
||||
{
|
||||
if (!addr || !buf) {
|
||||
@@ -500,7 +500,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_sendto(
|
||||
zta2ss(env, &ss, addr);
|
||||
zts_socklen_t addrlen = ss.ss_family == ZTS_AF_INET ? sizeof(struct zts_sockaddr_in) : sizeof(struct zts_sockaddr_in6);
|
||||
int retval = zts_sendto(fd, data, env->GetArrayLength(buf), flags, (struct zts_sockaddr *)&ss, addrlen);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -536,7 +536,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_recv(JNIEnv *env, jobjec
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t zts_recvfrom(int fd, void *buf, size_t len, int flags,
|
||||
ssize_t zts_recvfrom(int fd, void *buf, size_t len, int flags,
|
||||
struct zts_sockaddr *addr, zts_socklen_t *addrlen)
|
||||
{
|
||||
if (!buf) {
|
||||
@@ -556,7 +556,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_recvfrom(
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_recvfrom(fd, data, env->GetArrayLength(buf), flags, (struct zts_sockaddr *)&ss, &addrlen);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
ss2zta(env, &ss, addr);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -602,7 +602,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read(JNIEnv *env, jobjec
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_read(fd, data, env->GetArrayLength(buf));
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1offset(JNIEnv *env, jobject thisObj,
|
||||
@@ -610,7 +610,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1offset(JNIEnv *env
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_read_offset(fd, data, offset, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1length(JNIEnv *env, jobject thisObj,
|
||||
@@ -618,7 +618,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1length(JNIEnv *env
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_read(fd, data, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -648,7 +648,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write__IB(JNIEnv *env, j
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
int retval = zts_write(fd, data, env->GetArrayLength(buf));
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write_1offset(JNIEnv *env, jobject thisObj,
|
||||
@@ -656,7 +656,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write_1offset(JNIEnv *en
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(&(buf[offset]), NULL); // PENDING: check?
|
||||
int retval = zts_write(fd, data, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write_1byte(JNIEnv *env, jobject thisObj,
|
||||
|
||||
Reference in New Issue
Block a user