Document of c-modernization-kit (porter) 1.0.0
Loading...
Searching...
No Matches
window.c File Reference

スライディングウィンドウ管理モジュール。 More...

#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <porter_const.h>
#include "seqnum.h"
#include "window.h"
Include dependency graph for window.c:

Go to the source code of this file.

Functions

int window_init (PotrWindow *win, uint32_t initial_seq, uint16_t window_size, uint16_t max_payload)
 ウィンドウを初期化します。
void window_destroy (PotrWindow *win)
 ウィンドウが保持する動的確保バッファを解放します。
static uint16_t win_index (const PotrWindow *win, uint32_t seq)
int window_send_push (PotrWindow *win, const PotrPacket *packet)
 送信ウィンドウにパケットを積みます。
int window_send_full (const PotrWindow *win)
 送信ウィンドウが満杯かどうかを返します。
int window_send_get (const PotrWindow *win, uint32_t seq_num, PotrPacket *packet_out)
 送信ウィンドウから指定通番のパケットを取得します (再送用)。
int window_recv_push (PotrWindow *win, const PotrPacket *packet)
 受信ウィンドウにパケットを格納します。
int window_recv_pop (PotrWindow *win, PotrPacket *packet)
 受信ウィンドウから順序整列済みパケットを取り出します。
void window_recv_skip (PotrWindow *win, uint32_t seq_num)
 受信ウィンドウで指定通番をスキップして次の通番へ前進させます。
int window_recv_needs_nack (const PotrWindow *win, uint32_t *nack_num)
 受信ウィンドウで欠番が発生しているか確認し、NACK 番号を返します。
void window_recv_reset (PotrWindow *win, uint32_t new_base_seq)
 受信ウィンドウを新しい基点通番でリセットします。

Detailed Description

スライディングウィンドウ管理モジュール。

Author
c-modernization-kit sample team
Date
2026/03/04
Version
1.0.0

Definition in file window.c.

Function Documentation

◆ window_init()

int window_init ( PotrWindow * win,
uint32_t initial_seq,
uint16_t window_size,
uint16_t max_payload )

ウィンドウを初期化します。

Parameters
[in,out]win初期化するウィンドウ構造体へのポインタ。
[in]initial_seq初期通番。
[in]window_sizeウィンドウサイズ (パケット数)。
[in]max_payloadエントリごとのペイロード最大長 (バイト)。
Returns
成功時は POTR_SUCCESS、malloc 失敗時は POTR_ERROR を返します。

サイズが既存と同一の場合は状態をリセットするのみで再確保は行いません。
異なるサイズの場合は既存バッファを解放して再確保します。

Definition at line 42 of file window.c.

References PotrWindow::base_seq, PotrWindow::max_payload, PotrWindow::next_seq, PotrWindow::packets, PotrPacket::payload, PotrWindow::payload_pool, POTR_ERROR, POTR_SUCCESS, PotrWindow::valid, and PotrWindow::window_size.

Referenced by check_and_update_session(), check_health_timeout(), check_reorder_timeout(), n1_check_and_update_session(), peer_create(), potrOpenService(), and recv_thread_func().

Here is the caller graph for this function:

◆ window_destroy()

void window_destroy ( PotrWindow * win)

ウィンドウが保持する動的確保バッファを解放します。

Parameters
[in,out]win解放するウィンドウ構造体へのポインタ。

Definition at line 110 of file window.c.

References PotrWindow::packets, PotrWindow::payload_pool, and PotrWindow::valid.

Referenced by ctx_cleanup(), peer_create(), peer_free(), peer_table_destroy(), and potrCloseService().

Here is the caller graph for this function:

◆ win_index()

uint16_t win_index ( const PotrWindow * win,
uint32_t seq )
static

Definition at line 126 of file window.c.

References PotrWindow::base_seq, and PotrWindow::window_size.

Referenced by window_recv_needs_nack(), window_recv_pop(), window_recv_push(), window_recv_skip(), window_send_get(), and window_send_push().

Here is the caller graph for this function:

◆ window_send_push()

int window_send_push ( PotrWindow * win,
const PotrPacket * packet )

送信ウィンドウにパケットを積みます。

Parameters
[in,out]win送信ウィンドウ構造体へのポインタ。
[in]packet積むパケットへのポインタ。
Returns
成功時は POTR_SUCCESS、ウィンドウ満杯の場合は POTR_ERROR を返します。

Definition at line 141 of file window.c.

References PotrWindow::base_seq, PotrWindow::max_payload, PotrWindow::next_seq, PotrWindow::packets, PotrPacket::payload, PotrPacket::payload_len, PotrWindow::payload_pool, POTR_ERROR, POTR_SUCCESS, PotrWindow::valid, win_index(), and window_send_full().

Referenced by flush_packed(), and flush_packed_peer().

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

◆ window_send_full()

int window_send_full ( const PotrWindow * win)

送信ウィンドウが満杯かどうかを返します。

