shadesmar
1.0.0
ไลบรารี IPC ที่ใช้หน่วยความจำที่ใช้ร่วมกันของระบบเพื่อส่งข้อความ รองรับการเผยแพร่-Subscribe และ RPC
ต้องการ: Linux และ X86 ข้อควรระวัง: ซอฟต์แวร์อัลฟ่า
สมาชิกและผู้เผยแพร่หลายราย
ใช้บัฟเฟอร์แบบวงกลมเพื่อส่งข้อความระหว่างกระบวนการ
เร็วกว่าการใช้สแต็คเครือข่าย ปริมาณงานสูงเวลาแฝงต่ำสำหรับข้อความขนาดใหญ่
กระจายอำนาจโดยไม่มีความอดอยากทรัพยากร
ลดหรือเพิ่มประสิทธิภาพการเคลื่อนไหวของข้อมูลโดยใช้เครื่องถ่ายเอกสารที่กำหนดเอง
มีไฟล์ส่วนหัวเดียวที่สร้างขึ้นจากซอร์สโค้ดซึ่งสามารถพบได้ที่นี่
หากคุณต้องการสร้างไฟล์ส่วนหัวเดียวด้วยตัวคุณเองให้โคลน repo และเรียกใช้:
$ cd shadesmar
$ python3 simul/simul.py
สิ่งนี้จะสร้างไฟล์ใน include/
สำนักพิมพ์:
# include < shadesmar/pubsub/publisher.h >
int main () {
shm::pubsub::Publisher p ( " topic_name " );
const uint32_t data_size = 1024 ;
void *data = malloc (data_size);
for ( int i = 0 ; i < 1000 ; ++i) {
p. publish (data, data_size);
}
}สมาชิก:
# include < shadesmar/pubsub/subscriber.h >
void callback (shm::memory::Memblock *msg) {
// `msg->ptr` to access `data`
// `msg->size` to access `data_size`
// The memory will be free'd at the end of this callback.
// Copy to another memory location if you want to persist the data.
// Alternatively, if you want to avoid the copy, you can call
// `msg->no_delete()` which prevents the memory from being deleted
// at the end of the callback.
}
int main () {
shm::pubsub::Subscriber sub ( " topic_name " , callback);
// Using `spin_once` with a manual loop
while ( true ) {
sub. spin_once ();
}
// OR
// Using `spin`
sub. spin ();
}ลูกค้า:
# include < shadesmar/rpc/client.h >
int main () {
Client client ( " channel_name " );
shm::memory::Memblock req, resp;
// Populate req.
client. call (req, &resp);
// Use resp here.
// resp needs to be explicitly free'd.
client. free_resp (&resp);
}เซิร์ฟเวอร์:
# include < shadesmar/rpc/server.h >
bool callback ( const shm::memory::Memblock &req,
shm::memory::Memblock *resp) {
// resp->ptr is a void ptr, resp->size is the size of the buffer.
// You can allocate memory here, which can be free'd in the clean-up lambda.
return true ;
}
void clean_up (shm::memory::Memblock *resp) {
// This function is called *after* the callback is finished. Any memory
// allocated for the response can be free'd here. A different copy of the
// buffer is sent to the client, this can be safely cleaned.
}
int main () {
shm::rpc::Server server ( " channel_name " , callback, clean_up);
// Using `serve_once` with a manual loop
while ( true ) {
server. serve_once ();
}
// OR
// Using `serve`
server. serve ();
}