*/
UDPC_EXPORT void UDPC_atostr_unsafe_free_ptr(const char **addrBuf);
+/*!
+ * \brief Gets the currently set amount of time between heartbeat packets in
+ * milliseconds.
+ *
+ * \return 0 if context is invalid, otherwise the interval time in milliseconds.
+ */
+UDPC_EXPORT uint32_t UDPC_get_heartbeat_millis(UDPC_HContext ctx);
+
/*!
* \brief Sets the amount of time between heartbeat packets.
*
*/
UDPC_EXPORT int UDPC_set_heartbeat_millis(UDPC_HContext ctx, unsigned int millis);
+/*!
+ * \brief Gets the currently set connection timeout time in milliseconds.
+ *
+ * \return 0 if context is invalid, otherwise the timeout time in milliseconds.
+ */
+UDPC_EXPORT uint64_t UDPC_get_con_timeout_millis(UDPC_HContext ctx);
+
/*!
* \brief Sets the connection timeout time.
*
}
}
+uint32_t UDPC_get_heartbeat_millis(UDPC_HContext ctx) {
+ UDPC::Context *c = UDPC::verifyContext(ctx);
+ if (!c) {
+ return 0;
+ }
+
+ std::shared_lock<std::shared_mutex> lock(c->heartbeatMutex);
+ // The milliseconds are clamped to a maximum for heartbeat, so it should
+ // fit in a 32-bit unsigned integer.
+ return c->heartbeatDuration.count();
+}
+
int UDPC_set_heartbeat_millis(UDPC_HContext ctx, unsigned int millis) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if (!c) {
return ret;
}
+uint64_t UDPC_get_con_timeout_millis(UDPC_HContext ctx) {
+ UDPC::Context *c = UDPC::verifyContext(ctx);
+ if (!c) {
+ return 0;
+ }
+
+ std::shared_lock<std::shared_mutex> lock(c->conTimeoutMutex);
+ return c->conTimeoutDuration.count();
+}
+
int UDPC_set_con_timeout_millis(UDPC_HContext ctx, unsigned int millis) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if (!c) {
thread_array[i].join();
}
}
+
+ // Test get/set heartbeat millis
+ {
+ UDPC_ConnectionId id = UDPC_create_id_anyaddr(0);
+ UDPC_HContext ctx = UDPC_init(id, 0, 0);
+
+ CHECK_TRUE(UDPC_get_heartbeat_millis(ctx) == UDPC::HEARTBEAT_PKT_INT_MIN_MILLIS);
+ CHECK_TRUE(UDPC_set_heartbeat_millis(ctx, 1) == 1);
+ CHECK_TRUE(UDPC_get_heartbeat_millis(ctx) == UDPC::HEARTBEAT_PKT_INT_MIN_MILLIS);
+ CHECK_TRUE(UDPC_set_heartbeat_millis(ctx, 10000) == 2);
+ CHECK_TRUE(UDPC_get_heartbeat_millis(ctx) == UDPC::HEARTBEAT_PKT_INT_MAX_MILLIS);
+ CHECK_TRUE(UDPC_set_heartbeat_millis(ctx, 2000) == 0);
+ CHECK_TRUE(UDPC_get_heartbeat_millis(ctx) == 2000);
+
+ UDPC_destroy(ctx);
+ }
+
+ // Test get/set connection timeout millis
+ {
+ UDPC_ConnectionId id = UDPC_create_id_anyaddr(0);
+ UDPC_HContext ctx = UDPC_init(id, 0, 0);
+
+ CHECK_TRUE(UDPC_get_con_timeout_millis(ctx) == UDPC_CON_TIMEOUT_DEFAULT);
+ CHECK_TRUE(UDPC_set_con_timeout_millis(ctx, 1) == -2);
+ CHECK_TRUE(UDPC_get_con_timeout_millis(ctx) == UDPC_CON_TIMEOUT_DEFAULT);
+ CHECK_TRUE(UDPC_set_con_timeout_millis(ctx, 7000) == 0);
+ CHECK_TRUE(UDPC_get_con_timeout_millis(ctx) == 7000);
+
+ UDPC_destroy(ctx);
+ }
}