Document of c-modernization-kit (porter) 1.0.0

Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
potrHealthThread.c File Reference

ヘルスチェックスレッドモジュール。 More...

`#include <string.h>`
`#include <inttypes.h>`
`#include <sys/socket.h>`
`#include <netinet/in.h>`
`#include <arpa/inet.h>`
`#include <unistd.h>`
`#include <time.h>`
`#include <porter_const.h>`
`#include <porter.h>`
`#include "../protocol/packet.h"`
`#include "../protocol/window.h"`
`#include "../potrContext.h"`
`#include "../potrPeerTable.h"`
`#include "potrHealthThread.h"`
`#include "../infra/potrLog.h"`
`#include "../infra/crypto/crypto.h"`
Include dependency graph for potrHealthThread.c:

Go to the source code of this file.

## Data Structures
struct | HealthArg

## Macros
#define | POTR_MUTEX_LOCK_LOCAL(m)
#define | POTR_MUTEX_UNLOCK_LOCAL(m)

## Functions
static void | health_sleep (struct PotrContext_ *ctx, int path_idx, uint32_t interval_ms)
static uint64_t | health_get_ms (void)
static void * | health_thread_func (void *arg)
static void * | tcp_health_thread_func (void *arg)
int | potr_health_thread_start (struct PotrContext_ *ctx)
| 非 TCP ヘルスチェックスレッドを起動します。
int | potr_health_thread_stop (struct PotrContext_ *ctx)
| 非 TCP ヘルスチェックスレッドを停止します。
int | potr_tcp_health_thread_start (struct PotrContext_ *ctx, int path_idx)
| TCP ヘルスチェックスレッドを path ごとに起動します。
int | potr_tcp_health_thread_stop (struct PotrContext_ *ctx, int path_idx)
| TCP ヘルスチェックスレッドを停止します。

## Variables
static HealthArg | s_health_args [POTR_MAX_PATH]

## Detailed Description

ヘルスチェックスレッドモジュール。

Author
  c-modernization-kit sample team

Date
  2026/03/08

Version
  1.0.0

送信者側で動作する定周期 PING 送信スレッドです。
health_interval_ms 周期で PING パケットを送信します。
受信者側から送信者へのヘルスチェックは行いません (一方向ヘルスチェック)。

Copyright
  Copyright (C) CompanyName, Ltd. 2026. All rights reserved.

Definition in file potrHealthThread.c.

## Macro Definition Documentation

## ◆ POTR_MUTEX_LOCK_LOCAL

#define POTR_MUTEX_LOCK_LOCAL | ( |  | m | ) |

Value:
pthread_mutex_lock(m)

Definition at line 46 of file potrHealthThread.c.

Referenced by health_thread_func(), and tcp_health_thread_func().

## ◆ POTR_MUTEX_UNLOCK_LOCAL

#define POTR_MUTEX_UNLOCK_LOCAL | ( |  | m | ) |

Value:
pthread_mutex_unlock(m)

Definition at line 47 of file potrHealthThread.c.

Referenced by health_thread_func(), and tcp_health_thread_func().

## Function Documentation

## ◆ health_sleep()

void health_sleep | ( | struct PotrContext_ * | ctx,
|  | int | path_idx,
|  | uint32_t | interval_ms )
| static

Definition at line 65 of file potrHealthThread.c.

References PotrContext_::health_mutex, PotrContext_::health_running, and PotrContext_::health_wakeup.

Referenced by health_thread_func(), and tcp_health_thread_func().

Here is the caller graph for this function:

## ◆ health_get_ms()

uint64_t health_get_ms | ( | void |  | ) |
| static

Definition at line 96 of file potrHealthThread.c.

Referenced by health_thread_func(), and tcp_health_thread_func().

Here is the caller graph for this function:

## ◆ health_thread_func()

void * health_thread_func | ( | void * | arg | ) |
| static

Definition at line 111 of file potrHealthThread.c.

References PotrPeerContext_::active, PotrContext_::dest_addr, PotrPeerContext_::dest_addr, PotrServiceDef::encrypt_enabled, PotrServiceDef::encrypt_key, PotrPacket::flags, PotrContext_::global, health_get_ms(), PotrGlobalConfig::health_interval_ms, PotrContext_::health_running, health_sleep(), PotrContext_::is_multi_peer, PotrContext_::last_send_ms, PotrContext_::max_peers, PotrContext_::n_path, PotrWindow::next_seq, packet_build_ping(), PACKET_HEADER_SIZE, packet_wire_size(), PotrPacket::payload_len, PotrPeerContext_::peer_id, PotrContext_::peers, PotrContext_::peers_mutex, POTR_CRYPTO_NONCE_SIZE, POTR_CRYPTO_TAG_SIZE, potr_encrypt(), POTR_FLAG_ENCRYPTED, POTR_LOG, POTR_MAX_PATH, POTR_MUTEX_LOCK_LOCAL, POTR_MUTEX_UNLOCK_LOCAL, POTR_SUCCESS, POTR_TRACE_VERBOSE, PotrContext_::send_window, PotrPeerContext_::send_window, PotrContext_::send_window_mutex, PotrPeerContext_::send_window_mutex, PotrPacket::seq_num, PotrContext_::service, PotrPacketSessionHdr::service_id, PotrServiceDef::service_id, PotrContext_::session_id, PotrPacket::session_id, PotrPacketSessionHdr::session_id, PotrPeerContext_::session_id, PotrContext_::session_tv_nsec, PotrPacketSessionHdr::session_tv_nsec, PotrPeerContext_::session_tv_nsec, PotrContext_::session_tv_sec, PotrPacketSessionHdr::session_tv_sec, PotrPeerContext_::session_tv_sec, and PotrContext_::sock.

