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

potrCloseService 関数の実装。 More...

#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <porter_const.h>
#include <porter.h>
#include "../potrContext.h"
#include "../potrPeerTable.h"
#include "../thread/potrRecvThread.h"
#include "../thread/potrHealthThread.h"
#include "../thread/potrConnectThread.h"
#include "../infra/potrSendQueue.h"
#include "../thread/potrSendThread.h"
#include "../protocol/packet.h"
#include "../protocol/window.h"
#include "../util/potrIpAddr.h"
#include "../infra/potrLog.h"
#include "../infra/crypto/crypto.h"
Include dependency graph for potrCloseService.c:

Go to the source code of this file.

Functions

static void send_fin (struct PotrContext_ *ctx)
POTR_EXPORT int POTR_API potrCloseService (PotrHandle handle)
 サービスを閉じます。

Detailed Description

potrCloseService 関数の実装。

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

Definition in file potrCloseService.c.

Function Documentation

◆ send_fin()

◆ potrCloseService()

POTR_EXPORT int POTR_API potrCloseService ( PotrHandle handle)

サービスを閉じます。

Parameters
[in]handlepotrOpenService() で取得したセッションハンドル。
Returns
成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

受信スレッドを停止し、ソケットをクローズしてリソースを解放します。
マルチキャストの場合はグループから離脱します。
本関数呼び出し後、handle は無効となります。

Note
本関数呼び出し時、POTR_EVENT_DISCONNECTED コールバックは発火しません。
アプリケーション自身が明示的にサービスを閉じる操作は、接続状態変化イベントとして通知しない設計です。
UDP 通信種別の送信者 (POTR_ROLE_SENDER) が本関数を呼び出した場合は、POTR_FLAG_FIN パケットが送信されます。
TCP 通信種別 (POTR_TYPE_TCP / POTR_TYPE_TCP_BIDIR) では close() による TCP 切断が FIN 相当として機能します。
いずれの場合も、相手側では POTR_EVENT_DISCONNECTED が発火します。
スレッド セーフティ
本関数はスレッドセーフではありません。
同一ハンドルに対して他の porter API と並行して呼び出さないでください。
本関数を呼び出す前に、同一ハンドルへのすべての potrSend() が完了していることを確認してください。
Warning
handle が NULL の場合は失敗を返します。

Definition at line 120 of file potrCloseService.c.

References comm_recv_thread_stop(), PotrContext_::compress_buf, PotrContext_::crypto_buf, PotrContext_::frag_buf, PotrContext_::health_mutex, PotrContext_::health_running, PotrContext_::health_wakeup, PotrContext_::is_multi_peer, PotrServiceDef::multicast_group, PotrContext_::n_path, parse_ipv4_addr(), peer_table_destroy(), PotrContext_::peers, POTR_API, potr_connect_thread_stop(), POTR_ERROR, POTR_EXPORT, potr_health_thread_stop(), POTR_INVALID_SOCKET, potr_is_tcp_type(), POTR_LOG, POTR_MAX_PATH, potr_raw_base_type(), POTR_ROLE_SENDER, potr_send_queue_destroy(), potr_send_queue_wait_drained(), potr_send_thread_stop(), POTR_SUCCESS, POTR_TRACE_ERROR, POTR_TRACE_INFO, POTR_TRACE_VERBOSE, POTR_TYPE_MULTICAST, POTR_TYPE_TCP_BIDIR, PotrContext_::recv_buf, PotrContext_::recv_window, PotrContext_::recv_window_mutex, PotrContext_::role, PotrContext_::running, send_fin(), PotrContext_::send_queue, PotrContext_::send_thread_running, PotrContext_::send_window, PotrContext_::send_wire_buf, PotrContext_::service, PotrServiceDef::service_id, PotrContext_::sock, PotrContext_::src_addr_resolved, PotrContext_::tcp_send_mutex, PotrContext_::tcp_state_cv, PotrContext_::tcp_state_mutex, PotrServiceDef::type, and window_destroy().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: