Fossil SCM

Make the /chat-poll timeout configurable using the chat-poll-timeout setting.

drh 2020-12-26 12:33 trunk
Commit 8363e7b8e6ddf9ec48682b68e54ab288bda3342f8d030b02bb7ec402ed071582
2 files changed +30 -10 +13
+30 -10
--- src/chat.c
+++ src/chat.c
@@ -74,10 +74,24 @@
7474
**
7575
** Specifies whether posted images in /chat should default to being
7676
** displayed inline or as downloadable links. Each chat user can
7777
** change this value for their current chat session in the UI.
7878
*/
79
+/*
80
+** SETTING: chat-poll-timeout width=10 default=420
81
+**
82
+** On an HTTP request to /chat-poll, if there is no new content available,
83
+** the reply is delayed waiting for new content to arrive. (This is the
84
+** "long poll" strategy of event delivery to the client.) This setting
85
+** determines approximately how long /chat-poll will delay before giving
86
+** up and returning an empty reply. The default value is about 7 minutes,
87
+** which works well for Fossil behind the althttpd web server. Other
88
+** server environments may choose a longer or shorter delay.
89
+**
90
+** For maximum efficiency, it is best to choose the longest delay that
91
+** does not cause timeouts in intermediate proxies or web server.
92
+*/
7993
/*
8094
** WEBPAGE: chat
8195
**
8296
** Start up a browser-based chat session.
8397
**
@@ -335,19 +349,24 @@
335349
}
336350
337351
/*
338352
** WEBPAGE: chat-poll
339353
**
340
-** The chat page generated by /chat using a XHR to this page in order
341
-** to ask for new chat content. The "name" argument should begin with
342
-** an integer which is the largest "msgid" that the chat page currently
343
-** holds. If newer content is available, this routine returns that
344
-** content straight away. If no new content is available, this webpage
345
-** blocks until the new content becomes available. In this way, the
346
-** system implements "hanging-GET" or "long-poll" style event notification.
354
+** The chat page generated by /chat using an XHR to this page to
355
+** request new chat content. A typical invocation is:
356
+**
357
+** /chat-poll/N
358
+** /chat-poll?name=N
347359
**
348
-** /chat-poll/N
360
+** The "name" argument should begin with an integer which is the largest
361
+** "msgid" that the chat page currently holds. If newer content is
362
+** available, this routine returns that content straight away. If no new
363
+** content is available, this webpage blocks until the new content becomes
364
+** available. In this way, the system implements "hanging-GET" or "long-poll"
365
+** style event notification. If no new content arrives after a delay of
366
+** approximately chat-poll-timeout seconds (default: 420), then reply is
367
+** sent with an empty "msg": field.
349368
**
350369
** If N is negative, then the return value is the N most recent messages.
351370
** Hence a request like /chat-poll/-100 can be used to initialize a new
352371
** chat session to just the most recent messages.
353372
**
@@ -395,17 +414,18 @@
395414
** case they are sorted newest first (to facilitate the client-side UI update).
396415
*/
397416
void chat_poll_webpage(void){
398417
Blob json; /* The json to be constructed and returned */
399418
sqlite3_int64 dataVersion; /* Data version. Used for polling. */
400
- int iDelay = 1000; /* Delay until next poll (milliseconds) */
401
- int nDelay = 420; /* Maximum delay. 420*1000 = about 7 minutes */
419
+ const int iDelay = 1000; /* Delay until next poll (milliseconds) */
420
+ int nDelay; /* Maximum delay.*/
402421
int msgid = atoi(PD("name","0"));
403422
const int msgBefore = atoi(PD("before","0"));
404423
int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
405424
Blob sql = empty_blob;
406425
Stmt q1;
426
+ nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
407427
login_check_credentials();
408428
if( !g.perm.Chat ) return;
409429
chat_create_tables();
410430
cgi_set_content_type("text/json");
411431
dataVersion = db_int64(0, "PRAGMA data_version");
412432
--- src/chat.c
+++ src/chat.c
@@ -74,10 +74,24 @@
74 **
75 ** Specifies whether posted images in /chat should default to being
76 ** displayed inline or as downloadable links. Each chat user can
77 ** change this value for their current chat session in the UI.
78 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79 /*
80 ** WEBPAGE: chat
81 **
82 ** Start up a browser-based chat session.
83 **
@@ -335,19 +349,24 @@
335 }
336
337 /*
338 ** WEBPAGE: chat-poll
339 **
340 ** The chat page generated by /chat using a XHR to this page in order
341 ** to ask for new chat content. The "name" argument should begin with
342 ** an integer which is the largest "msgid" that the chat page currently
343 ** holds. If newer content is available, this routine returns that
344 ** content straight away. If no new content is available, this webpage
345 ** blocks until the new content becomes available. In this way, the
346 ** system implements "hanging-GET" or "long-poll" style event notification.
347 **
348 ** /chat-poll/N
 
 
 
 
 
 
 
349 **
350 ** If N is negative, then the return value is the N most recent messages.
351 ** Hence a request like /chat-poll/-100 can be used to initialize a new
352 ** chat session to just the most recent messages.
353 **
@@ -395,17 +414,18 @@
395 ** case they are sorted newest first (to facilitate the client-side UI update).
396 */
397 void chat_poll_webpage(void){
398 Blob json; /* The json to be constructed and returned */
399 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
400 int iDelay = 1000; /* Delay until next poll (milliseconds) */
401 int nDelay = 420; /* Maximum delay. 420*1000 = about 7 minutes */
402 int msgid = atoi(PD("name","0"));
403 const int msgBefore = atoi(PD("before","0"));
404 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
405 Blob sql = empty_blob;
406 Stmt q1;
 
407 login_check_credentials();
408 if( !g.perm.Chat ) return;
409 chat_create_tables();
410 cgi_set_content_type("text/json");
411 dataVersion = db_int64(0, "PRAGMA data_version");
412
--- src/chat.c
+++ src/chat.c
@@ -74,10 +74,24 @@
74 **
75 ** Specifies whether posted images in /chat should default to being
76 ** displayed inline or as downloadable links. Each chat user can
77 ** change this value for their current chat session in the UI.
78 */
79 /*
80 ** SETTING: chat-poll-timeout width=10 default=420
81 **
82 ** On an HTTP request to /chat-poll, if there is no new content available,
83 ** the reply is delayed waiting for new content to arrive. (This is the
84 ** "long poll" strategy of event delivery to the client.) This setting
85 ** determines approximately how long /chat-poll will delay before giving
86 ** up and returning an empty reply. The default value is about 7 minutes,
87 ** which works well for Fossil behind the althttpd web server. Other
88 ** server environments may choose a longer or shorter delay.
89 **
90 ** For maximum efficiency, it is best to choose the longest delay that
91 ** does not cause timeouts in intermediate proxies or web server.
92 */
93 /*
94 ** WEBPAGE: chat
95 **
96 ** Start up a browser-based chat session.
97 **
@@ -335,19 +349,24 @@
349 }
350
351 /*
352 ** WEBPAGE: chat-poll
353 **
354 ** The chat page generated by /chat using an XHR to this page to
355 ** request new chat content. A typical invocation is:
356 **
357 ** /chat-poll/N
358 ** /chat-poll?name=N
 
 
359 **
360 ** The "name" argument should begin with an integer which is the largest
361 ** "msgid" that the chat page currently holds. If newer content is
362 ** available, this routine returns that content straight away. If no new
363 ** content is available, this webpage blocks until the new content becomes
364 ** available. In this way, the system implements "hanging-GET" or "long-poll"
365 ** style event notification. If no new content arrives after a delay of
366 ** approximately chat-poll-timeout seconds (default: 420), then reply is
367 ** sent with an empty "msg": field.
368 **
369 ** If N is negative, then the return value is the N most recent messages.
370 ** Hence a request like /chat-poll/-100 can be used to initialize a new
371 ** chat session to just the most recent messages.
372 **
@@ -395,17 +414,18 @@
414 ** case they are sorted newest first (to facilitate the client-side UI update).
415 */
416 void chat_poll_webpage(void){
417 Blob json; /* The json to be constructed and returned */
418 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
419 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
420 int nDelay; /* Maximum delay.*/
421 int msgid = atoi(PD("name","0"));
422 const int msgBefore = atoi(PD("before","0"));
423 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
424 Blob sql = empty_blob;
425 Stmt q1;
426 nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
427 login_check_credentials();
428 if( !g.perm.Chat ) return;
429 chat_create_tables();
430 cgi_set_content_type("text/json");
431 dataVersion = db_int64(0, "PRAGMA data_version");
432
+13
--- src/setup.c
+++ src/setup.c
@@ -1159,10 +1159,23 @@
11591159
@ this setting. N may be fractional. So, for example, to only keep
11601160
@ an historical record of chat messages for 12 hours, set this value
11611161
@ to 0.5.
11621162
@ (Property: "chat-keep-days")</p>
11631163
@ <hr />
1164
+ entry_attribute("Chat Polling Timeout", 10,
1165
+ "chat-poll-timeout", "chatpt", "420", 0);
1166
+ @ <p>New chat content is downloaded using the "long poll" technique.
1167
+ @ HTTP requests are made to /chat-poll which blocks waiting on new
1168
+ @ content to arrive. But the /chat-poll cannot block forever. It
1169
+ @ eventual must give up and return an empty message set. This setting
1170
+ @ determines how long /chat-poll will wait before giving up. The
1171
+ @ default setting of approximately 7 minutes works well on many systems.
1172
+ @ Shorter delays might be required on installations that use proxies
1173
+ @ or web-servers with short timeouts. For best efficiency, this value
1174
+ @ should be larger rather than smaller.
1175
+ @ (Property: "chat-chat-timeout")</p>
1176
+ @ </hr>
11641177
@ <p><input type="submit" name="submit" value="Apply Changes" /></p>
11651178
@ </div></form>
11661179
db_end_transaction(0);
11671180
style_finish_page();
11681181
}
11691182
--- src/setup.c
+++ src/setup.c
@@ -1159,10 +1159,23 @@
1159 @ this setting. N may be fractional. So, for example, to only keep
1160 @ an historical record of chat messages for 12 hours, set this value
1161 @ to 0.5.
1162 @ (Property: "chat-keep-days")</p>
1163 @ <hr />
 
 
 
 
 
 
 
 
 
 
 
 
 
1164 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1165 @ </div></form>
1166 db_end_transaction(0);
1167 style_finish_page();
1168 }
1169
--- src/setup.c
+++ src/setup.c
@@ -1159,10 +1159,23 @@
1159 @ this setting. N may be fractional. So, for example, to only keep
1160 @ an historical record of chat messages for 12 hours, set this value
1161 @ to 0.5.
1162 @ (Property: "chat-keep-days")</p>
1163 @ <hr />
1164 entry_attribute("Chat Polling Timeout", 10,
1165 "chat-poll-timeout", "chatpt", "420", 0);
1166 @ <p>New chat content is downloaded using the "long poll" technique.
1167 @ HTTP requests are made to /chat-poll which blocks waiting on new
1168 @ content to arrive. But the /chat-poll cannot block forever. It
1169 @ eventual must give up and return an empty message set. This setting
1170 @ determines how long /chat-poll will wait before giving up. The
1171 @ default setting of approximately 7 minutes works well on many systems.
1172 @ Shorter delays might be required on installations that use proxies
1173 @ or web-servers with short timeouts. For best efficiency, this value
1174 @ should be larger rather than smaller.
1175 @ (Property: "chat-chat-timeout")</p>
1176 @ </hr>
1177 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1178 @ </div></form>
1179 db_end_transaction(0);
1180 style_finish_page();
1181 }
1182

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button