25 #include <sys/types.h>
34 #define get_pid() ((PidType)getpid())
36 #define client_recv(fd, buf, len) read((fd), (buf), (len))
38 #define client_send(fd, buf, len) write((fd), (buf), (len))
40 #define client_close(fd) close(fd)
44 #define WIN32_LEAN_AND_MEAN
55 #define get_pid() ((PidType)GetCurrentProcessId())
57 #define client_recv(fd, buf, len) recv((fd), (buf), (int)(len), 0)
59 #define client_send(fd, buf, len) send((fd), (buf), (int)(len), 0)
61 #define client_close(fd) closesocket(fd)
70#define DEFAULT_PORT 8080
72#define DEFAULT_WORKERS 4
74#define DEFAULT_CONNS_PER_WORKER 1
76#define BUFFER_SIZE 1024
void(* ClientSessionFn)(ClientFd fd)
セッション処理関数の型。
void platform_init(ClientSessionFn session_fn)
プラットフォーム初期化 (Windows: WSAStartup / Linux: no-op)。
@ MODE_FORK
接続ごと fork モード。
@ MODE_PREFORK
プリフォークモード (デフォルト)。
int dispatch_internal_args(int argc, char *argv[])
内部起動引数を処理します。
void platform_cleanup(void)
プラットフォーム後処理 (Windows: WSACleanup / Linux: no-op)。
void run_prefork_server(int port, int num_workers, int conns_per_worker)
prefork モードのサーバーを起動します。
ClientSessionFn g_session_fn
登録済みセッション処理関数。
void run_fork_server(int port)
fork モードのサーバーを起動します。
int ClientFd
クライアントソケットの型。Linux では int、Windows では SOCKET。
void handle_client_session(ClientFd fd)
TCP 通信メインループ (デフォルト実装)。
pid_t PidType
プロセス ID の型。Linux では pid_t、Windows では DWORD。