* move to the new linebuffered function while linebased reading from webbrowser and...
authorWilfried Göesgens <willi@citadel.org>
Sat, 11 Apr 2009 16:37:53 +0000 (16:37 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 11 Apr 2009 16:37:53 +0000 (16:37 +0000)
webcit/context_loop.c
webcit/tcp_sockets.c
webcit/webserver.c
webcit/webserver.h

index 5890f7fb8d1b3f9236dc48dbf402d76c9a08885a..e2697f290b1e43c781efc815b3ebdb28f1a7702e 100644 (file)
@@ -162,16 +162,6 @@ int GenerateSessionID(void)
        return ++seq;
 }
 
-/*
- * Collapse multiple cookies on one line
- */
-int ReqGetStrBuf(int *sock, StrBuf *Target, StrBuf *buf)
-{
-       
-       return ClientGetLine(sock, Target, buf);
-}
-
-
 
 /*
  * lingering_close() a`la Apache. see
@@ -260,6 +250,7 @@ const char *nix(void *vptr) {return ChrPtr( (StrBuf*)vptr);}
  */
 void context_loop(int *sock)
 {
+       const char *Pos = NULL;
        const char *buf;
        int desired_session = 0;
        int got_cookie = 0;
@@ -295,7 +286,9 @@ void context_loop(int *sock)
        do {
                nLine ++;
                Line = NewStrBuf();
-               if (ReqGetStrBuf(sock, Line, Buf) < 0) return;
+
+
+               if (ClientGetLine(sock, Line, Buf, &Pos) < 0) return;
 
                LineLen = StrLength(Line);
 
@@ -336,8 +329,10 @@ void context_loop(int *sock)
                LastLine = Line;
        } while (LineLen > 0);
        FreeStrBuf(&HeaderName);
+       /* finish linebuffered fast reading, cut the read part: */
+       StrBufCutLeft(Buf, Pos - ChrPtr(Buf));
 
-/*///  dbg_PrintHash(HTTPHeaders, nix, NULL); */
+       dbg_PrintHash(HTTPHeaders, nix, NULL); 
 
 
        /*
index 135819b311e2ea7ce5ddc085ab8ca1fe58fc6cf6..2352ca72643d4afc00e629c2add293eed79f137f 100644 (file)
@@ -144,6 +144,9 @@ inline void _serv_read(char *buf, int bytes, wcsession *WCC)
 void serv_read(char *buf, int bytes)
 {
        wcsession *WCC = WC;
+
+       WCC->ReadPos = NULL;
+
        _serv_read(buf, bytes, WCC);
 }
 
@@ -156,6 +159,7 @@ int serv_getln(char *strbuf, int bufsize)
        int ch, len;
        char buf[2];
 
+       WCC->ReadPos = NULL;
        len = 0;
        strbuf[0] = 0;
        do {
@@ -174,18 +178,20 @@ int serv_getln(char *strbuf, int bufsize)
 
 int StrBuf_ServGetln(StrBuf *buf)
 {
+       wcsession *WCC = WC;
        const char *ErrStr;
        int rc;
 
-       rc = StrBufTCP_read_line(buf, &WC->serv_sock, 0, &ErrStr);
+       WCC->ReadPos = NULL;
+       rc = StrBufTCP_read_line(buf, &WCC->serv_sock, 0, &ErrStr);
        if (rc < 0)
        {
                lprintf(1, "Server connection broken: %s\n",
                        ErrStr);
                wc_backtrace();
-               WC->serv_sock = (-1);
-               WC->connected = 0;
-               WC->logged_in = 0;
+               WCC->serv_sock = (-1);
+               WCC->connected = 0;
+               WCC->logged_in = 0;
        }
        return rc;
 }
@@ -196,11 +202,12 @@ int StrBuf_ServGetlnBuffered(StrBuf *buf)
        const char *ErrStr;
        int rc;
 
-       rc = StrBufTCP_read_buffered_line(buf, 
-                                         WCC->ReadBuf, 
-                                         &WCC->serv_sock, 
-                                         5, 1, 
-                                         &ErrStr);
+       rc = StrBufTCP_read_buffered_line_fast(buf, 
+                                              WCC->ReadBuf, 
+                                              &WCC->ReadPos, 
+                                              &WCC->serv_sock, 
+                                              5, 1, 
+                                              &ErrStr);
        if (rc < 0)
        {
                lprintf(1, "Server connection broken: %s\n",
@@ -215,18 +222,20 @@ int StrBuf_ServGetlnBuffered(StrBuf *buf)
 
 int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize)
 {
+       wcsession *WCC = WC;
        const char *Err;
        int rc;
        
-       rc = StrBufReadBLOB(buf, &WC->serv_sock, 1, BlobSize, &Err);
+       WCC->ReadPos = NULL;
+       rc = StrBufReadBLOB(buf, &WCC->serv_sock, 1, BlobSize, &Err);
        if (rc < 0)
        {
                lprintf(1, "Server connection broken: %s\n",
                        Err);
                wc_backtrace();
-               WC->serv_sock = (-1);
-               WC->connected = 0;
-               WC->logged_in = 0;
+               WCC->serv_sock = (-1);
+               WCC->connected = 0;
+               WCC->logged_in = 0;
        }
        return rc;
 }
@@ -263,9 +272,13 @@ void serv_write(const char *buf, int nbytes)
  */
 void serv_puts(const char *string)
 {
+       wcsession *WCC = WC;
 #ifdef SERV_TRACE
        lprintf(9, "%3d<%s\n", WC->serv_sock, string);
 #endif
+       FlushStrBuf(WCC->ReadBuf);
+       WCC->ReadPos = NULL;
+
        serv_write(string, strlen(string));
        serv_write("\n", 1);
 }
@@ -276,9 +289,13 @@ void serv_puts(const char *string)
  */
 void serv_putbuf(const StrBuf *string)
 {
+       wcsession *WCC = WC;
 #ifdef SERV_TRACE
        lprintf(9, "%3d<%s\n", WC->serv_sock, ChrPtr(string));
 #endif
+       FlushStrBuf(WCC->ReadBuf);
+       WCC->ReadPos = NULL;
+
        serv_write(ChrPtr(string), StrLength(string));
        serv_write("\n", 1);
 }
@@ -291,10 +308,14 @@ void serv_putbuf(const StrBuf *string)
  */
 void serv_printf(const char *format,...)
 {
+       wcsession *WCC = WC;
        va_list arg_ptr;
        char buf[SIZ];
        size_t len;
 
+       FlushStrBuf(WCC->ReadBuf);
+       WCC->ReadPos = NULL;
+
        va_start(arg_ptr, format);
        vsnprintf(buf, sizeof buf, format, arg_ptr);
        va_end(arg_ptr);
index 964f246abab89aa1d8c3d8984d7829de0db49d96..42d4c046a12d1abffdbd33edca57b2a83ac1f3e7 100644 (file)
@@ -389,7 +389,7 @@ void graceful_shutdown_watcher(int signum) {
 }
 
 
-int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf)
+int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf, const char **Pos)
 {
        const char *Error, *pch, *pchs;
        int rlen, len, retval = 0;
@@ -441,12 +441,13 @@ int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf)
                        return -1;
        }
        else 
-               return StrBufTCP_read_buffered_line(Target, 
-                                                   CLineBuf,
-                                                   sock,
-                                                   5,
-                                                   1,
-                                                   &Error);
+               return StrBufTCP_read_buffered_line_fast(Target, 
+                                                        CLineBuf,
+                                                        Pos,
+                                                        sock,
+                                                        5,
+                                                        1,
+                                                        &Error);
 }
 
 
index 82b4a51dfd690a6e574c508e0c5056e9b9bc1813..62a02bf96ea6df060dc864cf8d145f064931b041 100644 (file)
@@ -5,7 +5,7 @@ extern char *static_content_dirs[PATH_MAX];  /**< Disk representation */
 extern int ndirs;
 extern char socket_dir[PATH_MAX];
 
-int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf);
+int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf, const char **Pos);
 int client_getln(int *sock, char *buf, int bufsiz);
 int client_read(int *sock, StrBuf *Target, StrBuf *buf, int bytes);
 int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeout);