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
50 typedef struct
51{
52 PotrPeerId peer_id;
53 uint16_t flags;
54 uint16_t payload_len;
55 uint8_t *payload;
56} PotrPayloadElem;
57
71 typedef struct
72{
73 PotrPayloadElem *entries;
74 uint8_t *payload_pool;
75 size_t depth;
76 size_t head;
77 size_t tail;
78 size_t count;
79 size_t inflight;
80 PotrMutex mutex;
81 PotrCondVar not_empty;
82 PotrCondVar not_full;
83 PotrCondVar drained;
84} PotrSendQueue;
85
86#ifdef __cplusplus
87 extern "C"
88{
89#endif /* __cplusplus */
90
91 extern int potr_send_queue_init(PotrSendQueue *q, size_t depth, uint16_t max_payload);
92 extern void potr_send_queue_destroy(PotrSendQueue *q);
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 */
96 extern int potr_send_queue_push_wait(PotrSendQueue *q, PotrPeerId peer_id,
97 uint16_t flags,
98 const void *payload, uint16_t payload_len,
99 volatile int *running); /* 満杯時は空きを待機 */
100 extern int potr_send_queue_pop(PotrSendQueue *q, PotrPayloadElem *out,
101 volatile int *running);
102 extern int potr_send_queue_peek(PotrSendQueue *q, PotrPayloadElem *out);
103 extern int potr_send_queue_peek_timed(PotrSendQueue *q, PotrPayloadElem *out,
104 uint32_t timeout_ms);
105 extern int potr_send_queue_try_pop(PotrSendQueue *q, PotrPayloadElem *out);
106 extern void potr_send_queue_complete(PotrSendQueue *q);
107 extern void potr_send_queue_wait_drained(PotrSendQueue *q);
108 extern void potr_send_queue_shutdown(PotrSendQueue *q);
109
110#ifdef __cplusplus
111}
112#endif /* __cplusplus */
113
114#endif /* POTR_SEND_QUEUE_H */
porter_const.h
通信ライブラリの定数ファイル。
porter_type.h
通信ライブラリの型定義ファイル。
PotrPeerId
uint32_t PotrPeerId
ピア識別子。
Definition porter_type.h:32
potr_send_queue_init
int potr_send_queue_init(PotrSendQueue *q, size_t depth, uint16_t max_payload)
Definition potrSendQueue.c:51
potr_send_queue_push
int potr_send_queue_push(PotrSendQueue *q, PotrPeerId peer_id, uint16_t flags, const void *payload, uint16_t payload_len)
Definition potrSendQueue.c:100
potr_send_queue_complete
void potr_send_queue_complete(PotrSendQueue *q)
Definition potrSendQueue.c:258
potr_send_queue_pop
int potr_send_queue_pop(PotrSendQueue *q, PotrPayloadElem *out, volatile int *running)
Definition potrSendQueue.c:159
potr_send_queue_peek_timed
int potr_send_queue_peek_timed(PotrSendQueue *q, PotrPayloadElem *out, uint32_t timeout_ms)
Definition potrSendQueue.c:202
PotrCondVar
pthread_cond_t PotrCondVar
Definition potrSendQueue.h:33
potr_send_queue_peek
int potr_send_queue_peek(PotrSendQueue *q, PotrPayloadElem *out)
Definition potrSendQueue.c:185
potr_send_queue_shutdown
void potr_send_queue_shutdown(PotrSendQueue *q)
Definition potrSendQueue.c:293
potr_send_queue_try_pop
int potr_send_queue_try_pop(PotrSendQueue *q, PotrPayloadElem *out)
Definition potrSendQueue.c:238
PotrMutex
pthread_mutex_t PotrMutex
Definition potrSendQueue.h:32
potr_send_queue_destroy
void potr_send_queue_destroy(PotrSendQueue *q)
Definition potrSendQueue.c:87
potr_send_queue_push_wait
int potr_send_queue_push_wait(PotrSendQueue *q, PotrPeerId peer_id, uint16_t flags, const void *payload, uint16_t payload_len, volatile int *running)
Definition potrSendQueue.c:126
potr_send_queue_wait_drained
void potr_send_queue_wait_drained(PotrSendQueue *q)
Definition potrSendQueue.c:280
PotrPayloadElem
送信キューの 1 エントリ。ペイロードエレメント 1 個分のデータを保持する。
Definition potrSendQueue.h:51
PotrPayloadElem::payload_len
uint16_t payload_len
ペイロード長 (バイト)。
Definition potrSendQueue.h:54
PotrPayloadElem::flags
uint16_t flags
ペイロードエレメントフラグ (MORE_FRAG, COMPRESSED など)。
Definition potrSendQueue.h:53
PotrPayloadElem::payload
uint8_t * payload
ペイロードデータへのポインタ (プールスロット内を指す)。
Definition potrSendQueue.h:55
PotrPayloadElem::peer_id
PotrPeerId peer_id
送信先ピア識別子 (N:1 モード用。1:1 モードでは 0)。
Definition potrSendQueue.h:52
PotrSendQueue
非同期送信キュー。
Definition potrSendQueue.h:72
PotrSendQueue::depth
size_t depth
キュー容量 (エントリ数)。
Definition potrSendQueue.h:75
PotrSendQueue::count
size_t count
キュー内エントリ数。
Definition potrSendQueue.h:78
PotrSendQueue::inflight
size_t inflight
sendto 実行中エントリ数。
Definition potrSendQueue.h:79
PotrSendQueue::mutex
PotrMutex mutex
排他制御。
Definition potrSendQueue.h:80
PotrSendQueue::not_empty
PotrCondVar not_empty
count > 0 になったことを通知する条件変数。
Definition potrSendQueue.h:81
PotrSendQueue::drained
PotrCondVar drained
count == 0 && inflight == 0 を通知する条件変数。
Definition potrSendQueue.h:83
PotrSendQueue::head
size_t head
読み出し位置 (送信スレッドが使用)。
Definition potrSendQueue.h:76
PotrSendQueue::tail
size_t tail
書き込み位置 (potrSend 呼び出し元が使用)。
Definition potrSendQueue.h:77
PotrSendQueue::not_full
PotrCondVar not_full
count + inflight < depth になったことを通知する条件変数。
Definition potrSendQueue.h:82
PotrSendQueue::payload_pool
uint8_t * payload_pool
ペイロードプール (動的確保。depth × max_payload バイト)。
Definition potrSendQueue.h:74
PotrSendQueue::entries
PotrPayloadElem * entries
ペイロードエレメントバッファ (動的確保。depth 要素)。
Definition potrSendQueue.h:73
running
static volatile sig_atomic_t running
Definition tcpServer_linux.c:40