Skip to content

send and recv event between processes with very few lines of code

Notifications You must be signed in to change notification settings

K-B-Z/kbz-event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kbz-event

Send and recv event between processes/threads in very few lines of codes.

  • Unlimited buffer size
  • WITHOUT any initialization or daemon process.
  • Fast and simple

Usage:

server.c

#include <kbz-event.h>

void main() {
  
  for (;;) {
    char *buf;
    int len;
    
    // wait event from channel 123. timeout 1s.
    if (kbz_event_get(123, &buf, &len, 1000) == 0) {
     // if not timeout
     // buffer is available until next kbz_event_get call.
     printf("got: %s\n", buf);
    }
  }
  
}

client.c

#include <kbz-event.h>

void main() {
  // post event to channel 123.
  kbz_event_post(123, "hello", 6);
}

Usage2:

server.c

#include <kbz-event.h>

void main() {
  
  for (;;) {
    char *buf;
    int len;
    
    // get event from channel 123. wait forever(timeout=0).
    if (kbz_event_get(123, &buf, &len, 0) == 0) {
     char ans[128];
     sprintf(ans, "time now is %d", time(NULL));
     kbz_ack_event(123, buf, ans, strlen(ans)+1);
    }
  }
  
}

client.c

#include <kbz-event.h>

void main() {
  char *ans;
  int ans_len;
  
  // post an empty event to channel 123 and wait for answer.
  if (kbz_event_push(123, "", 0, &ans, &ans_len, 0) == 0) {
    printf("server says: %s\n", ans);
  }
}

Build Requirements:

gcc version > 4.6
Linux

About

send and recv event between processes with very few lines of code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages