cwb(C on Web)一个轻量级,快速的 C 语言网络框架。
特性:
- 异步IO支持
- 事件驱动库
- 数据序列化、编码支持
示例代码
/* 事件驱动库 */
Cwb_Event_Base *base = cwb_event_new();
assert(base);
assert(!cwb_event_watch_fd(base,serverSocket,CWB_EVENT_READ,sockethandler,NULL));
cwb_event_loop(base);
cwb_event_destroy(base);
/* 数据结构 */
#include
#include
#include
#include
#include
#include"Test.h"
int main(void)
{
Cwb_Ds *dic=cwb_ds_new(CWB_DS_DICTIONARY,CWB_DS_SKEY);
assert(dic);
cwb_ds_set(dic,"I","Suote127");
cwb_ds_set(dic,"you","User");
cwb_ds_set(dic,"he","Unknow");
puts(cwb_ds_get(dic,"he"));
puts(cwb_ds_get(dic,"you"));
puts(cwb_ds_get(dic,"I"));
cwb_ds_set(dic,"I","The programmer");
puts(cwb_ds_get(dic,"I"));
cwb_ds_set(dic,"you",CWB_DS_UNDEFINED);
assert(cwb_ds_get(dic,"you")==CWB_DS_UNDEFINED);
cwb_ds_destroy(dic);
return 0;
}
/* 动态字符串 */
#include
#include
#include
#include
#include
int main(void)
{
char temp[1024];
fgets(temp,1024,stdin);
temp[strlen(temp);
Cwb_Dstr *dstr = cwb_dstr_new();
assert(dstr);
assert(cwb_dstr_assign(dstr,temp));
Cwb_Dstr *copy = cwb_dstr_copy(dstr);
char *s = cwb_dstr_convert(dstr,NULL,0);
puts(s);
char *t = strdup(s);
cwb_dstr_appendd(dstr,&t);
assert(!t);
cwb_dstr_appendc(dstr,':');
cwb_dstr_appendc(dstr,')');
free(s);
s = cwb_dstr_convert(dstr,NULL,0);
puts(s);
cwb_dstr_destroy(dstr);
free(s);
cwb_dstr_appends(copy,":)");
s = cwb_dstr_convert(copy,NULL,0);
puts(s);
free(s);
return 0;
}