Giter Site home page Giter Site logo

tboox / tbox Goto Github PK

View Code? Open in Web Editor NEW
4.7K 4.7K 695.0 31.5 MB

🎁 A glib-like multi-platform c library

Home Page: https://docs.tboox.org

License: Apache License 2.0

C 89.14% C++ 0.01% GAP 8.45% Objective-C 0.04% Assembly 1.42% Lua 0.57% Shell 0.37%
algorithm container coroutines cross-platform iterator json network plist stream tbox xmake xml

tbox's People

Contributors

alexyer avatar ciotatsoft avatar codehz avatar colorfulorangecn avatar cuberl avatar da-liii avatar duyanning avatar federicobond avatar gajin2 avatar gitter-badger avatar ideal avatar idealvin avatar kortyburns avatar l1men9yu avatar opportunityliu avatar super119 avatar tangaoo avatar tbfly avatar timgates42 avatar vagrantc avatar wangling12 avatar waruqi avatar xanpeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tbox's Issues

macOS下无法编译

XMake v1.0.4.201609061812, The Automatic Cross-platform Build Tool
Copyright (C) 2015-2016 Ruki Wang, tboox.org
Copyright (C) 2005-2014 Mike Pall, luajit.org

步骤:

  1. 执行 xmake
$ xmake

报错:

error: /Users/canmor/workspace/tbox/xmake.lua:2: attempt to call global 'set_project' (a nil value)

具体的log: log.txt

警告

编译警告