Parameters
[in]win送信ウィンドウ構造体へのポインタ。
Returns
満杯の場合は 1、空きがある場合は 0 を返します。

Definition at line 184 of file window.c.

References PotrWindow::base_seq, PotrWindow::next_seq, and PotrWindow::window_size.

Referenced by window_send_push().

Here is the caller graph for this function:

◆ window_send_get()

int window_send_get ( const PotrWindow * win,
uint32_t seq_num,
PotrPacket * packet_out )

送信ウィンドウから指定通番のパケットを取得します (再送用)。

Parameters
[in]win送信ウィンドウ構造体へのポインタ。
[in]seq_num取得する通番。
[out]packet_out取得したパケットを格納する構造体へのポインタ。
Returns
成功時は POTR_SUCCESS、エントリが存在しない場合は POTR_ERROR を返します。

Definition at line 202 of file window.c.

References PotrWindow::base_seq, PotrWindow::next_seq, PotrWindow::packets, POTR_ERROR, POTR_SUCCESS, seqnum_in_window(), PotrWindow::valid, and win_index().

Referenced by recv_thread_func().

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

◆ window_recv_push()

int window_recv_push ( PotrWindow * win,
const PotrPacket * packet )

受信ウィンドウにパケットを格納します。

Parameters
[in,out]win受信ウィンドウ構造体へのポインタ。
[in]packet格納するパケットへのポインタ。
Returns
成功時は POTR_SUCCESS、ウィンドウ外の場合は POTR_ERROR を返します。

通番が受信ウィンドウ内であればバッファリングします。
追い越し (順序外到着) にも対応します。

Definition at line 242 of file window.c.

References PotrWindow::base_seq, PotrWindow::max_payload, PotrWindow::packets, PotrPacket::payload, PotrPacket::payload_len, PotrWindow::payload_pool, POTR_ERROR, POTR_SUCCESS, PotrPacket::seq_num, seqnum_in_window(), PotrWindow::valid, win_index(), and PotrWindow::window_size.

Referenced by n1_process_outer_pkt(), process_outer_pkt(), and tcp_recv_thread_func().

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

◆ window_recv_pop()

int window_recv_pop ( PotrWindow * win,
PotrPacket * packet )

受信ウィンドウから順序整列済みパケットを取り出します。

Parameters
[in,out]win受信ウィンドウ構造体へのポインタ。
[out]packet取り出したパケットを格納する構造体へのポインタ。
Returns
取り出せた場合は POTR_SUCCESS、次のパケットが未着の場合は POTR_ERROR を返します。

Definition at line 279 of file window.c.

References PotrWindow::base_seq, PotrWindow::next_seq, PotrWindow::packets, POTR_ERROR, POTR_SUCCESS, PotrWindow::valid, and win_index().

Referenced by drain_recv_window(), n1_drain_recv_window(), and tcp_recv_thread_func().

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

◆ window_recv_skip()

void window_recv_skip ( PotrWindow * win,
uint32_t seq_num )

受信ウィンドウで指定通番をスキップして次の通番へ前進させます。

Parameters
[in,out]win受信ウィンドウ構造体へのポインタ。
[in]seq_numスキップする通番。next_seq と一致する場合のみ動作します。

REJECT 受信時に欠落パケットを「配信済み」として扱い、後続パケットの配信を 継続するために使用します。seq_num が next_seq と一致しない場合は何もしません。

Definition at line 313 of file window.c.

References PotrWindow::base_seq, PotrWindow::next_seq, PotrWindow::valid, and win_index().

Referenced by recv_thread_func().

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

◆ window_recv_needs_nack()

int window_recv_needs_nack ( const PotrWindow * win,
uint32_t * nack_num )

受信ウィンドウで欠番が発生しているか確認し、NACK 番号を返します。

Parameters
[in]win受信ウィンドウ構造体へのポインタ。
[out]nack_num欠番の通番を格納するポインタ。
Returns
欠番がある場合は 1、ない場合は 0 を返します。

Definition at line 336 of file window.c.

References PotrWindow::next_seq, PotrWindow::valid, win_index(), and PotrWindow::window_size.

Referenced by n1_process_outer_pkt(), and process_outer_pkt().

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

◆ window_recv_reset()

void window_recv_reset ( PotrWindow * win,
uint32_t new_base_seq )

受信ウィンドウを新しい基点通番でリセットします。

Parameters
[in,out]win受信ウィンドウ構造体へのポインタ。
[in]new_base_seqリセット後の基点通番 (次に期待する通番)。

全スロットを無効化し、base_seq / next_seq を new_base_seq に設定します。
バッファの再確保は行いません。
RAW モードでギャップを検出してセッションをリセットする際に使用します。

Definition at line 378 of file window.c.

References PotrWindow::base_seq, PotrWindow::next_seq, PotrWindow::valid, and PotrWindow::window_size.

Referenced by process_outer_pkt(), and recv_thread_func().

Here is the caller graph for this function: