* do linebuffered reading from server
authorWilfried Göesgens <willi@citadel.org>
Sun, 15 Feb 2009 22:40:47 +0000 (22:40 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 15 Feb 2009 22:40:47 +0000 (22:40 +0000)
webcit/context_loop.c
webcit/tcp_sockets.c
webcit/webcit.c
webcit/webcit.h
webcit/who.c

index ddfd3bc21019f3d33ae4a00d0ef576f68e6feca2..27d03b36db9a4139b368ec8191bc5a38d56d181e 100644 (file)
@@ -38,6 +38,7 @@ void DestroySession(wcsession **sessions_to_kill)
        DeleteHash(&((*sessions_to_kill)->hash_prefs));
        DeleteHash(&((*sessions_to_kill)->IconBarSettings));
        DeleteHash(&((*sessions_to_kill)->ServCfg));
+       FreeStrBuf(&((*sessions_to_kill)->ReadBuf));
        FreeStrBuf(&((*sessions_to_kill)->UrlFragment1));
        FreeStrBuf(&((*sessions_to_kill)->UrlFragment2));
        FreeStrBuf(&((*sessions_to_kill)->UrlFragment3));
index b57a2de40208cfc27ccc269c210ad8008ebdbb37..f9c121b6c0057aa7da56faf5c2b7df3073c89909 100644 (file)
@@ -190,6 +190,29 @@ int StrBuf_ServGetln(StrBuf *buf)
        return rc;
 }
 
+int StrBuf_ServGetlnBuffered(StrBuf *buf)
+{
+       wcsession *WCC = WC;
+       const char *ErrStr;
+       int rc;
+
+       rc = StrBufTCP_read_buffered_line(buf, 
+                                         WCC->ReadBuf, 
+                                         &WCC->serv_sock, 
+                                         5, 1, 
+                                         &ErrStr);
+       if (rc < 0)
+       {
+               lprintf(1, "Server connection broken: %s\n",
+                       ErrStr);
+               wc_backtrace();
+               WCC->serv_sock = (-1);
+               WCC->connected = 0;
+               WCC->logged_in = 0;
+       }
+       return rc;
+}
+
 int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize)
 {
        const char *Err;
index 1974b2e1e117c1902a4eeda0d040f0291a774757..8647deec2b3fc7aefb5a8b24963b41b4b5462ebb 100644 (file)
@@ -788,6 +788,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
         * connection now.
         */
        if (!WCC->connected) {
+               WCC->ReadBuf = NewStrBuf();
                if (!strcasecmp(ctdlhost, "uds")) {
                        /* unix domain socket */
                        snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
index e372480ba89f4f1c4790d17953f6e6b864d8f2ae..34c3a4ad28f4eaf933a924a01759af003b80d0b5 100644 (file)
@@ -340,6 +340,7 @@ struct wcsession {
 /* Session local Members */
        int http_sock;                          /**< HTTP server socket */
        int serv_sock;                          /**< Client socket to Citadel server */
+       StrBuf *ReadBuf;
        int chat_sock;                          /**< Client socket to Citadel server - for chat */
        time_t lastreq;                         /**< Timestamp of most recent HTTP */
        time_t last_pager_check;                /**< last time we polled for instant msgs */
@@ -532,6 +533,7 @@ int uds_connectsock(char *);
 int tcp_connectsock(char *, char *);
 int serv_getln(char *strbuf, int bufsize);
 int StrBuf_ServGetln(StrBuf *buf);
+int StrBuf_ServGetlnBuffered(StrBuf *buf);
 int GetServerStatus(StrBuf *Line, long* FullState);
 void serv_puts(const char *string);
 void who(void);
index 6be0e6c67431e35b9e87da8fd9accd19d53070a3..320ef01538701f61f988376210b9bc24c089bc45 100644 (file)
@@ -54,7 +54,7 @@ int GetWholistSection(HashList *List, time_t now)
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                Buf = NewStrBuf();
-               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (BufLen = StrBuf_ServGetlnBuffered(Buf), strcmp(ChrPtr(Buf), "000")) {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;