|
Document of c-modernization-kit (porter) 1.0.0
|
TCP 接続管理スレッドモジュール。 More...
#include <stdlib.h>#include <inttypes.h>#include <string.h>#include <sys/socket.h>#include <sys/select.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <time.h>#include <porter_const.h>#include "../potrContext.h"#include "../protocol/packet.h"#include "../infra/potrSendQueue.h"#include "../protocol/window.h"#include "../infra/potrLog.h"#include "potrConnectThread.h"#include "potrRecvThread.h"#include "potrSendThread.h"#include "potrHealthThread.h"Go to the source code of this file.
Data Structures | |
| struct | ConnectArg |
Macros | |
| #define | TCP_SESSION_NEW ( 1) /* 新セッション (または初回接続) */ |
| #define | TCP_SESSION_SAME ( 0) /* 同一セッション */ |
| #define | TCP_SESSION_OLD (-1) /* 旧セッション (破棄すべき) */ |
Functions | |
| static uint64_t | connect_get_ms (void) |
| static void | close_tcp_conn (struct PotrContext_ *ctx, int path_idx) |
| static void | reconnect_wait (struct PotrContext_ *ctx, int path_idx, uint32_t wait_ms) |
| static int | accept_tcp_read_all (PotrSocket fd, uint8_t *buf, size_t n) |
| static int | accept_tcp_wait_readable (PotrSocket fd, uint32_t wait_ms) |
| static int | tcp_read_first_packet (PotrSocket fd, uint8_t *buf, size_t max_buf, size_t *out_len, uint32_t timeout_ms) |
| static int | tcp_session_compare (const struct PotrContext_ *ctx, const PotrPacket *pkt) |
| static void | join_recv_thread (struct PotrContext_ *ctx, int path_idx) |
| static void | reset_connection_state (struct PotrContext_ *ctx) |
| static void | reset_all_paths_disconnected (struct PotrContext_ *ctx) |
| static void | reset_send_queue (struct PotrContext_ *ctx) |
| static int | start_connected_threads (struct PotrContext_ *ctx, int path_idx) |
| static void | stop_connected_threads (struct PotrContext_ *ctx, int path_idx) |
| static PotrSocket | tcp_connect_with_timeout (struct PotrContext_ *ctx, int path_idx) |
| static void | sender_connect_loop (struct PotrContext_ *ctx, int path_idx) |
| static void | receiver_accept_loop (struct PotrContext_ *ctx, int path_idx) |
| static void * | connect_thread_func (void *arg) |
| int | potr_connect_thread_start (struct PotrContext_ *ctx) |
| TCP 接続管理スレッドを起動します (path 数分)。 | |
| void | potr_connect_thread_stop (struct PotrContext_ *ctx) |
| TCP 接続管理スレッドを停止します。 | |
Variables | |
| static ConnectArg | s_connect_args [POTR_MAX_PATH] |
TCP 接続管理スレッドモジュール。
SENDER: TCP connect/reconnect ループを管理するスレッドです。
RECEIVER: TCP accept ループを管理するスレッドです。
接続確立後、送受信・ヘルスチェックスレッドを起動し、
recv スレッドが切断を検知して終了するまで待機してから再接続サイクルへ移行します。
Definition in file potrConnectThread.c.
| #define TCP_SESSION_NEW ( 1) /* 新セッション (または初回接続) */ |
Definition at line 217 of file potrConnectThread.c.
Referenced by receiver_accept_loop(), and tcp_session_compare().
| #define TCP_SESSION_SAME ( 0) /* 同一セッション */ |
Definition at line 218 of file potrConnectThread.c.
Referenced by tcp_session_compare().
| #define TCP_SESSION_OLD (-1) /* 旧セッション (破棄すべき) */ |
Definition at line 219 of file potrConnectThread.c.
Referenced by receiver_accept_loop(), and tcp_session_compare().
|
static |
Definition at line 62 of file potrConnectThread.c.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 74 of file potrConnectThread.c.
References POTR_INVALID_SOCKET, and PotrContext_::tcp_conn_fd.
Referenced by receiver_accept_loop(), start_connected_threads(), and stop_connected_threads().
|
static |
Definition at line 90 of file potrConnectThread.c.
References PotrContext_::connect_thread_running, PotrContext_::tcp_state_cv, and PotrContext_::tcp_state_mutex.
Referenced by sender_connect_loop().
|
static |
Definition at line 127 of file potrConnectThread.c.
Referenced by tcp_read_first_packet().
|
static |
Definition at line 150 of file potrConnectThread.c.
Referenced by tcp_read_first_packet().
|
static |
Definition at line 179 of file potrConnectThread.c.
References accept_tcp_read_all(), accept_tcp_wait_readable(), and PACKET_HEADER_SIZE.
Referenced by receiver_accept_loop().
|
static |
Definition at line 224 of file potrConnectThread.c.
References PotrContext_::peer_session_id, PotrContext_::peer_session_known, PotrContext_::peer_session_tv_nsec, PotrContext_::peer_session_tv_sec, PotrPacket::session_id, PotrPacket::session_tv_nsec, PotrPacket::session_tv_sec, TCP_SESSION_NEW, TCP_SESSION_OLD, and TCP_SESSION_SAME.
Referenced by receiver_accept_loop().
|
static |
Definition at line 240 of file potrConnectThread.c.
References PotrContext_::recv_thread.
Referenced by receiver_accept_loop(), sender_connect_loop(), and start_connected_threads().
|
static |
Definition at line 259 of file potrConnectThread.c.
References PotrContext_::frag_buf_len, and PotrContext_::peer_session_known.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 268 of file potrConnectThread.c.
References PotrWindow::base_seq, PotrContext_::callback, PotrContext_::frag_buf_len, PotrContext_::health_alive, PotrWindow::next_seq, PotrContext_::peer_session_known, POTR_EVENT_DISCONNECTED, POTR_LOG, POTR_PEER_NA, POTR_TRACE_INFO, PotrContext_::send_window, PotrContext_::service, PotrServiceDef::service_id, PotrWindow::valid, and PotrWindow::window_size.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 295 of file potrConnectThread.c.
References PotrSendQueue::depth, PotrContext_::global, PotrGlobalConfig::max_payload, potr_send_queue_destroy(), potr_send_queue_init(), and PotrContext_::send_queue.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 308 of file potrConnectThread.c.
References close_tcp_conn(), join_recv_thread(), POTR_ERROR, POTR_LOG, POTR_ROLE_SENDER, potr_send_thread_start(), potr_send_thread_stop(), POTR_SUCCESS, potr_tcp_health_thread_start(), POTR_TRACE_ERROR, POTR_TYPE_TCP_BIDIR, PotrContext_::role, PotrContext_::running, PotrContext_::send_thread_running, PotrContext_::service, PotrServiceDef::service_id, tcp_recv_thread_start(), and PotrServiceDef::type.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 363 of file potrConnectThread.c.
References close_tcp_conn(), POTR_ROLE_SENDER, potr_tcp_health_thread_stop(), POTR_TYPE_TCP_BIDIR, PotrContext_::role, PotrContext_::service, and PotrServiceDef::type.
Referenced by receiver_accept_loop(), and sender_connect_loop().
|
static |
Definition at line 381 of file potrConnectThread.c.
References PotrServiceDef::connect_timeout_ms, PotrContext_::dst_addr_resolved, PotrServiceDef::dst_port, POTR_INVALID_SOCKET, POTR_LOG, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, PotrContext_::service, PotrServiceDef::service_id, PotrServiceDef::src_addr, PotrContext_::src_addr_resolved, and PotrServiceDef::src_port.
Referenced by sender_connect_loop().
|
static |
Definition at line 634 of file potrConnectThread.c.
References connect_get_ms(), PotrContext_::connect_thread_running, PotrServiceDef::dst_addr, PotrServiceDef::dst_port, join_recv_thread(), POTR_INVALID_SOCKET, POTR_LOG, POTR_SUCCESS, POTR_TRACE_INFO, POTR_TRACE_VERBOSE, PotrServiceDef::reconnect_interval_ms, reconnect_wait(), reset_all_paths_disconnected(), reset_connection_state(), reset_send_queue(), PotrContext_::service, PotrServiceDef::service_id, start_connected_threads(), stop_connected_threads(), PotrContext_::tcp_active_paths, PotrContext_::tcp_conn_fd, tcp_connect_with_timeout(), PotrContext_::tcp_last_ping_recv_ms, PotrContext_::tcp_last_ping_req_recv_ms, and PotrContext_::tcp_state_mutex.
Referenced by connect_thread_func().
|
static |
Definition at line 783 of file potrConnectThread.c.
References close_tcp_conn(), connect_get_ms(), PotrContext_::connect_thread_running, PotrContext_::global, join_recv_thread(), PotrGlobalConfig::max_payload, PotrContext_::n_path, PACKET_HEADER_SIZE, packet_parse(), PotrContext_::peer_session_id, POTR_INVALID_SOCKET, POTR_LOG, POTR_SUCCESS, POTR_TRACE_INFO, POTR_TRACE_VERBOSE, POTR_TRACE_WARNING, POTR_TYPE_TCP_BIDIR, reset_all_paths_disconnected(), reset_connection_state(), reset_send_queue(), PotrContext_::running, PotrContext_::service, PotrServiceDef::service_id, PotrContext_::session_establish_mutex, PotrPacket::session_id, PotrServiceDef::src_addr, PotrContext_::src_addr_resolved, PotrServiceDef::src_port, start_connected_threads(), stop_connected_threads(), PotrContext_::tcp_active_paths, PotrContext_::tcp_conn_fd, PotrContext_::tcp_first_pkt_buf, PotrContext_::tcp_first_pkt_len, PotrGlobalConfig::tcp_health_timeout_ms, PotrContext_::tcp_last_ping_recv_ms, PotrContext_::tcp_last_ping_req_recv_ms, PotrContext_::tcp_listen_sock, tcp_read_first_packet(), tcp_session_compare(), TCP_SESSION_NEW, TCP_SESSION_OLD, PotrContext_::tcp_state_mutex, and PotrServiceDef::type.
Referenced by connect_thread_func().
|
static |
Definition at line 1034 of file potrConnectThread.c.
References PotrContext_::connect_thread_running, ConnectArg::ctx, ConnectArg::path_idx, POTR_LOG, POTR_ROLE_SENDER, POTR_TRACE_VERBOSE, POTR_TYPE_TCP_BIDIR, receiver_accept_loop(), PotrContext_::role, sender_connect_loop(), PotrContext_::service, PotrServiceDef::service_id, and PotrServiceDef::type.
Referenced by potr_connect_thread_start().
| int potr_connect_thread_start | ( | struct PotrContext_ * | ctx | ) |
TCP 接続管理スレッドを起動します (path 数分)。
TCP 接続管理スレッドを起動します。
| [in,out] | ctx | セッションコンテキストへのポインタ。 |
呼び出し前提:
Definition at line 1084 of file potrConnectThread.c.
References PotrContext_::connect_thread, connect_thread_func(), PotrContext_::connect_thread_running, PotrContext_::global, PotrGlobalConfig::max_payload, PotrContext_::n_path, PACKET_HEADER_SIZE, POTR_ERROR, POTR_LOG, POTR_ROLE_RECEIVER, POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_VERBOSE, PotrContext_::role, s_connect_args, PotrContext_::service, PotrServiceDef::service_id, PotrContext_::session_establish_mutex, PotrContext_::tcp_first_pkt_buf, and PotrContext_::tcp_first_pkt_len.
Referenced by potrOpenService().
| void potr_connect_thread_stop | ( | struct PotrContext_ * | ctx | ) |
TCP 接続管理スレッドを停止します。
| [in,out] | ctx | セッションコンテキストへのポインタ。 |
Definition at line 1183 of file potrConnectThread.c.
References PotrContext_::connect_thread, PotrContext_::connect_thread_running, PotrContext_::n_path, POTR_INVALID_SOCKET, POTR_LOG, POTR_ROLE_RECEIVER, potr_send_thread_stop(), POTR_TRACE_VERBOSE, PotrContext_::role, PotrContext_::service, PotrServiceDef::service_id, PotrContext_::session_establish_mutex, PotrContext_::tcp_conn_fd, PotrContext_::tcp_first_pkt_buf, PotrContext_::tcp_first_pkt_len, PotrContext_::tcp_listen_sock, PotrContext_::tcp_state_cv, and PotrContext_::tcp_state_mutex.
Referenced by potrCloseService().
|
static |
Definition at line 59 of file potrConnectThread.c.
Referenced by potr_connect_thread_start().