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

TCP サーバーサンプル共通実装。 More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <console-util.h>
#include "tcpServer.h"
Include dependency graph for tcpServer.c:

Go to the source code of this file.

Functions

void handle_client_session (ClientFd fd)
 TCP 通信メインループ (デフォルト実装)。
static void parse_args (int argc, char *argv[], ServerMode *mode, int *port, int *workers, int *conns_per_worker)
 コマンドライン引数を解析します。
int main (int argc, char *argv[])
 メインエントリーポイント。

Detailed Description

TCP サーバーサンプル共通実装。

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

プラットフォーム共通の処理を実装します。

プラットフォーム差異は tcpServer.h のマクロ (ClientFd / client_recv / client_send / client_close / get_pid) および各プラットフォームファイルが実装するフック関数 (platform_init / platform_cleanup / dispatch_internal_args) で吸収します。

Definition in file tcpServer.c.

Function Documentation

◆ handle_client_session()

void handle_client_session ( ClientFd fd)

TCP 通信メインループ (デフォルト実装)。

Parameters
[in]fdクライアントソケット。

受信したデータをそのまま返します。クライアントが切断すると戻ります。 ソケットは本関数内で閉じます。fork モード・prefork モード共用。

Definition at line 34 of file tcpServer.c.

References BUFFER_SIZE, client_close, client_recv, client_send, and get_pid.

Referenced by main().

Here is the caller graph for this function:

◆ parse_args()

void parse_args ( int argc,
char * argv[],
ServerMode * mode,
int * port,
int * workers,
int * conns_per_worker )
static

コマンドライン引数を解析します。

Parameters
[in]argc引数の数。
[in]argv引数の配列。
[out]mode動作モード (MODE_FORK / MODE_PREFORK)。
[out]port待ち受けポート番号。
[out]workersワーカー数。
[out]conns_per_worker1 ワーカーあたりの同時接続数。

--mode fork|prefork / --port <num> / --workers <num> / --conns-per-worker <num> を解析します。 内部起動引数 (--child, --worker) は dispatch_internal_args() で処理済みの ため、本関数では無視します。

Definition at line 66 of file tcpServer.c.

References MODE_FORK, and MODE_PREFORK.

Referenced by main().

Here is the caller graph for this function:

◆ main()

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

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

Parameters
[in]argcコマンドライン引数の数。
[in]argvコマンドライン引数の配列。
Returns
正常終了時は 0 を返します。
  1. platform_init() でプラットフォーム初期化。
  2. dispatch_internal_args() で内部起動引数 (–child / –worker) を確認。 処理済みの場合は platform_cleanup() して終了します。
  3. parse_args() でモード・ポート・ワーカー数を解析。
  4. 指定されたモードでサーバーを起動します。

Definition at line 101 of file tcpServer.c.

References DEFAULT_CONNS_PER_WORKER, DEFAULT_PORT, DEFAULT_WORKERS, dispatch_internal_args(), handle_client_session(), MODE_FORK, MODE_PREFORK, parse_args(), platform_cleanup(), platform_init(), run_fork_server(), and run_prefork_server().

Here is the call graph for this function: