From: Wilfried Göesgens Date: Sun, 15 Feb 2009 22:40:47 +0000 (+0000) Subject: * do linebuffered reading from server X-Git-Tag: v7.86~1450 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=61f8d366c50bf2d7e85ee123c13f45d6724bc15e * do linebuffered reading from server --- diff --git a/webcit/context_loop.c b/webcit/context_loop.c index ddfd3bc21..27d03b36d 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -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)); diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index b57a2de40..f9c121b6c 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -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; diff --git a/webcit/webcit.c b/webcit/webcit.c index 1974b2e1e..8647deec2 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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); diff --git a/webcit/webcit.h b/webcit/webcit.h index e372480ba..34c3a4ad2 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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); diff --git a/webcit/who.c b/webcit/who.c index 6be0e6c67..320ef0153 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -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;