|
Document of c-modernization-kit (porter) 1.0.0
|
potrOpenService 関数の実装。 More...
#include <stdlib.h>#include <inttypes.h>#include <string.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <time.h>#include <porter_const.h>#include <porter.h>#include "../protocol/packet.h"#include "../protocol/window.h"#include "../potrContext.h"#include "../potrPeerTable.h"#include "../thread/potrRecvThread.h"#include "../thread/potrHealthThread.h"#include "../thread/potrConnectThread.h"#include "../infra/compress/compress.h"#include "../infra/potrSendQueue.h"#include "../thread/potrSendThread.h"#include "../util/potrIpAddr.h"#include "../infra/potrLog.h"Go to the source code of this file.
Functions | |
| static PotrSocket | open_socket_unicast (struct in_addr bind_addr, uint16_t port) |
| static void | generate_session (struct PotrContext_ *ctx) |
| static PotrSocket | open_socket_multicast (const PotrServiceDef *def, struct in_addr src_if, int is_receiver) |
| static PotrSocket | open_socket_broadcast (uint16_t src_port, uint16_t dst_port, struct in_addr src_if, int is_receiver) |
| static void | cleanup_sockets (struct PotrContext_ *ctx) |
| static void | ctx_cleanup (struct PotrContext_ *ctx) |
| static int | open_socket_tcp_receiver (struct PotrContext_ *ctx, int path_idx) |
| static int | open_socket_tcp_sender (struct PotrContext_ *ctx, int path_idx) |
| POTR_EXPORT int POTR_API | potrOpenService (const PotrGlobalConfig *global, const PotrServiceDef *service, PotrRole role, PotrRecvCallback callback, PotrHandle *handle) |
| 設定構造体から指定サービスを開きます。 | |
potrOpenService 関数の実装。
Definition in file potrOpenService.c.
|
static |
Definition at line 47 of file potrOpenService.c.
References POTR_INVALID_SOCKET.
Referenced by potrOpenService().
|
static |
Definition at line 85 of file potrOpenService.c.
References PotrContext_::session_id, PotrContext_::session_tv_nsec, and PotrContext_::session_tv_sec.
Referenced by potrOpenService().
|
static |
Definition at line 115 of file potrOpenService.c.
References PotrServiceDef::dst_port, PotrServiceDef::multicast_group, parse_ipv4_addr(), POTR_INVALID_SOCKET, POTR_SUCCESS, and PotrServiceDef::src_port.
Referenced by potrOpenService().
|
static |
Definition at line 211 of file potrOpenService.c.
References POTR_INVALID_SOCKET.
Referenced by potrOpenService().
|
static |
Definition at line 274 of file potrOpenService.c.
References POTR_INVALID_SOCKET, POTR_MAX_PATH, and PotrContext_::sock.
Referenced by ctx_cleanup().
|
static |
Definition at line 293 of file potrOpenService.c.
References cleanup_sockets(), PotrContext_::compress_buf, PotrContext_::crypto_buf, PotrContext_::frag_buf, PotrContext_::is_multi_peer, peer_table_destroy(), PotrContext_::peers, POTR_INVALID_SOCKET, POTR_MAX_PATH, PotrContext_::recv_buf, PotrContext_::recv_window, PotrContext_::send_window, PotrContext_::send_wire_buf, PotrContext_::tcp_conn_fd, PotrContext_::tcp_listen_sock, and window_destroy().
Referenced by potrOpenService().
|
static |
Definition at line 343 of file potrOpenService.c.
References PotrServiceDef::dst_addr, PotrContext_::dst_addr_resolved, PotrServiceDef::dst_port, POTR_ERROR, POTR_INVALID_SOCKET, POTR_SUCCESS, resolve_ipv4_addr(), PotrContext_::service, PotrServiceDef::src_addr, PotrContext_::src_addr_resolved, and PotrContext_::tcp_listen_sock.
Referenced by potrOpenService().
|
static |
Definition at line 417 of file potrOpenService.c.
References PotrServiceDef::dst_addr, PotrContext_::dst_addr_resolved, POTR_ERROR, POTR_LOG, POTR_SUCCESS, POTR_TRACE_ERROR, resolve_ipv4_addr(), PotrContext_::service, PotrServiceDef::src_addr, and PotrContext_::src_addr_resolved.
Referenced by potrOpenService().
| POTR_EXPORT int POTR_API potrOpenService | ( | const PotrGlobalConfig * | global, |
| const PotrServiceDef * | service, | ||
| PotrRole | role, | ||
| PotrRecvCallback | callback, | ||
| PotrHandle * | handle ) |
設定構造体から指定サービスを開きます。
| [in] | global | グローバル設定構造体へのポインタ。 |
| [in] | service | サービス定義構造体へのポインタ。 |
| [in] | role | 役割種別。POTR_ROLE_SENDER または POTR_ROLE_RECEIVER。 |
| [in] | callback | イベント発生時に呼び出されるコールバック関数 (PotrRecvCallback)。 POTR_ROLE_RECEIVER の場合は必須。データ受信・接続検知・切断検知を受け取る。 POTR_ROLE_SENDER の場合は通常 NULL を指定すること。 ただし POTR_TYPE_TCP_BIDIR および POTR_TYPE_UNICAST_BIDIR では SENDER にもコールバックが必須。これらの種別では POTR_ROLE_SENDER でも callback が NULL の場合は失敗を返します。 |
| [out] | handle | 成功時にセッションハンドルを格納するポインタ。 |
設定構造体からサービス定義を取得し、UDP ソケットを初期化します。
role と callback の組み合わせが不正な場合は POTR_ERROR を返します。
role と設定の IP アドレスが不整合 (bind 失敗など) の場合も POTR_ERROR を返します。
通信種別・役割に応じて以下のソケット設定を行います。
| 通信種別 | 役割 | bind アドレス | bind ポート |
|---|---|---|---|
| POTR_TYPE_UNICAST | 送信者 | src_addr | src_port |
| POTR_TYPE_UNICAST | 受信者 | dst_addr | dst_port |
| POTR_TYPE_MULTICAST | 送信者 | INADDR_ANY | src_port |
| POTR_TYPE_MULTICAST | 受信者 | INADDR_ANY | dst_port |
| POTR_TYPE_BROADCAST | 送信者 | src_addr | src_port |
| POTR_TYPE_BROADCAST | 受信者 | INADDR_ANY | dst_port |
POTR_ROLE_RECEIVER の場合、内部で受信スレッドを起動します。
Definition at line 445 of file potrOpenService.c.
References PotrServiceDef::broadcast_addr, PotrContext_::callback, comm_recv_thread_start(), PotrContext_::compress_buf, PotrContext_::compress_buf_size, PotrContext_::crypto_buf, PotrContext_::crypto_buf_size, ctx_cleanup(), PotrContext_::dest_addr, PotrServiceDef::dst_addr, PotrContext_::dst_addr_resolved, PotrServiceDef::dst_port, PotrServiceDef::encrypt_enabled, PotrContext_::frag_buf, generate_session(), PotrContext_::global, PotrGlobalConfig::health_interval_ms, PotrServiceDef::health_interval_ms, PotrContext_::health_mutex, PotrGlobalConfig::health_timeout_ms, PotrServiceDef::health_timeout_ms, PotrContext_::health_wakeup, PotrContext_::is_multi_peer, PotrGlobalConfig::max_message_size, PotrGlobalConfig::max_payload, PotrContext_::max_peers, PotrServiceDef::max_peers, PotrServiceDef::multicast_group, PotrContext_::n_path, open_socket_broadcast(), open_socket_multicast(), open_socket_tcp_receiver(), open_socket_tcp_sender(), open_socket_unicast(), PACKET_HEADER_SIZE, parse_ipv4_addr(), peer_table_init(), POTR_API, POTR_COMPRESS_HEADER_SIZE, potr_connect_thread_start(), POTR_CRYPTO_TAG_SIZE, POTR_ERROR, POTR_EXPORT, potr_health_thread_start(), potr_health_thread_stop(), POTR_INVALID_SOCKET, potr_is_tcp_type(), POTR_LOG, POTR_MAX_PATH, POTR_MAX_PAYLOAD, POTR_MAX_WINDOW_SIZE, potr_raw_base_type(), POTR_ROLE_RECEIVER, POTR_ROLE_SENDER, potr_send_queue_destroy(), potr_send_queue_init(), potr_send_thread_start(), potr_send_thread_stop(), POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_INFO, POTR_TRACE_VERBOSE, POTR_TYPE_BROADCAST, POTR_TYPE_BROADCAST_RAW, POTR_TYPE_MULTICAST, POTR_TYPE_MULTICAST_RAW, POTR_TYPE_TCP, POTR_TYPE_TCP_BIDIR, POTR_TYPE_UNICAST, POTR_TYPE_UNICAST_BIDIR, POTR_TYPE_UNICAST_BIDIR_N1, POTR_TYPE_UNICAST_RAW, PotrContext_::recv_buf, PotrContext_::recv_window, PotrContext_::recv_window_mutex, resolve_ipv4_addr(), PotrContext_::role, PotrContext_::send_queue, PotrGlobalConfig::send_queue_depth, PotrContext_::send_window, PotrContext_::send_wire_buf, PotrContext_::service, PotrServiceDef::service_id, PotrContext_::sock, PotrServiceDef::src_addr, PotrContext_::src_addr_resolved, PotrServiceDef::src_port, PotrContext_::tcp_conn_fd, PotrGlobalConfig::tcp_health_interval_ms, PotrGlobalConfig::tcp_health_timeout_ms, PotrContext_::tcp_listen_sock, PotrContext_::tcp_send_mutex, PotrContext_::tcp_state_cv, PotrContext_::tcp_state_mutex, PotrServiceDef::type, window_init(), and PotrGlobalConfig::window_size.
Referenced by potrOpenServiceFromConfig().