Document of c-modernization-kit (porter) 1.0.0

Loading...
Searching...
No Matches
Functions
potrSendThread.c File Reference

非同期送信スレッドの実装。 More...

`#include <pthread.h>`
`#include <sys/socket.h>`
`#include <netinet/in.h>`
`#include <time.h>`
`#include <poll.h>`
`#include <string.h>`
`#include <inttypes.h>`
`#include <porter_const.h>`
`#include "../potrContext.h"`
`#include "../potrPeerTable.h"`
`#include "../infra/potrSendQueue.h"`
`#include "potrSendThread.h"`
`#include "../protocol/packet.h"`
`#include "../protocol/window.h"`
`#include "../infra/potrLog.h"`
`#include "../infra/crypto/crypto.h"`
Include dependency graph for potrSendThread.c:

Go to the source code of this file.

## Functions
static uint64_t | get_ms (void)
static void | append_payload_elem (uint8_t *packed_buf, size_t *packed_len, const PotrPayloadElem *entry)
static int | tcp_send_all (PotrSocket fd, PotrMutex *mtx, const uint8_t *buf, size_t len)
static void | flush_packed (struct PotrContext_ *ctx, size_t packed_len)
static void | flush_packed_peer (struct PotrContext_ *ctx, PotrPeerContext *peer, size_t packed_len)
static void | send_packed_peer_mode (struct PotrContext_ *ctx, PotrPayloadElem *first)
static void * | send_thread_func (void *arg)
int | potr_send_thread_start (struct PotrContext_ *ctx)
void | potr_send_thread_stop (struct PotrContext_ *ctx)

## Detailed Description

非同期送信スレッドの実装。

Author
  c-modernization-kit sample team

Date
  2026/03/08

Version
  1.0.0

送信キュー (PotrSendQueue) からペイロードエレメントを取り出して 外側パケット (POTR_FLAG_DATA) を構築し sendto を呼び出す送信スレッド。
potrOpenService (POTR_ROLE_SENDER) 時に起動し、potrCloseService 時に停止します。
potrSend の flags 引数の値によらず常に起動しており、 ノンブロッキング送信 (POTR_SEND_BLOCKING なし) 時のみキューが使用されます。

通番管理
  すべてのデータパケットはパックコンテナ形式で送受信します。
  再送・順序整列の単位は外側パケット (UDP datagram) であり、
  通番は本スレッドが外側パケットを構築する際に付与します。
  送信ウィンドウ (ctx->send_window) への登録も本スレッドが行います。

パッキング機能
  POTR_MAX_PAYLOAD - POTR_PAYLOAD_ELEM_HDR_SIZE 以下のフラグメントが 複数キューに滞留している場合、送信スレッドが 1 つの外側パケットに まとめて送信します。
  以下の場合は単体 (ペイロードエレメント 1 件) のコンテナとして送信します。
  - MORE_FRAG フラグが付いているエントリ (フラグメント化メッセージの途中)
  - キューに追加エントリが存在しない場合

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

Definition in file potrSendThread.c.

## Function Documentation

## ◆ get_ms()

uint64_t get_ms | ( | void |  | ) |
| static

Definition at line 61 of file potrSendThread.c.

Referenced by flush_packed(), flush_packed_peer(), and send_thread_func().

Here is the caller graph for this function:

## ◆ append_payload_elem()

void append_payload_elem | ( | uint8_t * | packed_buf,
|  | size_t * | packed_len,
|  | const PotrPayloadElem * | entry )
| static

Definition at line 73 of file potrSendThread.c.

References PotrPayloadElem::flags, PotrPayloadElem::payload, and PotrPayloadElem::payload_len.

Referenced by send_packed_peer_mode(), and send_thread_func().

Here is the caller graph for this function:

## ◆ tcp_send_all()

int tcp_send_all | ( | PotrSocket | fd,
|  | PotrMutex * | mtx,
|  | const uint8_t * | buf,
|  | size_t | len )
| static

Definition at line 87 of file potrSendThread.c.

References POTR_ERROR, and POTR_SUCCESS.

Referenced by flush_packed().

Here is the caller graph for this function:

## ◆ flush_packed()

void flush_packed | ( | struct PotrContext_ * | ctx,
|  | size_t | packed_len )
| static

Definition at line 120 of file potrSendThread.c.

References PotrContext_::buf_full_suppress_cnt, PotrContext_::crypto_buf, PotrContext_::crypto_buf_size, PotrContext_::dest_addr, PotrServiceDef::encrypt_enabled, PotrServiceDef::encrypt_key, PotrPacket::flags, get_ms(), PotrContext_::health_mutex, PotrContext_::health_running, PotrContext_::health_wakeup, PotrContext_::last_send_ms, PotrContext_::n_path, PotrWindow::next_seq, packet_build_packed(), PACKET_HEADER_SIZE, PotrPacket::payload_len, POTR_CRYPTO_NONCE_SIZE, POTR_CRYPTO_TAG_SIZE, potr_encrypt(), POTR_FLAG_ENCRYPTED, POTR_INVALID_SOCKET, potr_is_tcp_type(), POTR_LOG, POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, PotrContext_::send_window, PotrContext_::send_window_mutex, PotrContext_::send_wire_buf, 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_::sock, PotrContext_::tcp_active_paths, PotrContext_::tcp_conn_fd, tcp_send_all(), PotrContext_::tcp_send_mutex, PotrServiceDef::type, and window_send_push().

Referenced by send_thread_func().

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

## ◆ flush_packed_peer()

void flush_packed_peer | ( | struct PotrContext_ * | ctx,
|  | PotrPeerContext * | peer,
|  | size_t | packed_len )
| static

Definition at line 369 of file potrSendThread.c.

References PotrContext_::crypto_buf, PotrContext_::crypto_buf_size, PotrPeerContext_::dest_addr, PotrServiceDef::encrypt_enabled, PotrServiceDef::encrypt_key, PotrPacket::flags, get_ms(), PotrContext_::last_send_ms, PotrWindow::next_seq, packet_build_packed(), PACKET_HEADER_SIZE, PotrPacket::payload_len, PotrPeerContext_::peer_id, POTR_CRYPTO_NONCE_SIZE, POTR_CRYPTO_TAG_SIZE, potr_encrypt(), POTR_FLAG_ENCRYPTED, POTR_LOG, POTR_MAX_PATH, POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, PotrPeerContext_::send_window, PotrPeerContext_::send_window_mutex, PotrContext_::send_wire_buf, PotrPacket::seq_num, PotrContext_::service, PotrPacketSessionHdr::service_id, PotrServiceDef::service_id, PotrPacket::session_id, PotrPacketSessionHdr::session_id, PotrPeerContext_::session_id, PotrPacketSessionHdr::session_tv_nsec, PotrPeerContext_::session_tv_nsec, PotrPacketSessionHdr::session_tv_sec, PotrPeerContext_::session_tv_sec, PotrContext_::sock, and window_send_push().

Referenced by send_packed_peer_mode().

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

## ◆ send_packed_peer_mode()

void send_packed_peer_mode | ( | struct PotrContext_ * | ctx,
|  | PotrPayloadElem * | first )
| static

Definition at line 493 of file potrSendThread.c.

References append_payload_elem(), PotrServiceDef::encrypt_enabled, PotrPayloadElem::flags, flush_packed_peer(), PotrContext_::global, PotrGlobalConfig::max_payload, PACKET_HEADER_SIZE, PotrPayloadElem::payload_len, peer_find_by_id(), PotrPayloadElem::peer_id, PotrContext_::peers_mutex, POTR_CRYPTO_TAG_SIZE, POTR_FLAG_MORE_FRAG, POTR_PAYLOAD_ELEM_HDR_SIZE, potr_send_queue_complete(), potr_send_queue_peek(), potr_send_queue_try_pop(), POTR_SUCCESS, PotrContext_::send_queue, PotrContext_::send_wire_buf, and PotrContext_::service.

Referenced by send_thread_func().

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

## ◆ send_thread_func()

void * send_thread_func | ( | void * | arg | ) |
| static

Definition at line 566 of file potrSendThread.c.

References append_payload_elem(), PotrServiceDef::encrypt_enabled, PotrPayloadElem::flags, flush_packed(), get_ms(), PotrContext_::global, PotrContext_::is_multi_peer, PotrGlobalConfig::max_payload, PotrServiceDef::pack_wait_ms, PACKET_HEADER_SIZE, PotrPayloadElem::payload_len, POTR_CRYPTO_TAG_SIZE, POTR_FLAG_MORE_FRAG, POTR_PAYLOAD_ELEM_HDR_SIZE, potr_send_queue_complete(), potr_send_queue_peek(), potr_send_queue_peek_timed(), potr_send_queue_pop(), potr_send_queue_try_pop(), POTR_SUCCESS, send_packed_peer_mode(), PotrContext_::send_queue, PotrContext_::send_thread_running, PotrContext_::send_wire_buf, and PotrContext_::service.

Referenced by potr_send_thread_start().

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

## ◆ potr_send_thread_start()

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

Definition at line 710 of file potrSendThread.c.

References POTR_ERROR, POTR_SUCCESS, PotrContext_::send_thread, send_thread_func(), PotrContext_::send_thread_running, and PotrContext_::send_window_mutex.

Referenced by potrOpenService(), and start_connected_threads().

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

## ◆ potr_send_thread_stop()

void potr_send_thread_stop | ( | struct PotrContext_ * | ctx | ) |

Definition at line 737 of file potrSendThread.c.

References potr_send_queue_shutdown(), PotrContext_::send_queue, PotrContext_::send_thread, PotrContext_::send_thread_running, and PotrContext_::send_window_mutex.

Referenced by potr_connect_thread_stop(), potrCloseService(), potrOpenService(), and start_connected_threads().

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