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

受信テストコマンド。 More...

#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <porter.h>
#include <console-util.h>
Include dependency graph for recv.c:

Go to the source code of this file.

Data Structures

struct  BidirSendCtx
 bidir 送信スレッドに渡すコンテキスト。 More...

Typedefs

typedef pthread_t BidirThread

Functions

static void sig_handler (int sig)
 Linux SIGINT シグナルハンドラー。
static void on_recv (int64_t service_id, PotrPeerId peer_id, PotrEvent event, const void *data, size_t len)
 受信コールバック関数。
static int parse_log_level (const char *str, PotrLogLevel *out)
 ログレベル文字列を PotrLogLevel に変換する。
static int read_line (char *buf, size_t size)
 標準入力から1行読み込み、末尾の改行を取り除く。
static void * bidir_send_thread_func (void *arg)
 bidir 送信スレッド関数 (Linux)。
static int start_bidir_send_thread (BidirThread *thread, BidirSendCtx *ctx)
 bidir 送信スレッドを起動する。
static void join_bidir_send_thread (BidirThread thread)
 bidir 送信スレッドの終了を待機して破棄する。
int main (int argc, char *argv[])
 メインエントリーポイント。

Variables

static volatile int g_running = 1
 受信ループ継続フラグ。シグナルハンドラーで 0 に設定される。

Detailed Description

受信テストコマンド。

Author
c-modernization-kit sample team
Date
2026/03/22
Version
1.2.0

指定サービスでデータを受信し続ける CLI テストコマンドです。
Ctrl+C で終了します。

サービス種別が unicast_bidir の場合は双方向モードで動作します。
双方向モードでは受信待機中に標準入力からメッセージを送信できます (空行で送信終了)。

使用方法
recv [-l <level>] <config_path> <service_id>
オプション
オプション 説明
-l <level> ログレベルを指定します。指定がない場合はログ出力なし。

level に指定可能な値: TRACE, DEBUG, INFO, WARN, ERROR, FATAL (大文字小文字不問)

使用例
recv porter-services.conf 10
recv -l INFO porter-services.conf 10
recv -l DEBUG porter-services.conf 1031

Definition in file recv.c.

Typedef Documentation

◆ BidirThread

typedef pthread_t BidirThread

Definition at line 228 of file recv.c.

Function Documentation

◆ sig_handler()

void sig_handler ( int sig)
static

Linux SIGINT シグナルハンドラー。

Parameters
[in]sigシグナル番号。

Definition at line 67 of file recv.c.

References g_running.

Referenced by main().

Here is the caller graph for this function:

◆ on_recv()

void on_recv ( int64_t service_id,
PotrPeerId peer_id,
PotrEvent event,
const void * data,
size_t len )
static

受信コールバック関数。

Parameters
[in]service_idサービスの ID。
[in]peer_idピア識別子 (N:1 モード時は非ゼロ、1:1 モード時は 0)。
[in]eventイベント種別。
[in]data受信データへのポインタ (POTR_EVENT_DATA 時のみ有効)。
[in]len受信データのバイト数 (POTR_EVENT_DATA 時のみ有効)。

Definition at line 122 of file recv.c.

References POTR_EVENT_CONNECTED, POTR_EVENT_DATA, POTR_EVENT_DISCONNECTED, and POTR_MAX_PAYLOAD.

Referenced by main().

Here is the caller graph for this function:

◆ parse_log_level()

int parse_log_level ( const char * str,
PotrLogLevel * out )
static

ログレベル文字列を PotrLogLevel に変換する。

Parameters
[in]strレベル文字列 (TRACE/DEBUG/INFO/WARN/ERROR/FATAL)。
[out]out変換結果の格納先。
Returns
変換に成功した場合は 1、未知の文字列の場合は 0 を返します。

Definition at line 166 of file recv.c.

References POTR_TRACE_CRITICAL, POTR_TRACE_ERROR, POTR_TRACE_INFO, POTR_TRACE_VERBOSE, and POTR_TRACE_WARNING.

Referenced by main().

Here is the caller graph for this function:

◆ read_line()

int read_line ( char * buf,
size_t size )
static

標準入力から1行読み込み、末尾の改行を取り除く。

Parameters
[out]buf読み込み先バッファ。
[in]sizeバッファサイズ (バイト)。
Returns
入力があれば 1、EOF またはエラーなら 0 を返します。

Definition at line 217 of file recv.c.

Referenced by bidir_send_thread_func().

Here is the caller graph for this function:

◆ bidir_send_thread_func()

void * bidir_send_thread_func ( void * arg)
static

bidir 送信スレッド関数 (Linux)。

Parameters
[in]argBidirSendCtx へのポインタ。
Returns
NULL

Definition at line 237 of file recv.c.

References BidirSendCtx::handle, POTR_MAX_MESSAGE_SIZE, POTR_PEER_NA, POTR_SEND_BLOCKING, POTR_SEND_COMPRESS, POTR_SUCCESS, potrSend(), read_line(), and BidirSendCtx::running.

Referenced by start_bidir_send_thread().

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

◆ start_bidir_send_thread()

int start_bidir_send_thread ( BidirThread * thread,
BidirSendCtx * ctx )
static

bidir 送信スレッドを起動する。

Parameters
[out]threadスレッドハンドルの格納先。
[in]ctxスレッドに渡すコンテキスト。
Returns
成功時は 1、失敗時は 0 を返します。

Definition at line 329 of file recv.c.

References bidir_send_thread_func().

Referenced by main().

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

◆ join_bidir_send_thread()

void join_bidir_send_thread ( BidirThread thread)
static

bidir 送信スレッドの終了を待機して破棄する。

Parameters
[in]threadスレッドハンドル。

Definition at line 350 of file recv.c.

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

メインエントリーポイント。

Parameters
[in]argcコマンドライン引数の数。
[in]argvコマンドライン引数の配列。
Returns
成功時は EXIT_SUCCESS、失敗時は EXIT_FAILURE を返します。

Definition at line 369 of file recv.c.

References g_running, BidirSendCtx::handle, join_bidir_send_thread(), on_recv(), parse_log_level(), POTR_ROLE_RECEIVER, POTR_SUCCESS, POTR_TRACE_NONE, POTR_TYPE_UNICAST_BIDIR, potrCloseService(), potrGetServiceType(), potrLogConfig(), potrOpenServiceFromConfig(), BidirSendCtx::running, sig_handler(), and start_bidir_send_thread().

Here is the call graph for this function:

Variable Documentation

◆ g_running

volatile int g_running = 1
static

受信ループ継続フラグ。シグナルハンドラーで 0 に設定される。

Definition at line 58 of file recv.c.

Referenced by main(), sig_handler(), and sig_handler().