Giter Site home page Giter Site logo

kbz-event's Introduction

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

kbz-event's People

Contributors

k-b-z avatar cfanfrank avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.