Code Monkey home page Code Monkey logo

pink's Introduction

Pink

Build Status

Pink is a wrapper of pthread. Why you need it?

When you use pthread, you always define many type of thread, such as:

In network programming scenario, some thread used for accept the clinet's connection, some thread used for pass message to other thread, some thread used for communicate with client using protobuf.

So pink wrap a thin capsulation upon pthread to offer more convinent function.

Model

DispatchThread + Multi WorkerThread

Now pink support these type of thread:

DispatchThread:

DispatchThread is used for listen a port, and get an accept connection. And then dispatch this connection to the worker thread. the usage example is:

Thread *t = new DispatchThread<BadaConn>(9211, 1, reinterpret_cast<WorkerThread<BadaConn> **>(badaThread));

You can see example/bada.cc for more detail example

WorkerThread:

WorkerThread is the working thread, working thread use to communicate with client, you can use different protocol, now we have support google protobuf protocol. And you just need write the protocol, and then generate the code. The WorkerThread will deal with the protocol analysis, so it simplify your job.

the usage example is:

class BadaThread : public WorkerThread<BadaConn>

You can see example/bada_thread.h example/bada_thread.cc for more detail example

HolyThread:

HolyThread just like the redis's main thread, it is the thread that both listen a port and do the job. When should you use HolyThread and When should you use DispatchThread combine with WorkerThread, if your job is not so busy, so you can use HolyThread do the all job. if your job is deal lots of client's request, we suggest you use WorkerThreads

the usage example is:


class PinkThread : public HolyThread<PinkHolyConn>

Thread *t = new PinkThread(9211);
t->Start();

You can see example/holy_test.h example/holy_test.cc for more detail example

Now we will use pink build our project pika, floyd, zeppelin

In the future, I will add some thread manager in pink.

pink's People

Contributors

baotiao avatar catkang avatar flabby avatar jacketwoo avatar kernelmaker avatar pingyym avatar songbingyu avatar wenduo avatar

Watchers

 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.