Document of c-modernization-kit (porter) 1.0.0
Loading...
Searching...
No Matches
potrSendQueue.h
Go to the documentation of this file.
1
21
22#ifndef POTR_SEND_QUEUE_H
23#define POTR_SEND_QUEUE_H
24
25#include <stddef.h>
26
27#include <porter_const.h>
28#include <porter_type.h>
29
30#ifndef _WIN32
31 #include <pthread.h>
32 typedef pthread_mutex_t PotrMutex;
33 typedef pthread_cond_t PotrCondVar;
34#else /* _WIN32 */
35 #include <winsock2.h>
36 #include <windows.h>
37 typedef CRITICAL_SECTION PotrMutex;
38 typedef CONDITION_VARIABLE PotrCondVar;
39#endif /* _WIN32 */
40
50typedef struct
51{
53 uint16_t flags;
54 uint16_t payload_len;
55 uint8_t *payload;
57
85
86#ifdef __cplusplus
87extern "C"
88{
89#endif /* __cplusplus */
90
91 extern int potr_send_queue_init(PotrSendQueue *q, size_t depth, uint16_t max_payload);
93 extern int potr_send_queue_push(PotrSendQueue *q, PotrPeerId peer_id,
94 uint16_t flags,
95 const void *payload, uint16_t payload_len); /* 満杯時は即時 POTR_ERROR */
97 uint16_t flags,
98 const void *payload, uint16_t payload_len,
99 volatile int *running); /* 満杯時は空きを待機 */
101 volatile int *running);
104 uint32_t timeout_ms);
109
110#ifdef __cplusplus
111}
112#endif /* __cplusplus */
113
114#endif /* POTR_SEND_QUEUE_H */
通信ライブラリの定数ファイル。
通信ライブラリの型定義ファイル。
uint32_t PotrPeerId
ピア識別子。
Definition porter_type.h:32
int potr_send_queue_init(PotrSendQueue *q, size_t depth, uint16_t max_payload)
int potr_send_queue_push(PotrSendQueue *q, PotrPeerId peer_id, uint16_t flags, const void *payload, uint16_t payload_len)
void potr_send_queue_complete(PotrSendQueue *q)
int potr_send_queue_pop(PotrSendQueue *q, PotrPayloadElem *out, volatile int *running)
int potr_send_queue_peek_timed(PotrSendQueue *q, PotrPayloadElem *out, uint32_t timeout_ms)
pthread_cond_t PotrCondVar
int potr_send_queue_peek(PotrSendQueue *q, PotrPayloadElem *out)
void potr_send_queue_shutdown(PotrSendQueue *q)
int potr_send_queue_try_pop(PotrSendQueue *q, PotrPayloadElem *out)
pthread_mutex_t PotrMutex
void potr_send_queue_destroy(PotrSendQueue *q)
int potr_send_queue_push_wait(PotrSendQueue *q, PotrPeerId peer_id, uint16_t flags, const void *payload, uint16_t payload_len, volatile int *running)
void potr_send_queue_wait_drained(PotrSendQueue *q)
送信キューの 1 エントリ。ペイロードエレメント 1 個分のデータを保持する。
uint16_t payload_len
ペイロード長 (バイト)。
uint16_t flags
ペイロードエレメントフラグ (MORE_FRAG, COMPRESSED など)。
uint8_t * payload
ペイロードデータへのポインタ (プールスロット内を指す)。
PotrPeerId peer_id
送信先ピア識別子 (N:1 モード用。1:1 モードでは 0)。
非同期送信キュー。
size_t depth
キュー容量 (エントリ数)。
size_t count
キュー内エントリ数。
size_t inflight
sendto 実行中エントリ数。
PotrMutex mutex
排他制御。
PotrCondVar not_empty
count > 0 になったことを通知する条件変数。
PotrCondVar drained
count == 0 && inflight == 0 を通知する条件変数。
size_t head
読み出し位置 (送信スレッドが使用)。
size_t tail
書き込み位置 (potrSend 呼び出し元が使用)。
PotrCondVar not_full
count + inflight < depth になったことを通知する条件変数。
uint8_t * payload_pool
ペイロードプール (動的確保。depth × max_payload バイト)。
PotrPayloadElem * entries
ペイロードエレメントバッファ (動的確保。depth 要素)。
static volatile sig_atomic_t running