Introduction
Introduction Statistics Contact Development Disclaimer Help
improve dcgi support - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit 6136de9a50186b811bb80acba917e6f6ea4cfe13
parent 3717798485ae28c453c83a109d17e66188d8379d
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 25 Jun 2017 20:53:07 +0200
improve dcgi support
- fix a memory leak (readln).
- use getline: this also improves performance:
- tested with a 30 MB file via netcat: 25s to 16s.
Signed-off-by: Christoph Lohmann <[email protected]>
Diffstat:
M handlr.c | 20 +++++++++++++++++---
M ind.c | 20 --------------------
M ind.h | 1 -
3 files changed, 17 insertions(+), 24 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -181,7 +181,10 @@ void
handledcgi(int sock, char *file, char *port, char *base, char *args,
char *sear, char *ohost)
{
- char *p, *path, *ln;
+ FILE *fp;
+ char *p, *path, *ln = nil;
+ size_t linesiz = 0;
+ ssize_t n;
int outpipe[2];
Elems *el;
@@ -226,7 +229,15 @@ handledcgi(int sock, char *file, char *port, char *base, c…
dup2(sock, 1);
close(outpipe[1]);
- while((ln = readln(outpipe[0])) != nil) {
+ if (!(fp = fdopen(outpipe[0], "r"))) {
+ perror("fdopen");
+ break;
+ }
+
+ while ((n = getline(&ln, &linesiz, fp)) > 0) {
+ if (ln[n - 1] == '\n')
+ ln[--n] = '\0';
+
el = getadv(ln);
if (el == nil)
continue;
@@ -234,10 +245,13 @@ handledcgi(int sock, char *file, char *port, char *base, …
printelem(sock, el, ohost, port);
freeelem(el);
}
+ if (ferror(fp))
+ perror("getline");
dprintf(sock, ".\r\n");
- wait(NULL);
+ free(ln);
free(path);
+ wait(NULL);
break;
}
}
diff --git a/ind.c b/ind.c
@@ -106,26 +106,6 @@ gettype(char *filename)
return &type[0];
}
-char *
-readln(int fd)
-{
- char *ret;
- int len;
-
- len = 1;
-
- ret = xmalloc(2);
- while(read(fd, &ret[len - 1], 1) > 0 && ret[len - 1] != '\n')
- ret = xrealloc(ret, ++len + 1);
- if(ret[len - 1] != '\n') {
- free(ret);
- return nil;
- }
- ret[len - 1] = '\0';
-
- return ret;
-}
-
void
freeelem(Elems *e)
{
diff --git a/ind.h b/ind.h
@@ -42,7 +42,6 @@ void addindexs(Indexs *idx, Elems *el);
void addelem(Elems *e, char *s);
void freeindex(Indexs *i);
void freeelem(Elems *e);
-char *readln(int fd);
int initlogging(char *logf);
void stoplogging(int fd);
char *smprintf(char *fmt, ...);
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.