From: Zoran V. <vas...@us...> - 2005-10-10 09:32:08
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28623/nsd Modified Files: adpeval.c adprequest.c fastpath.c urlopen.c Log Message: Removed OS/FS fallbacks. Now use TclVFS wrappers always. This simplifies code and (hopefully) does not introduce any (perceivable) speed penalties. Index: fastpath.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/fastpath.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** fastpath.c 8 Oct 2005 12:06:07 -0000 1.21 --- fastpath.c 10 Oct 2005 09:32:04 -0000 1.22 *************** *** 88,94 **** struct stat *stPtr); ! static int ReturnRange (Ns_Conn *conn, Range *rangesPtr, int fd, ! Tcl_Channel chan, CONST char *data, ! int len, CONST char *type); /* --- 88,93 ---- struct stat *stPtr); ! static int ReturnRange (Ns_Conn *conn, Range *rangesPtr, Tcl_Channel chan, ! CONST char *data, int len, CONST char *type); /* *************** *** 276,280 **** Ns_DStringInit(&ds); if (Ns_UrlToFile(&ds, server, url) == NS_OK ! && (!stat(ds.string, &st) || !Tcl_Stat(ds.string, &st)) && ((dir && S_ISDIR(st.st_mode)) || (dir == NS_FALSE && S_ISREG(st.st_mode)))) { --- 275,279 ---- Ns_DStringInit(&ds); if (Ns_UrlToFile(&ds, server, url) == NS_OK ! && Tcl_Stat(ds.string, &st) == 0 && ((dir && S_ISDIR(st.st_mode)) || (dir == NS_FALSE && S_ISREG(st.st_mode)))) { *************** *** 366,371 **** } Ns_DStringVarAppend(&ds, "/", servPtr->fastpath.dirv[i], NULL); ! if ((!stat(ds.string, &st) || !Tcl_Stat(ds.string, &st)) ! && S_ISREG(st.st_mode)) { if (url[strlen(url) - 1] != '/') { Ns_DStringTrunc(&ds, 0); --- 365,369 ---- } Ns_DStringVarAppend(&ds, "/", servPtr->fastpath.dirv[i], NULL); ! if (Tcl_Stat(ds.string, &st) == 0 && S_ISREG(st.st_mode)) { if (url[strlen(url) - 1] != '/') { Ns_DStringTrunc(&ds, 0); *************** *** 470,474 **** FastStat(CONST char *file, struct stat *stPtr) { ! if (stat(file, stPtr) != 0 && Tcl_Stat(file, stPtr) != 0) { if (Tcl_GetErrno() != ENOENT && Tcl_GetErrno() != EACCES) { Ns_Log(Error, "fastpath: stat(%s) failed: %s", --- 468,472 ---- FastStat(CONST char *file, struct stat *stPtr) { ! if (Tcl_Stat(file, stPtr) != 0) { if (Tcl_GetErrno() != ENOENT && Tcl_GetErrno() != EACCES) { Ns_Log(Error, "fastpath: stat(%s) failed: %s", *************** *** 502,506 **** CONST char *file, struct stat *stPtr) { ! int fd = -1, new, nread, result = NS_ERROR; Range range; char *key; --- 500,504 ---- CONST char *file, struct stat *stPtr) { ! int new, nread, result = NS_ERROR; Range range; char *key; *************** *** 576,598 **** if (servPtr->fastpath.mmap && NsMemMap(file, stPtr->st_size, NS_MMAP_READ, &fmap) == NS_OK) { ! result = ReturnRange(conn,&range,-1,NULL,fmap.addr,fmap.size,type); NsMemUmap(&fmap); } else { ! fd = open(file, O_RDONLY|O_BINARY); ! if (fd == -1) { ! chan = Tcl_OpenFileChannel(NULL, file, "r", 0644); ! if (chan == NULL) { ! Ns_Log(Warning, "fastpath: failed to open '%s': '%s'", ! file, strerror(Tcl_GetErrno())); ! goto notfound; ! } ! Tcl_SetChannelOption(NULL, chan, "-translation", "binary"); ! } ! result = ReturnRange(conn,&range,fd,chan,0,stPtr->st_size,type); ! if (fd >= 0) { ! close(fd); ! } else { ! Tcl_Close(NULL, chan); } } --- 574,589 ---- if (servPtr->fastpath.mmap && NsMemMap(file, stPtr->st_size, NS_MMAP_READ, &fmap) == NS_OK) { ! result = ReturnRange(conn,&range, NULL, fmap.addr,fmap.size, type); NsMemUmap(&fmap); } else { ! chan = Tcl_OpenFileChannel(NULL, file, "r", 0644); ! if (chan == NULL) { ! Ns_Log(Warning, "fastpath: failed to open '%s': '%s'", ! file, strerror(Tcl_GetErrno())); ! goto notfound; } + Tcl_SetChannelOption(NULL, chan, "-translation", "binary"); + result = ReturnRange(conn, &range, chan, 0, stPtr->st_size, type); + Tcl_Close(NULL, chan); } *************** *** 635,664 **** Ns_CacheUnlock(servPtr->fastpath.cache); ! fd = open(file, O_RDONLY|O_BINARY); ! if (fd == -1) { ! chan = Tcl_OpenFileChannel(NULL, file, "r", 0644); ! if (chan == NULL) { ! filePtr = NULL; ! Ns_Log(Warning, "fastpath: failed to open '%s': '%s'", ! file, strerror(Tcl_GetErrno())); ! } else { ! Tcl_SetChannelOption(NULL, chan, "-translation", "binary"); ! } } ! if (fd >= 0 || chan) { filePtr = ns_malloc(sizeof(File) + stPtr->st_size); filePtr->refcnt = 1; filePtr->size = stPtr->st_size; filePtr->mtime = stPtr->st_mtime; ! if (fd >= 0) { ! nread = read(fd, filePtr->bytes, (size_t)filePtr->size); ! close(fd); ! } else { ! nread = Tcl_Read(chan, filePtr->bytes, filePtr->size); ! Tcl_Close(NULL, chan); ! } if (nread != filePtr->size) { Ns_Log(Warning, "fastpath: failed to read '%s': '%s'", ! file, strerror((fd>=0)?errno:Tcl_GetErrno())); ns_free(filePtr); filePtr = NULL; --- 626,647 ---- Ns_CacheUnlock(servPtr->fastpath.cache); ! chan = Tcl_OpenFileChannel(NULL, file, "r", 0644); ! if (chan == NULL) { ! filePtr = NULL; ! Ns_Log(Warning, "fastpath: failed to open '%s': '%s'", ! file, strerror(Tcl_GetErrno())); ! } else { ! Tcl_SetChannelOption(NULL, chan, "-translation", "binary"); } ! if (chan) { filePtr = ns_malloc(sizeof(File) + stPtr->st_size); filePtr->refcnt = 1; filePtr->size = stPtr->st_size; filePtr->mtime = stPtr->st_mtime; ! nread = Tcl_Read(chan, filePtr->bytes, filePtr->size); ! Tcl_Close(NULL, chan); if (nread != filePtr->size) { Ns_Log(Warning, "fastpath: failed to read '%s': '%s'", ! file, strerror(Tcl_GetErrno())); ns_free(filePtr); filePtr = NULL; *************** *** 677,681 **** ++filePtr->refcnt; Ns_CacheUnlock(servPtr->fastpath.cache); ! result = ReturnRange(conn, &range, -1, NULL, filePtr->bytes, filePtr->size, type); Ns_CacheLock(servPtr->fastpath.cache); --- 660,664 ---- ++filePtr->refcnt; Ns_CacheUnlock(servPtr->fastpath.cache); ! result = ReturnRange(conn, &range, NULL, filePtr->bytes, filePtr->size, type); Ns_CacheLock(servPtr->fastpath.cache); *************** *** 947,951 **** static int ! ReturnRange(Ns_Conn *conn, Range *rangesPtr, int fd, Tcl_Channel chan, CONST char *data, int len, CONST char *type) { --- 930,934 ---- static int ! ReturnRange(Ns_Conn *conn, Range *rangesPtr, Tcl_Channel chan, CONST char *data, int len, CONST char *type) { *************** *** 966,972 **** status = rangesPtr->status; ! if (fd >= 0) { ! return Ns_ConnReturnOpenFd(conn, status, type, fd, len); ! } else if (chan) { return Ns_ConnReturnOpenChannel(conn, status, type, chan, len); } else { --- 949,953 ---- status = rangesPtr->status; ! if (chan) { return Ns_ConnReturnOpenChannel(conn, status, type, chan, len); } else { *************** *** 988,995 **** Ns_ConnQueueHeaders(conn, rangesPtr->status); ! if (fd >= 0) { ! lseek(fd, roPtr->start, SEEK_SET); ! result = Ns_ConnSendFd(conn, fd, roPtr->size); ! } else if (chan) { Tcl_Seek(chan, roPtr->start, SEEK_SET); result = Ns_ConnSendChannel(conn, chan, roPtr->size); --- 969,973 ---- Ns_ConnQueueHeaders(conn, rangesPtr->status); ! if (chan) { Tcl_Seek(chan, roPtr->start, SEEK_SET); result = Ns_ConnSendChannel(conn, chan, roPtr->size); *************** *** 1045,1049 **** /* * Second io vector will contain actual range buffer offset ! * and size. It will be ignored in fd mode. */ --- 1023,1027 ---- /* * Second io vector will contain actual range buffer offset ! * and size. It will be ignored in chan mode. */ *************** *** 1080,1084 **** Ns_ConnQueueHeaders(conn, rangesPtr->status); ! if (fd == -1 && chan == NULL) { /* --- 1058,1062 ---- Ns_ConnQueueHeaders(conn, rangesPtr->status); ! if (chan == NULL) { /* *************** *** 1091,1095 **** /* ! * In fd/chan mode, send headers and contents in separate calls */ --- 1069,1073 ---- /* ! * In chan mode, send headers and contents in separate calls */ *************** *** 1108,1121 **** /* ! * Send file content directly from open fd/chan */ ! if (fd >= 0) { ! lseek(fd, roPtr->start, SEEK_SET); ! result = Ns_ConnSendFd(conn, fd, roPtr->size); ! } else { ! Tcl_Seek(chan, roPtr->start, SEEK_SET); ! result = Ns_ConnSendChannel(conn, chan, roPtr->size); ! } if (result == NS_ERROR) { break; --- 1086,1094 ---- /* ! * Send file content directly from open chan */ ! Tcl_Seek(chan, roPtr->start, SEEK_SET); ! result = Ns_ConnSendChannel(conn, chan, roPtr->size); if (result == NS_ERROR) { break; *************** *** 1124,1128 **** /* * Point iovPtr to the third (boundary) iov buffer. ! * The second iov buffer is not used in fd/chan mode. */ --- 1097,1101 ---- /* * Point iovPtr to the third (boundary) iov buffer. ! * The second iov buffer is not used in chan mode. */ Index: adpeval.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/adpeval.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** adpeval.c 8 Oct 2005 12:06:07 -0000 1.6 --- adpeval.c 10 Oct 2005 09:32:03 -0000 1.7 *************** *** 353,357 **** */ ! if (stat(file, &st) != 0 && Tcl_Stat(file, &st) != 0) { Tcl_AppendResult(interp, "could not stat \"", file, "\": ", Tcl_PosixError(interp), NULL); --- 353,357 ---- */ ! if (Tcl_Stat(file, &st) != 0) { Tcl_AppendResult(interp, "could not stat \"", file, "\": ", Tcl_PosixError(interp), NULL); *************** *** 695,699 **** Tcl_DString utf; char *page, *buf; ! int fd = -1, n, trys, status; size_t size; Page *pagePtr; --- 695,699 ---- Tcl_DString utf; char *page, *buf; ! int n, trys, status; size_t size; Page *pagePtr; *************** *** 701,712 **** Tcl_Channel chan = NULL; ! fd = open(file, O_RDONLY | O_BINARY); ! if (fd == -1) { ! chan = Tcl_OpenFileChannel(interp, file, "r", 0644); ! if (chan == NULL) { ! Tcl_AppendResult(interp, "could not open \"", file, "\": ", ! Tcl_PosixError(interp), NULL); ! return NULL; ! } } --- 701,709 ---- Tcl_Channel chan = NULL; ! chan = Tcl_OpenFileChannel(interp, file, "r", 0644); ! if (chan == NULL) { ! Tcl_AppendResult(interp, "could not open \"", file, "\": ", ! Tcl_PosixError(interp), NULL); ! return NULL; } *************** *** 722,730 **** */ ! if (fd >= 0) { ! status = fstat(fd, stPtr); ! } else { ! status = Tcl_Stat(file, stPtr); ! } if (status != 0) { Tcl_AppendResult(interp, "could not stat \"", file, "\": ", --- 719,723 ---- */ ! status = Tcl_Stat(file, stPtr); if (status != 0) { Tcl_AppendResult(interp, "could not stat \"", file, "\": ", *************** *** 740,748 **** */ ! if (fd >= 0) { ! n = read(fd, buf, size + 1); ! } else { ! n = Tcl_Read(chan, buf, size + 1); ! } if (n < 0) { Tcl_AppendResult(interp, "could not read \"", file, "\": ", --- 733,737 ---- */ ! n = Tcl_Read(chan, buf, size + 1); if (n < 0) { Tcl_AppendResult(interp, "could not read \"", file, "\": ", *************** *** 756,764 **** */ ! if (fd >= 0) { ! status = lseek(fd, 0, SEEK_SET); ! } else { ! status = Tcl_Seek(chan, 0, SEEK_SET); ! } if (status != 0) { Tcl_AppendResult(interp, "could not seek \"", file, "\": ", --- 745,749 ---- */ ! status = Tcl_Seek(chan, 0, SEEK_SET); if (status != 0) { Tcl_AppendResult(interp, "could not seek \"", file, "\": ", *************** *** 804,813 **** done: ns_free(buf); ! ! if (fd >= 0) { ! close(fd); ! } else { ! Tcl_Close(interp, chan); ! } return pagePtr; --- 789,793 ---- done: ns_free(buf); ! Tcl_Close(interp, chan); return pagePtr; Index: urlopen.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/urlopen.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** urlopen.c 8 Oct 2005 12:06:07 -0000 1.4 --- urlopen.c 10 Oct 2005 09:32:04 -0000 1.5 *************** *** 79,98 **** Ns_DString ds; Tcl_Channel chan = NULL; ! int nread, fd = -1; char buf[1024]; Ns_DStringInit(&ds); Ns_UrlToFile(&ds, server, url); ! fd = open(ds.string, O_RDONLY|O_BINARY); ! if (fd == -1) { ! chan = Tcl_OpenFileChannel(NULL, ds.string, "r", 0); ! } Ns_DStringFree(&ds); ! if (fd >= 0) { ! while ((nread = read(fd, buf, sizeof(buf))) > 0) { ! Ns_DStringNAppend(dsPtr, buf, nread); ! } ! close(fd); ! } else if (chan) { while ((nread = Tcl_Read(chan, buf, sizeof(buf))) > 0) { Ns_DStringNAppend(dsPtr, buf, nread); --- 79,90 ---- Ns_DString ds; Tcl_Channel chan = NULL; ! int nread; char buf[1024]; Ns_DStringInit(&ds); Ns_UrlToFile(&ds, server, url); ! chan = Tcl_OpenFileChannel(NULL, ds.string, "r", 0); Ns_DStringFree(&ds); ! if (chan) { while ((nread = Tcl_Read(chan, buf, sizeof(buf))) > 0) { Ns_DStringNAppend(dsPtr, buf, nread); Index: adprequest.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/adprequest.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** adprequest.c 8 Oct 2005 12:06:07 -0000 1.8 --- adprequest.c 10 Oct 2005 09:32:04 -0000 1.9 *************** *** 104,109 **** * Verify the file exists. */ ! ! if (access(file, R_OK) != 0 && Tcl_Access(file, R_OK) != 0) { return Ns_ConnReturnNotFound(conn); } --- 104,109 ---- * Verify the file exists. */ ! ! if (Tcl_Access(file, R_OK) != 0) { return Ns_ConnReturnNotFound(conn); } |