deprecated: please uses has_config("small, micro") instead of is_option("small, micro")
deprecated: please uses has_config("hash") instead of is_option("hash")
deprecated: please uses has_config("mbedtls") instead of is_option("mbedtls")
deprecated: please uses has_config("coroutine") instead of is_option("coroutine")
deprecated: please uses has_config("charset") instead of is_option("charset")
deprecated: please uses has_config("zip") instead of is_option("zip")
deprecated: please uses has_config("micro") instead of is_option("micro")
deprecated: please uses has_config("xml") instead of is_option("xml")
deprecated: please uses has_config("float") instead of is_option("float")
deprecated: please uses has_config("openssl") instead of is_option("openssl")
deprecated: please uses has_config("database") instead of is_option("database")
deprecated: please uses has_config("object") instead of is_option("object")
deprecated: please uses has_config("polarssl") instead of is_option("polarssl")
deprecated: please uses has_config("demo") instead of is_option("demo")
deprecated: please uses has_config("regex") instead of is_option("regex")
deprecated: please uses has_config("exception") instead of is_option("exception")`

使用xmake 最新master 版 编译

xmake v2.2.1.201808241856, A cross-platform build utility based on Lua
Copyright (C) 2015-2018 Ruki Wang, tboox.org, xmake.io
Copyright (C) 2005-2015 Mike Pall, luajit.org
                         _        
    __  ___ __  __  __ _| | ______ 
    \ \/ / |  \/  |/ _  | |/ / __ \
     >  <  | \__/ | /_| |   <  ___/
    /_/\_\_|_|  |_|\__ \|_|\_\____| 
                         by ruki, tboox.org
    
      Manual: https://xmake.io/#/home
      Donate: https://xmake.io/pages/donation.html#donate

build

build

[00%]: compiling.release src/tbox/tbox.c
[00%]: compiling.release src/tbox/hash/bkdr.c
[00%]: compiling.release src/tbox/hash/fnv32.c
[00%]: compiling.release src/tbox/hash/adler32.c
error: clang: error: argument unused during compilation: '-mthumb' [-Werror,-Wunused-command-line-argument]

thks

tb_socket_ctrl支持更多参数

我正在把一个基于tcp的阻塞式传输库搬到tbox的协程上来,发现socket参数有些配置是没有的。如:

KeepAlive类

  • SOL_SOCKET SO_KEEPALIVE
  • IPPROTO_TCP TCP_KEEPINTVL
int keepalive = 1;
        setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_KEEPALIVE, (void *) (&keepalive), (socklen_t) sizeof(keepalive));
        int keepalive_intvl = 5;
        setsockopt(r->m_sb.sb_socket, IPPROTO_TCP, TCP_KEEPINTVL, (void *) (&keepalive_intvl),
                   (socklen_t) sizeof(keepalive_intvl));

忽略SIGPIPE事件

  • SOL_SOCKET SO_NOSIGPIPE
        int value = 1;
        int ret = setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));

请问可否提交相关代码加上相关设置

IOCP in Windows

One drawback of glib is that it does not support IOCP in Windows.
I hope you will consider about implementing it.

支持MCU吗??

亲,
tbox支持MCU吗??可以在stm32 ,avr这样的单片机上跑么??

协程bug?

只创建一个协程如下:
static tb_void_t tb_demo_coroutine_echo(tb_cpointer_t priv)
{
tb_co_channel_ref_t channel = tb_co_channel_init(0, tb_null, 0);
tb_co_channel_send(channel, (tb_cpointer_t)1);
return ;
}
程序结束时会出现断言失败
tb_co_scheduler_exit函数中 tb_assert(!tb_list_entry_size(&scheduler->coroutines_suspend));
原因是tb_co_channel_send --> tb_co_scheduler_suspend中:switch to the original coroutine
--> tb_co_scheduler_switch -->
回到了tb_co_scheduler_loop中,而tb_list_entry_size==0,因为唯一的一个协程已经移到了scheduler->coroutines_suspend中去

如何快速优雅地停止协程 scheduler ?

以 echo_server 为例子, 假如有许多客户端(例如5万个) 连接着, 那么有上万个协程会处于 tb_socket_wait 这一等待中, 发送什么信号可以它们同时快速地退出 , 并使 scheduler 安全退出?

思路很好啊,特别是内嵌检测

我发现大多数开发者对检测这事重视程度不够,导致写出的代码不稳定。本身业界也没有好的开源方案,自己也想过要弄,希望你这个项目能继续搞下去,造福人类啊.

tbox 在vs2017下 x86 无法编译通过

1、我使用 xmake project -k vs2017 -m "debug,release" 生产vs2017工程,发现只有x64能编译过,x86不能编译通过。
2、在windows下,用xmake 编译 tbox,release 的demo编译不过,dubug可以过。
3、在windows下,用xmake编译生产 x86 的静态库lib,我在使用的lib的时候,报“无法解析的外部符号 _in6addr_any”,是配置哪里不对吗?

Irregular performance of asio_httpd

Hello !
Now that the reported memory leak is solved I did another test and found that the performance of asio_httpd is irregular/wrong, I mean when testing of few concurrent requests with keepalive the performance is a lot low compared with no keepalive (normally is the opposite).

With keepalive 124 rps

httpress -t 2 -n 10000 -c 5 -k http://127.0.0.1:8080/index-ngx.html
2500 requests launched (19.924486 sec)
5000 requests launched (20.011948 sec)
7500 requests launched (20.015992 sec)
10000 requests launched (20.011983 sec)
thread 2: 3 connect, 6000 requests, 6000 success, 0 fail, 0 fail avg, 3672000 bytes, 738000 overhead
thread 1: 2 connect, 4000 requests, 4000 success, 0 fail, 0 fail avg, 2448000 bytes, 492000 overhead

TOTALS:  5 connect, 10000 requests, 10000 success, 0 fail, 0 fail avg, 5 (5) real concurrency
TRAFFIC: 612 avg bytes, 123 avg overhead, 6120000 bytes, 1230000 overhead
TIMING:  80.005 seconds, 124 rps, 89 kbps, 40.0 ms avg req time

Wthouth keepalive 8896 rps

httpress -t 2 -n 10000 -c 5 http://127.0.0.1:8080/index-ngx.html
2500 requests launched (0.276716 sec)
5000 requests launched (0.312879 sec)
7500 requests launched (0.267462 sec)
10000 requests launched (0.264104 sec)
thread 1: 4932 connect, 4932 requests, 4932 success, 0 fail, 0 fail avg, 3018384 bytes, 581976 overhead
thread 2: 5068 connect, 5068 requests, 5068 success, 0 fail, 0 fail avg, 3101616 bytes, 598024 overhead

TOTALS:  10000 connect, 10000 requests, 10000 success, 0 fail, 0 fail avg, 5 (5) real concurrency
TRAFFIC: 612 avg bytes, 118 avg overhead, 6120000 bytes, 1180000 overhead
TIMING:  1.124 seconds, 8896 rps, 6342 kbps, 0.6 ms avg req time

Cheers !

linux-clang compile error

[21%]: compiling.release src/tbox/libc/string/wcsrchr.c
error: src/tbox/libc/string/strlcpy.c:52:12: error: implicit declaration of function 'strlcpy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
return strlcpy(s1, s2, n);
^
1 error generated.
make[2]: *** [../3rdparty/tbox/src/tbox-stamp/tbox-build] Error 255
make[1]: *** [3rdparty/CMakeFiles/tbox.dir/all] Error 2
make: *** [all] Error 2

关于分拆各模块的使用

大神,你好,感谢你的分享。看了您的内存模块介绍,我想将它弄到我将来的项目中,为减少库的体积,我只需你模块中的一小部分,毕竟我不需要数据库、流之类的,这些,都有现成的了。请问下各模块的依赖关系如何?可以使用make而不用xmake搞吗?

IO处理和协程调度问题

tb_co_scheduler_io_loop中只有当scheduler->coroutines_ready没有协程时才会去调用tb_poller_wait处理IO事件,也就是所有的协程都阻塞在IO或sleep时才查看socket上是否可读可写,通过tb_co_scheduler_yield来往其它活动协程切换的。这种做法如果有两个协程一直自在活动中,它们没有调用阻塞和sleep,那这样网络事件将没有机会处理??

Memory leak on demo asio_httpd

Hello !
I just cloned tbox and build it, then when testing ./demo asio_httpd with httpress/ab and watching a task manager I can see how memory consumption only grows, keep running the command bellow and watch process memory usage:

ab -n 100000 -c 2000 -k http://127.0.0.1:8080/tbox/config.h

or

httpress -t 2 -n 100000 -c 2000 -k http://127.0.0.1:8080/tbox/config.h

I tested with valgrind and it reports no memory leaks (same number of allocations/deallocations) when terminating the program normally (key press), so I think it's memory fragmentation or any pool attached to a connection that is not been released (but because maybe they are attached to a hierarchy of pools that are released at the end valgrind can not find anything).

The system where it's running is a ubuntu 14.04 64bits.

Cheers !

链接错误

我在编译出来的库中,找不到关于utils/option的函数,也没有编译其对应的demo
也许option被废除了,但是我找不到任何与之对应的标记或说明。
也许是xmake.lua中有一些错误:将add_files("utils/*.c|option.c")改为add_files("utils/*.c|utils/option.c")后可以正常编译option但出现更多依赖。

关于 HN 上的一些 comments

你好,

几个小时前我将 TBOX 的项目链接分享到了 Hacker News 上,并收到了一些 comments,预计可能会持续产生一些新的反馈,虽然我是这条 read 的提交者,但是作为原作者才是最有权处理这些 comments 的。

谢谢你的贡献🍺。

怎么编译Example

新手,
现在下载安装了xmake
下载和build了tbox
但问题是怎么编译Example.c?

关于demo的sleep.c请教

你好,大牛,tbox的demo源码的sleep.c执行后开始打印了:

 [demo]: [coroutine: 10]: count: 9, interval: 10 ms
 [demo]: [coroutine: 1000]: count: 9, interval: 10 ms
 [demo]: [coroutine: 2000]: count: 9, interval: 10 ms
 [demo]: [coroutine: 100]: count: 9, interval: 10 ms
 ...

我刚开始接触协程请见谅,有个地方想不通:按我的理解遇到 tb_msleep 后协程切出去了,10 ms超时后其它的协程(100, 1000, 2000 )应该不会执行啊,不应该是 tb_msleep 到时间后才会往后走麽?

How to compile tbox as shared library?

Hello masters,

Looking at Build page, it seems there is no any option to compile tbox as shared library, so I changed set_kind("static") to set_kind("shared") in all .lua build files, however, when I try to compile it with my changes, it is stopped with the following error:

...
[49%]: compiling.release src/tbox/platform/arch/context.S
[50%]: linking.release libtbox.so
error: /usr/bin/ld: pkg/polarssl.pkg/lib/linux/x86_64/libpolarssl.a(ctr_drbg.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
pkg/polarssl.pkg/lib/linux/x86_64/libpolarssl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

I tried to add -fPIC via add_cxflags("-fPIC"), but got same error.

So, how to compile tbox using official mechanisms?

Thank you!

My environment:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

Tboox.org source

Hey! Would it be reasonably to do two things: first, put the tboox.org site on Github so people can help with translating to English (or any other language)?; second, self-host tboox.org using a C web-server written using tbox? I would be very interested in working on either of these two issues!

协程间 跨线程通信的一个问题

想利用多个核功能. 所以有多个线程.

为了描述简单, 假设有两个线程,记为: A, B. 各有一个调度器. 记为: a_scheduler
和b_scheduler.

A 负责从tcp服务器收数据,解码转为消息,交给线程B处理. (通过一个queue通信,有lock,和条件变量 cond)
B 负责处理消息, 以及其它一些事情(比如定时输出系统状态等)

问题是: B 和如何等待 A的消息 ? 代码如下:

//A线程
void A()
{
    //...
    tb_coroutine_start(b_scheduler,a_recv_tcp_data,tb_null,0);
    tb_co_scheduler_loop(a_scheduler, , tb_true);
}

//A线程中的, 收数据协程.
void a_recv_tcp_data(tb_cpointer_t priv)
{
    while(1){
        data = recv_from_tcp();
        msg = decode(data);

        lock(); //线程锁
        queue.enqueue(msg); //放入队列.
        cond.wake_up();  // 通知执行.
        unlock();//线程锁
    }

}



void do_show_tick(tb_cpointer_t priv)
{
    while(1)
    {
        tb_trace_i("tick...");
        tb_coroutine_sleep(10*1000);
    }

}

//问题就是这个函数该怎么写, 
//版本1:cond.wait 会导致线程B被挂起.
//tick, do_show_tick 不会被执行.

void do_handle_msg(tb_cpointer_t priv)
{
    lock();
    int cdn = queue.size(); 
    while(cdn == 0){
        cond.wait();
        cdn = queue.size();
    }
    unlock();
    //...
}

//版本 2. 
//如果这样的话, do_handle_msg 是不是会被一直调用. 就像忙查一样? 

void do_handle_msg(tb_cpointer_t priv)
{
    while(1) {
        lock();
        int cdn = queue.size(); 
        unlock();
        if(cdn == 0){
            tb_coroutine_yield();//....
        }else{
            ..... //handle msg
       }
        
    }
    //...
}

void B()
{
    ...
    tb_coroutine_start(b_scheduler,do_show_tick,tb_null,0);
    tb_co_scheduler_loop(b_scheduler, tb_true);
}

tbox能否移植到 openwrt 上

tbox移植到其它平台需要修改哪些地方,还有 xmake 的 sdk和bin选项有没有具体点的说明,我使用
xmake f --sdk=openwrt_sdk_home/ 和
xmake f --bin=tool_chain_home 都不能正常编译

关于 echo_server.c 疑问

你好,大牛,关于demo中的stackful中的echo_server.c 请教下:
环境:CentOS Linux release 7.2.1511 (Core)

运行./demo coroutine_echo_client 10 后服务器端回显正常,但是改成100 或者 1000后,
服务器端只打印了部分回显,其余的都是打印 wait 等待状态。这是什么原因呢?是因为
服务器端的栈开销太大导致的麽?

Windows/MinGW compile errors

Compiling tbox 1.6.3 on Windows with MinGW (GCC 7.3.0) via:

xmake f -p mingw --cflags=-Wno-error=unknown-pragmas
xmake
...
[23%]: compiling.release src\tbox\libm\tanf.c
[23%]: compiling.release src\tbox\libm\atan.c
[23%]: compiling.release src\tbox\libc\string\strcat.c
error: src\tbox\platform\windows\iocp_object.c:456:85: error: 'FILE_SKIP_COMPLETION_PORT_ON_SUCCESS' undeclared (first use in this function); did you mean 'IO_COMPLETION_ALL_ACCESS'?
             if (tb_kernel32()->SetFileCompletionNotificationModes((HANDLE)clientfd, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS))
                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                     IO_COMPLETION_ALL_ACCESS
src\tbox\platform\windows\iocp_object.c:456:85: note: each undeclared identifier is reported only once for each function it appears in
src\tbox\platform\windows\iocp_object.c: In function 'tb_iocp_object_connect':
src\tbox\platform\windows\iocp_object.c:544:117: error: 'FILE_SKIP_COMPLETION_PORT_ON_SUCCESS' undeclared (first use in this function); did you mean 'IO_COMPLETION_ALL_ACCESS'?
                     if (tb_kernel32()->SetFileCompletionNotificationModes((HANDLE)(SOCKET)tb_sock2fd(object->sock), FILE_SKIP_COMPLETION_PORT_ON_SUCCESS))
                                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                                                     IO_COMPLETION_ALL_ACCESS

Visual Studio 2015 compiles fine but that's not what i am looking for. Anything i missed? Thanks!

错误:总是创建链表失败

在我的计算机上, tb_list_init总是返回NULL。
int main(){ tb_list_ref_t a = tb_list_init(0, tb_element_long()); printf("over\n"); if(a == NULL){ printf("NULL\n"); return 0; } tb_list_exit(a); }
输出
over
NULL
我使用UBUNTU 18.04 LTS

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.