|
Document of c-modernization-kit (porter) 1.0.0
|
TCP サーバーサンプル共通定義。 More...
#include <sys/types.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | get_pid() |
| 現在のプロセス ID を取得する。 | |
| #define | client_recv(fd, buf, len) |
| クライアントからデータを受信する。 | |
| #define | client_send(fd, buf, len) |
| クライアントへデータを送信する。 | |
| #define | client_close(fd) |
| クライアントソケットを閉じる。 | |
| #define | DEFAULT_PORT 8080 |
| デフォルト待ち受けポート番号。 | |
| #define | DEFAULT_WORKERS 4 |
| デフォルト prefork ワーカー数。 | |
| #define | DEFAULT_CONNS_PER_WORKER 1 |
| デフォルト 1 ワーカーあたりの同時接続数。 | |
| #define | BUFFER_SIZE 1024 |
| 送受信バッファサイズ (バイト)。 | |
Typedefs | |
| typedef int | ClientFd |
| クライアントソケットの型。Linux では int、Windows では SOCKET。 | |
| typedef pid_t | PidType |
| プロセス ID の型。Linux では pid_t、Windows では DWORD。 | |
| typedef void(* | ClientSessionFn) (ClientFd fd) |
| セッション処理関数の型。 | |
Enumerations | |
| enum | ServerMode { MODE_PREFORK = 0 , MODE_FORK = 1 } |
| サーバー動作モード。 More... | |
Functions | |
| void | handle_client_session (ClientFd fd) |
| TCP 通信メインループ (デフォルト実装)。 | |
| void | platform_init (ClientSessionFn session_fn) |
| プラットフォーム初期化 (Windows: WSAStartup / Linux: no-op)。 | |
| void | platform_cleanup (void) |
| プラットフォーム後処理 (Windows: WSACleanup / Linux: no-op)。 | |
| int | dispatch_internal_args (int argc, char *argv[]) |
| 内部起動引数を処理します。 | |
| void | run_fork_server (int port) |
| fork モードのサーバーを起動します。 | |
| void | run_prefork_server (int port, int num_workers, int conns_per_worker) |
| prefork モードのサーバーを起動します。 | |
Variables | |
| ClientSessionFn | g_session_fn |
| 登録済みセッション処理関数。 | |
TCP サーバーサンプル共通定義。
Definition in file tcpServer.h.
| #define get_pid | ( | ) |
現在のプロセス ID を取得する。
Definition at line 34 of file tcpServer.h.
Referenced by handle_client_session(), run_fork_server(), run_prefork_server(), and worker_loop().
| #define client_recv | ( | fd, | |
| buf, | |||
| len ) |
クライアントからデータを受信する。
Definition at line 36 of file tcpServer.h.
Referenced by handle_client_session(), and worker_loop().
| #define client_send | ( | fd, | |
| buf, | |||
| len ) |
クライアントへデータを送信する。
Definition at line 38 of file tcpServer.h.
Referenced by handle_client_session(), and worker_loop().
| #define client_close | ( | fd | ) |
クライアントソケットを閉じる。
Definition at line 40 of file tcpServer.h.
Referenced by handle_client_session(), and worker_loop().
| #define DEFAULT_PORT 8080 |
| #define DEFAULT_WORKERS 4 |
| #define DEFAULT_CONNS_PER_WORKER 1 |
| #define BUFFER_SIZE 1024 |
送受信バッファサイズ (バイト)。
Definition at line 76 of file tcpServer.h.
Referenced by handle_client_session(), and worker_loop().
| typedef int ClientFd |
クライアントソケットの型。Linux では int、Windows では SOCKET。
Definition at line 29 of file tcpServer.h.
| typedef pid_t PidType |
プロセス ID の型。Linux では pid_t、Windows では DWORD。
Definition at line 31 of file tcpServer.h.
| typedef void(* ClientSessionFn) (ClientFd fd) |
| enum ServerMode |
サーバー動作モード。
| Enumerator | ||
|---|---|---|
| MODE_PREFORK | 0 | プリフォークモード (デフォルト)。 |
| MODE_FORK | 1 | 接続ごと fork モード。 |
Definition at line 87 of file tcpServer.h.
| void handle_client_session | ( | ClientFd | fd | ) |
TCP 通信メインループ (デフォルト実装)。
| [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().
| void platform_init | ( | ClientSessionFn | session_fn | ) |
プラットフォーム初期化 (Windows: WSAStartup / Linux: no-op)。
| [in] | session_fn | セッション処理関数。g_session_fn に保存されます。 |
Definition at line 254 of file tcpServer_linux.c.
References g_session_fn.
Referenced by main().
| void platform_cleanup | ( | void | ) |
プラットフォーム後処理 (Windows: WSACleanup / Linux: no-op)。
Definition at line 259 of file tcpServer_linux.c.
Referenced by main().
| int dispatch_internal_args | ( | int | argc, |
| char * | argv[] ) |
内部起動引数を処理します。
| [in] | argc | コマンドライン引数の数。 |
| [in] | argv | コマンドライン引数の配列。 |
Windows では --child <handle> / --worker <pipe> を検出して処理します。 Linux では常に 0 を返します。
Definition at line 264 of file tcpServer_linux.c.
Referenced by main().
| void run_fork_server | ( | int | port | ) |
fork モードのサーバーを起動します。
| [in] | port | 待ち受けポート番号。 |
Definition at line 275 of file tcpServer_linux.c.
References create_listen_socket(), g_session_fn, get_pid, and sigchld_handler().
Referenced by main().
| void run_prefork_server | ( | int | port, |
| int | num_workers, | ||
| int | conns_per_worker ) |
prefork モードのサーバーを起動します。
| [in] | port | 待ち受けポート番号。 |
| [in] | num_workers | 事前生成するワーカープロセス数。 |
| [in] | conns_per_worker | 1 ワーカーあたりの同時接続数。 1 の場合は従来の逐次処理。 2 以上の場合はイベント駆動型の多重接続処理。 |
Definition at line 316 of file tcpServer_linux.c.
References create_listen_socket(), get_pid, running, shutdown_handler(), sigchld_handler(), and worker_loop().
Referenced by main().
|
extern |
登録済みセッション処理関数。
platform_init() で設定します。
登録済みセッション処理関数。
Definition at line 19 of file tcpServer_common.c.
Referenced by platform_init(), run_fork_server(), and worker_loop().