免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2861 | 回复: 1
打印 上一主题 下一主题

[FastDFS] 优化建议fastdfs api多进行参数检查,也建议fastdfs使用可重入函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 14:30 |只看该作者 |倒序浏览
hi,在使用和测试api过程中发现这几个问题需要你考虑优化的:

1,api的函数未对指针参数进行非NULL判断
例如函数:
int tracker_query_storage_store_without_group(TrackerServerInfo *pTrackerServer,
  TrackerServerInfo *pStorageServer, int *store_path_index)
里面未判断pTrackerServer、pTrackerServer是否为NULL,同事出错重连tracker时把pTrackerServer置为NULL后,自己也忘了判断是否为NULL就调用#define tracker_query_storage_store(pTrackerServer, pStorageServer, \
  store_path_index) \
而导致core dump,所以建议在api中接上参数判断,让fastdfs更健壮,即使使用者忘了还有api这层避免应用崩溃。

2,使用了非线程安全函数
看到fastdfs的代码中还有些线程方面的隐患,具体说是使用了gethostbyname等不可重入函数,应该改为gethostbyname_r更好,当然也有的可重入函数版本如gethostbyaddr_r有些Linux版本不支持,我找了个官方列表http://www.opengroup.org/onlinep ... /xsh_chap02_09.html
,你看看下面列表中的函数哪些可以改成线程安全版本,哪些不需要改并说明一下,包括server和api端,这样大家就可以放心使用:

2.9.1 Thread-Safety
All functions defined by this volume of IEEE Std 1003.1-2001 shall be thread-safe, except that the following functions1 need not be thread-safe.


asctime()
basename()
catgets()
crypt()
ctime()
dbm_clearerr()
dbm_close()
dbm_delete()
dbm_error()
dbm_fetch()
dbm_firstkey()
dbm_nextkey()
dbm_open()
dbm_store()
dirname()
dlerror()
drand48()


ecvt()
encrypt()
endgrent()
endpwent()
endutxent()
fcvt()
ftw()
gcvt()
getc_unlocked()
getchar_unlocked()
getdate()
getenv()
getgrent()
getgrgid()
getgrnam()
gethostbyaddr()
gethostbyname()


gethostent()
getlogin()
getnetbyaddr()
getnetbyname()
getnetent()
getopt()
getprotobyname()
getprotobynumber()
getprotoent()
getpwent()
getpwnam()
getpwuid()
getservbyname()
getservbyport()
getservent()
getutxent()
getutxid()


getutxline()
gmtime()
hcreate()
hdestroy()
hsearch()
inet_ntoa()
l64a()
lgamma()
lgammaf()
lgammal()
localeconv()
localtime()
lrand48()
mrand48()
nftw()
nl_langinfo()
ptsname()


putc_unlocked()
putchar_unlocked()
putenv()
pututxline()
rand()
readdir()
setenv()
setgrent()
setkey()
setpwent()
setutxent()
strerror()
strtok()
ttyname()
unsetenv()
wcstombs()
wctomb()



The ctermid() and tmpnam() functions need not be thread-safe if passed a NULL argument. The wcrtomb() and wcsrtombs() functions need not be thread-safe if passed a NULL ps argument.

Implementations shall provide internal synchronization as necessary in order to satisfy this requirement.

论坛徽章:
4
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:11IT运维版块每日发帖之星
日期:2016-08-11 06:20:00IT运维版块每日发帖之星
日期:2016-08-15 06:20:00
2 [报告]
发表于 2009-12-03 09:50 |只看该作者

回复 #1 happy_fastdfs 的帖子

>> 1,api的函数未对指针参数进行非NULL判断
这个不打算改了。像C的库函数,也不会进行参数检查的。
我们要遵循C语言惯例,呵呵。

>> 2,使用了非线程安全函数
这个我会确认一下。如果不是在多线程中,可以使用线程非安全函数的。

谢谢happy_fastdfs 的反馈和支持!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP