shadesmar
1.0.0
시스템의 공유 메모리를 사용하여 메시지를 전달하는 IPC 라이브러리. Publish-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 ();
}