提交 10e951eb 编写于 作者: 陶建辉(Jeff)'s avatar 陶建辉(Jeff)

fix bug in tfile

上级 9bf73b64
...@@ -26,13 +26,11 @@ static void taosCloseFile(void *p) { ...@@ -26,13 +26,11 @@ static void taosCloseFile(void *p) {
} }
int tfinit() { int tfinit() {
tsFileRsetId = taosOpenRef(2000, taosCloseFile); tsFileRsetId = taosOpenRef(2000, taosCloseFile);
return tsFileRsetId; return tsFileRsetId;
} }
void tfcleanup() { void tfcleanup() {
if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId); if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId);
tsFileRsetId = -1; tsFileRsetId = -1;
} }
...@@ -45,17 +43,15 @@ int64_t tfopen(const char *pathname, int flags) { ...@@ -45,17 +43,15 @@ int64_t tfopen(const char *pathname, int flags) {
return -1; return -1;
} }
int64_t rid = taosAddRef(tsFileRsetId, (void *)(long)fd); void *p = (void *)(long)fd;
if (rid < 0) { int64_t rid = taosAddRef(tsFileRsetId, p);
close(fd); if (rid < 0) close(fd);
return -1;
}
return rid; return rid;
} }
int64_t tfclose(int64_t tfd) { int64_t tfclose(int64_t tfd) {
return taosReleaseRef(tsFileRsetId, tfd); return taosRemoveRef(tsFileRsetId, tfd);
} }
ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) { ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) {
...@@ -66,10 +62,7 @@ ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) { ...@@ -66,10 +62,7 @@ ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) {
int fd = (int)(uintptr_t)p; int fd = (int)(uintptr_t)p;
ssize_t ret = write(fd, buf, count); ssize_t ret = write(fd, buf, count);
if (ret < 0) { if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
taosReleaseRef(tsFileRsetId, tfd); taosReleaseRef(tsFileRsetId, tfd);
return ret; return ret;
...@@ -83,10 +76,7 @@ ssize_t tfread(int64_t tfd, void *buf, size_t count) { ...@@ -83,10 +76,7 @@ ssize_t tfread(int64_t tfd, void *buf, size_t count) {
int fd = (int)(uintptr_t)p; int fd = (int)(uintptr_t)p;
ssize_t ret = read(fd, buf, count); ssize_t ret = read(fd, buf, count);
if (ret < 0) { if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
taosReleaseRef(tsFileRsetId, tfd); taosReleaseRef(tsFileRsetId, tfd);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册