Referenced by potr_health_thread_start().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ tcp_health_thread_func()

void * tcp_health_thread_func | ( | void * | arg | ) |
| static

Definition at line 354 of file potrHealthThread.c.

References HealthArg::ctx, PotrServiceDef::encrypt_enabled, PotrServiceDef::encrypt_key, PotrPacket::flags, PotrContext_::global, health_get_ms(), PotrGlobalConfig::health_interval_ms, PotrContext_::health_running, health_sleep(), PotrGlobalConfig::health_timeout_ms, PotrWindow::next_seq, packet_build_ping(), PACKET_HEADER_SIZE, packet_wire_size(), HealthArg::path_idx, PotrPacket::payload_len, POTR_CRYPTO_NONCE_SIZE, POTR_CRYPTO_TAG_SIZE, potr_encrypt(), POTR_FLAG_ENCRYPTED, POTR_INVALID_SOCKET, POTR_LOG, POTR_MUTEX_LOCK_LOCAL, POTR_MUTEX_UNLOCK_LOCAL, POTR_SUCCESS, POTR_TRACE_VERBOSE, POTR_TRACE_WARNING, PotrContext_::send_window, PotrContext_::send_window_mutex, PotrPacket::seq_num, PotrContext_::service, PotrPacketSessionHdr::service_id, PotrServiceDef::service_id, PotrContext_::session_id, PotrPacket::session_id, PotrPacketSessionHdr::session_id, PotrContext_::session_tv_nsec, PotrPacketSessionHdr::session_tv_nsec, PotrContext_::session_tv_sec, PotrPacketSessionHdr::session_tv_sec, PotrContext_::tcp_active_paths, PotrContext_::tcp_conn_fd, PotrContext_::tcp_last_ping_recv_ms, and PotrContext_::tcp_send_mutex.

Referenced by potr_tcp_health_thread_start().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ potr_health_thread_start()

int potr_health_thread_start | ( | struct PotrContext_ * | ctx | ) |

非 TCP ヘルスチェックスレッドを起動します。

Parameters

  [in,out] | ctx | セッションコンテキストへのポインタ。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

ctx->global.health_interval_ms が 0 の場合は起動しません (POTR_SUCCESS を返します)。

Definition at line 526 of file potrHealthThread.c.

References PotrContext_::global, PotrGlobalConfig::health_interval_ms, PotrContext_::health_mutex, PotrContext_::health_running, PotrContext_::health_thread, health_thread_func(), PotrContext_::health_wakeup, POTR_ERROR, POTR_LOG, POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, PotrContext_::service, and PotrServiceDef::service_id.

Referenced by potrOpenService().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ potr_health_thread_stop()

int potr_health_thread_stop | ( | struct PotrContext_ * | ctx | ) |

非 TCP ヘルスチェックスレッドを停止します。

Parameters

  [in,out] | ctx | セッションコンテキストへのポインタ。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

Definition at line 584 of file potrHealthThread.c.

References PotrContext_::health_mutex, PotrContext_::health_running, PotrContext_::health_thread, PotrContext_::health_wakeup, POTR_ERROR, and POTR_SUCCESS.

Referenced by potrCloseService(), and potrOpenService().

Here is the caller graph for this function:

## ◆ potr_tcp_health_thread_start()

int potr_tcp_health_thread_start | ( | struct PotrContext_ * | ctx,
|  | int | path_idx )

TCP ヘルスチェックスレッドを path ごとに起動します。

Parameters

  [in,out] | ctx | セッションコンテキストへのポインタ。
  [in] | path_idx | パスインデックス (0 ～ n_path-1)。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

ctx->global.health_interval_ms が 0 の場合は起動しません (POTR_SUCCESS を返します)。

Definition at line 629 of file potrHealthThread.c.

References PotrContext_::global, PotrGlobalConfig::health_interval_ms, PotrContext_::health_running, PotrContext_::health_thread, POTR_ERROR, POTR_LOG, POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, s_health_args, PotrContext_::service, PotrServiceDef::service_id, and tcp_health_thread_func().

Referenced by start_connected_threads().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ potr_tcp_health_thread_stop()

int potr_tcp_health_thread_stop | ( | struct PotrContext_ * | ctx,
|  | int | path_idx )

TCP ヘルスチェックスレッドを停止します。

Parameters

  [in,out] | ctx | セッションコンテキストへのポインタ。
  [in] | path_idx | パスインデックス (0 ～ n_path-1)。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

Definition at line 681 of file potrHealthThread.c.

References PotrContext_::health_mutex, PotrContext_::health_running, PotrContext_::health_thread, PotrContext_::health_wakeup, POTR_ERROR, and POTR_SUCCESS.

Referenced by stop_connected_threads().

Here is the caller graph for this function:

## Variable Documentation

## ◆ s_health_args

HealthArg s_health_args[POTR_MAX_PATH]
| static

Definition at line 62 of file potrHealthThread.c.

Referenced by potr_tcp_health_thread_start().