把chord下dbm_noauth做成静态库,提供接口
我的dbm.C文件如下,在src/chord-0.1/tools/下
/* * * Copyright (C) 2001 Frank Dabek (fdabek@lcs.mit.edu), * Massachusetts Institute of Technology * * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ #include <async.h>#include <dhash_common.h>#include <dhash_prot.h>#include <dhashclient.h>#include <dhblock.h>#include <dbfe.h>#include <crypt.h>#include <sys/time.h> #include <string>#include <iostream>#include <vector>using namespace std; string strResult;static vector<string> str_vec; str control_socket;static FILE *outfile;unsigned int datasize; ptr<axprt_stream> xprt;int fconnected = 0;int out = 0;int MAX_OPS_OUT = 1024; int bps = 0;int sec = 0;timecb_t *measurer = NULL; u_int64_tgetusec (){ timeval tv; gettimeofday (&tv, NULL);return tv.tv_sec * INT64(1000000) + tv.tv_usec;} voidstore_cb (u_int64_t start, dhash_stat status, ptr<insert_info> i){out++; strbuf s;if (status != DHASH_OK) { s << "store_cb: " << i->key << " " << status << "\n"; } else { bps++; s << i->key << " / " << (getusec () - start)/1000 << " /";for (size_t j = 0; j < i->path.size (); j++) s << " " << i->path[j]; s << "\n"; } str buf (s); fprintf (outfile, "%s", buf.cstr ());if (outfile != stdout) warnx << buf;} intstore (dhashclient *dhash, char *key, char *value) { dhash->insert (compute_hash (key, strlen(key)), value, strlen(value) + 1, wrap (store_cb, getusec ()), NULL, DHASH_NOAUTH); dhash->insert (compute_hash (key, strlen(key)), value, strlen(value) + 1, wrap (store_cb, getusec ()), NULL, DHASH_NOAUTH); while (out == 0) acheck ();return 0;} voidfetch_cb (dhash_stat stat, ptr<dhash_block> blk, vec<chordID> path){out++; if (!blk) { strbuf buf; fprintf (outfile, str (buf).cstr ()); } if (blk) { strbuf buf; bps++; buf << " /";for (u_int i = 0; i < blk->times.size (); i++) buf << " " << blk->times[i]; buf << " /"; buf << " " << blk->hops << " " << blk->errors << " " << blk->retries << " ";for (u_int i=0; i < path.size (); i++) { buf << path[i] << " "; } buf << " : ";if (blk->vData.size () > 0) { warn << blk->vData.size () << "\n";for (unsigned int i = 0; i < blk->vData.size (); i++) { buf << "" << i << ": " << blk->vData[i] << " -- \n"; warn << blk->vData[i] << "\n"; str_vec.push_back(blk->vData[i].cstr()); strResult += blk->vData[i].cstr(); strResult += "/"; } } else { buf << blk->data << "\n"; str_vec.push_back(blk->data.cstr()); strResult += blk->data.cstr(); strResult += "/"; } cout << "\nstrResult is:" << strResult << endl; buf << "\n\n"; fprintf (outfile, str (buf).cstr ());if (outfile != stdout) warnx << buf; } } voidfetch (dhashclient &dhash, char *key){ dhash.retrieve (compute_hash (key, strlen(key)), DHASH_NOAUTH, wrap (fetch_cb)); while (out == 0) acheck ();} voidusage (char *progname) { warn << "control_socket f|s key [value]\n"; exit(0);} voidcleanup (void){if (outfile) { fclose (outfile); } exit (1);} voideofhandler () { warn << "Unexpected EOF: block too large?\n"; cleanup ();} voidconnected (dhashclient *dhash, int argc, char **argv) { dhash->seteofcb (wrap (eofhandler)); //dbm sock [f|s] key value fconnected = 1; outfile = stdout; struct timeval start; gettimeofday (&start, NULL); if (argv[2][0] == 's') store (dhash, argv[3], argv[4]);else fetch (*dhash, argv[3]); delete dhash;} voidtcp_connect_cb (int argc, char **argv, int fd){if (fd < 0) fatal << "connect failed\n"; warnx << "... connected!\n"; xprt = axprt_stream::alloc (fd); dhashclient *dhash = New dhashclient (xprt); connected (dhash, argc, argv);} intmain (int argc, char **argv){ str_vec.clear(); setprogname (argv[0]); if (argc < 4) usage (argv[0]); sigcb (SIGTERM, wrap (&cleanup)); sigcb (SIGINT, wrap (&cleanup)); control_socket = argv[1];char *cstr = (char *)control_socket.cstr ();if (strchr (cstr, ':')) {char *port = strchr (cstr, ':'); *port = 0; //isolate host port++; // point at port char *host = cstr;short i_port = atoi (port); warn << "Connecting to " << host << ":" << i_port << " via TCP..."; tcpconnect (host, i_port, wrap (&tcp_connect_cb, argc, argv));while (!fconnected) acheck (); } else { dhashclient *dhash = New dhashclient (control_socket); connected (dhash, argc, argv); } printf("end of func\n"); unsigned int j;for (j = 0; j < str_vec.size(); ++j) { cout << str_vec[j] << endl; }}
在build/chord/tools的目录下还有dbm_use.h dbm_use.C两个文件
dbm_use.h
#ifndef _DBM_USE_H_#define _DMB_USE_H_ #include <string>#include <vector>using namespace std;vector<string> Fetch(const string & key);void Store(const string & key, const string & val); #endif
dbm_use.C
1 /* 2 * 3 * Copyright (C) 2001 Frank Dabek (fdabek@lcs.mit.edu), 4 * Massachusetts Institute of Technology 5 * 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 */ 27 28 #include <async.h> 29 #include <dhash_common.h> 30 #include <dhash_prot.h> 31 #include <dhashclient.h> 32 #include <dhblock.h> 33 #include <dbfe.h> 34 #include <crypt.h> 35 #include <sys/time.h> 36 37 #include <string> 38 #include <iostream> 39 #include <vector> 40 using namespace std; 41 42 #include "dbm_use.h" 43 string strResult; 44 static vector<string> str_vec; 45 46 str control_socket; 47 static FILE *outfile; 48 unsigned int datasize; 49 50 ptr<axprt_stream> xprt; 51 int fconnected = 0; 52 int out = 0; 53 int MAX_OPS_OUT = 1024; 54 55 int bps = 0; 56 int sec = 0; 57 timecb_t *measurer = NULL; 58 59 u_int64_t 60 getusec () 61 { 62 timeval tv; 63 gettimeofday (&tv, NULL); 64 return tv.tv_sec * INT64(1000000) + tv.tv_usec; 65 } 66 67 68 69 void 70 store_cb (u_int64_t start, dhash_stat status, ptr<insert_info> i) 71 { 72 out++; 73 74 strbuf s; 75 if (status != DHASH_OK) { 76 s << "store_cb: " << i->key << " " << status << "\n"; 77 } else { 78 bps++; 79 s << i->key << " / " << (getusec () - start)/1000 << " /"; 80 for (size_t j = 0; j < i->path.size (); j++) 81 s << " " << i->path[j]; 82 s << "\n"; 83 } 84 str buf (s); 85 fprintf (outfile, "%s", buf.cstr ()); 86 if (outfile != stdout) 87 warnx << buf; 88 } 89 90 91 int 92 store (dhashclient *dhash, char *key, char *value) 93 { 94 95 dhash->insert (compute_hash (key, strlen(key)), 96 value, strlen(value) + 1, 97 wrap (store_cb, getusec ()), NULL, DHASH_NOAUTH); 98 99 dhash->insert (compute_hash (key, strlen(key)), 100 value, strlen(value) + 1, 101 wrap (store_cb, getusec ()), NULL, DHASH_NOAUTH);102 103 while (out == 0) acheck ();104 return 0;105 }106 107 108 109 void110 fetch_cb (dhash_stat stat, ptr<dhash_block> blk, vec<chordID> path)111 {112 out++;113 114 if (!blk) {115 strbuf buf;116 fprintf (outfile, str (buf).cstr ());117 }118 119 if (blk) {120 strbuf buf;121 122 123 bps++;124 buf << " /";125 for (u_int i = 0; i < blk->times.size (); i++)126 buf << " " << blk->times[i];127 buf << " /";128 129 buf << " " << blk->hops << " " << blk->errors130 << " " << blk->retries << " ";131 for (u_int i=0; i < path.size (); i++) {132 buf << path[i] << " ";133 }134 135 buf << " : ";136 if (blk->vData.size () > 0) {137 warn << blk->vData.size () << "\n";138 for (unsigned int i = 0; i < blk->vData.size (); i++) {139 buf << "" << i << ": " << blk->vData[i] << " -- \n";140 warn << blk->vData[i] << "\n";141 str_vec.push_back(blk->vData[i].cstr());142 strResult += blk->vData[i].cstr();143 strResult += "/";144 }145 } else {146 buf << blk->data << "\n";147 str_vec.push_back(blk->data.cstr());148 strResult += blk->data.cstr();149 strResult += "/";150 }151 cout << "\nstrResult is:" << strResult << endl;152 buf << "\n\n";153 154 fprintf (outfile, str (buf).cstr ());155 if (outfile != stdout)156 warnx << buf;157 } 158 }159 160 161 void162 fetch (dhashclient &dhash, char *key)163 {164 165 166 dhash.retrieve (compute_hash (key, strlen(key)), DHASH_NOAUTH, 167 wrap (fetch_cb));168 169 while (out == 0) acheck ();170 }171 172 void173 usage (char *progname) 174 {175 warn << "control_socket f|s key [value]\n";176 exit(0);177 }178 179 void180 cleanup (void)181 {182 if (outfile) {183 fclose (outfile);184 }185 186 exit (1);187 }188 189 void190 eofhandler () 191 {192 warn << "Unexpected EOF: block too large?\n";193 cleanup ();194 }195 196 void197 connected (dhashclient *dhash, int argc, char **argv) 198 {199 dhash->seteofcb (wrap (eofhandler));200 201 //dbm sock [f|s] key value202 203 fconnected = 1;204 outfile = stdout;205 206 struct timeval start;207 gettimeofday (&start, NULL);208 209 if (argv[2][0] == 's')210 store (dhash, argv[3], argv[4]);211 else212 fetch (*dhash, argv[3]);213 214 215 delete dhash;216 }217 218 void219 tcp_connect_cb (int argc, char **argv, int fd)220 {221 if (fd < 0) 222 fatal << "connect failed\n";223 warnx << "... connected!\n";224 xprt = axprt_stream::alloc (fd); 225 dhashclient *dhash = New dhashclient (xprt);226 connected (dhash, argc, argv);227 }228 229 230 #define MAX_KEY_LEN 1024231 #define MAX_VAL_LEN 1024232 233 vector<string> Fetch(const string & key)234 {235 str_vec.clear();236 char key_star[MAX_KEY_LEN];237 strcpy(key_star, key.c_str());238 char * argvo[4] = {"./dbm", "/tmp/chord-sock", "f", key_star};239 char **argv = argvo;240 int argc = 4;241 242 if (argc < 4) usage (argv[0]);243 244 sigcb (SIGTERM, wrap (&cleanup));245 sigcb (SIGINT, wrap (&cleanup));246 247 control_socket = argv[1];248 char *cstr = (char *)control_socket.cstr ();249 if (strchr (cstr, ':')) {250 char *port = strchr (cstr, ':');251 *port = 0; //isolate host252 port++; // point at port253 char *host = cstr;254 short i_port = atoi (port);255 warn << "Connecting to " << host << ":" << i_port << " via TCP...";256 tcpconnect (host, i_port, wrap (&tcp_connect_cb, argc, argv));257 while (!fconnected) acheck ();258 } else {259 dhashclient *dhash = New dhashclient (control_socket);260 connected (dhash, argc, argv);261 }262 printf("end of func\n");263 unsigned int j;264 for (j = 0; j < str_vec.size(); ++j) {265 cout << str_vec[j] << endl;266 }267 return str_vec;268 }269 270 void Store(const string & key, const string & val)271 {272 char key_star[MAX_KEY_LEN];273 char val_star[MAX_VAL_LEN];274 strcpy(key_star, key.c_str());275 strcpy(val_star, val.c_str());276 char * argvo[5] = {"./dbm", "/tmp/chord-sock", "s", key_star, val_star};277 char **argv = argvo;278 int argc = 5;279 280 if (argc < 4) usage (argv[0]);281 282 sigcb (SIGTERM, wrap (&cleanup));283 sigcb (SIGINT, wrap (&cleanup));284 285 control_socket = argv[1];286 char *cstr = (char *)control_socket.cstr ();287 if (strchr (cstr, ':')) {288 char *port = strchr (cstr, ':');289 *port = 0; //isolate host290 port++; // point at port291 char *host = cstr;292 short i_port = atoi (port);293 warn << "Connecting to " << host << ":" << i_port << " via TCP...";294 tcpconnect (host, i_port, wrap (&tcp_connect_cb, argc, argv));295 while (!fconnected) acheck ();296 } else {297 dhashclient *dhash = New dhashclient (control_socket);298 connected (dhash, argc, argv);299 }300 printf("end of func\n");301 }302 303 /*int main()304 {305 string key = "mykey";306 string val = "myvalue4";307 // Store(key, val);308 vector<string> result = Fetch(key);309 310 unsigned int i;311 for (i = 0; i < result.size(); ++i) {312 cout << result[i] << endl;313 }314 }*/
在build的tools下还有test.cpp文件,同时有.deps目录,本目录有个libtool,mymakefile如下:
a.out: mkdir .deps g++ -DHAVE_CONFIG_H -I. -I/root/src/chord-0.1/tools -I/root/build/chord -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/u sr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/root/build/chord/svc -I/root/src/chord-0.1/lsd -I/ro ot/src/chord-0.1/svc -I/root/src/chord-0.1/dhash -I/root/src/chord-0.1/chord -I/root/src/chord-0.1/merkle -I/root/src/chord-0.1/utils -I/root/build/chor d/../sfslite -I/root/src/sfslite-0.8.16/async -I/root/src/sfslite-0.8.16/arpc -I/root/src/sfslite-0.8.16/crypt -I/root/src/sfslite-0.8.16/sfsmisc -I/root /src/sfslite-0.8.16/libsfs -I/root/build/chord/../sfslite/svc -I/usr/include/db4 -DSLEEPYCAT -g -O2 -Wall -Werror -MT dbm_use.o -MD -MP -MF ".deps/db m_use.Tpo" -c -o dbm_use.o ./dbm_use.C; ar -r libdbmuse.a dbm_use.o g++ -DHAVE_CONFIG_H -I. -I/root/src/chord-0.1/tools -I/root/build/chord -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/u sr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/root/build/chord/svc -I/root/src/chord-0.1/lsd -I/ro ot/src/chord-0.1/svc -I/root/src/chord-0.1/dhash -I/root/src/chord-0.1/chord -I/root/src/chord-0.1/merkle -I/root/src/chord-0.1/utils -I/root/build/chor d/../sfslite -I/root/src/sfslite-0.8.16/async -I/root/src/sfslite-0.8.16/arpc -I/root/src/sfslite-0.8.16/crypt -I/root/src/sfslite-0.8.16/sfsmisc -I/root /src/sfslite-0.8.16/libsfs -I/root/build/chord/../sfslite/svc -I/usr/include/db4 -DSLEEPYCAT -g -O2 -Wall -Werror -MT test.o -MD -MP -MF ".deps/test. Tpo" -c -o test.o ./test.cpp; mv -f ".deps/test.Tpo" ".deps/test.Po"; /bin/sh ./libtool --tag=CXX --mode=link g++ -g -O2 -Wall -Werror -o a.out test.o ./libdbmuse.a /root/build/chord/dhash/libdhashclient.a /root/bu ild/chord/utils/libutil.a /root/build/chord/svc/libsvc.la /root/build/chord/../sfslite/libtame/libtame.la /root/build/chord/../sfslite/sfsmisc/libsfsmisc .la /root/build/chord/../sfslite/svc/libsvc.la /root/build/chord/../sfslite/crypt/libsfscrypt.la /root/build/chord/../sfslite/arpc/libarpc.la /root/ build/chord/../sfslite/async/libasync.la -lgmp; g++ -static -g -O2 -Wall -Werror -o a.out test.o ./libdbmuse.a /root/build/chord/dhash/libdhashclient.a /root/build/chord/utils/libutil.a /root/buil d/chord/svc/.libs/libsvc.a /root/build/chord/../sfslite/libtame/.libs/libtame.a /root/build/chord/../sfslite/sfsmisc/.libs/libsfsmisc.a /root/build/chord /../sfslite/svc/.libs/libsvc.a /root/build/chord/../sfslite/crypt/.libs/libsfscrypt.a /root/build/chord/../sfslite/arpc/.libs/libarpc.a /root/build/chord /../sfslite/async/.libs/libasync.a -lnsl -lresolv -lgmp; clean: rm -rf *.o a.out libdbmuse.a .deps
转载于:https://www.cnblogs.com/tzhangofseu/archive/2011/12/05/2276524.html
把chord下dbm_noauth做成静态库,提供接口相关推荐
- iOS架构-C/C++lame库在Mac下编译通用静态库.a库(13)
C/C++ 有很多成熟的库,还有很多特殊功能的库,有时候iOS 平台开发一些比较前沿或者冷门的功能时,iOS并没有提供解决方案,这时候就可以研究C/C++的一些库,为我们使用.但是在Xcode编译C/ ...
- 解决 Xcode下使用公用静态库,出现的Duplicate Symbol错误
解决 Xcode下使用公用静态库,出现的"Duplicate Symbol"错误 分类: iPhone/iPad开发技术 2013-11-08 14:20 227人阅读 评论( ...
- iOS:Xcode7下创建 .a静态库 和 .framework静态库
Xcode7 中创建静态库:.a 和 .framework 一.简单介绍 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.库的分类 根据源代码的公开情况,库可以分为2种类型 (1)开 ...
- linux调用qt生成静态库文件下载,Centos7下编译openssl静态库与QT引用
1.下载openssl版本:https://www.openssl.org/source/old/ 下载地址 2.我们下载版本为:openssl-1.0.2k 3.拷贝到Linux服务器任意目录 4. ...
- MinGW下编译ffmpeg静态库给Visual C++使用
首先推荐 http://ffmpeg.zeranoe.com/builds/, 这里已经有编译好的动态连接库.可惜上面没静态链接库.我也试过 DLL2Lib, 但是无法连接LIBCMT库,只能使用MS ...
- windows下多个静态库合并的方法
方法一: VS项目->属性->配置属性->库管理器->常规->附加依赖项.附加库目录 添加需要合并的静态库 方法二: 开始->所有程序->Microsoft ...
- Ubuntu下gcc的静态库与动态库的生成与使用
目录 LInux中函数库的类型 一.用gcc生成.a静态库 1.编辑生成例子程序 hello.h .hello.c和main.c 2.将hello.c编译成.o文件 3.由.o文件创建静态库 4.在程 ...
- VS2017下编译Jsoncpp静态库
1. 下载Jsoncpp源代码 1.1 网址链接: http://sourceforge.net/projects/jsoncpp/ 1.2 百度云链接: 链接:https://pan.baidu.c ...
- [转]gcc下程序调用静态库编译命令:主文件必须在静态库前面!
很容易犯的错误,转载以备注! 转载请注明文章地址,尊重作者赖半仙的劳动成果,谢谢支持: http://hi.baidu.com/mgqw/blog/item/0969c4230a2508559922e ...
最新文章
- 数据库中关于convert的参数学习(转化函数用法)
- 管人、管团队、管项目,如何让团队管理者成为技术团队中的发动机?
- js时间工具 MyTimeUtil.js
- 产品经理专业知识50篇(一)-产品经理应该知道的一些产品术语
- MFCButton Memory leak(内存泄露问题)
- 使用位运算(与运算)代替%操作
- 习题3.11 递归和非递归查找元素
- C#:设置CefSharp的一些参数,比如忽略安全证书
- 使用Java反射(Reflect)、自定义注解(Customer Annotation)生成简单SQL语句
- window8.1中用户的管理员权限的提升方法
- SMART Utility for mac (硬盘检测工具)
- 转载:兼容IE的内阴影和外阴影效果
- 处理键盘上升盖住文本框问题
- Windows定时开机 命令 自动开机
- 怎么做一个企业级的BI项目?三步教你迅速搭建
- 双系统中Ubuntu启动失败
- PowerBI-日期和时间函数-YEAR\QUARTER\MONTH\DAY
- 云时代编程语言Ballerina发布,TIOBE9月排行榜PHP排名在边缘飘摇(2019/09/16)
- iOS 真机调试包(最新 16.1 真机调试包)
- CAD高版本转低版本怎么转?分享几种好用的转换方法
热门文章
- python123程序设计实验答案_Python程序设计第二次实验报告
- 吸收塔如何提高吸收率_想让肌肉生长得更好,蛋白质的补充很重要,如何选择你知道吗?...
- android大屏适配_2019年度投影机盘点:无线智能,塑造大屏全应用场景
- js 正则表达式判断价格
- signature=12e3283d637b587235bcb4cbbfa1a5b3,A pathogen-inducible endogenous siRNA in plant immunity
- html中为什么style中不显示发光点,css实现发光文字,以及一点点js特效
- 接收list对象_PyTorch入门视频笔记从数组、列表对象中创建Tensor
- python数据库操作批量sql执行_利用Python如何批量修改数据库执行Sql文件
- mysql录入图片数据_mysql插入图片数据
- oracle 配置监听和TNS常见的问题