3636#endif
3737
3838extern int am_server ;
39+ extern int am_daemon ;
40+ extern int always_checksum ;
3941extern int whole_file ;
4042extern int checksum_seed ;
4143extern int protocol_version ;
4244extern int proper_seed_order ;
4345extern const char * checksum_choice ;
46+ extern void maybe_send_keepalive (time_t now , int flags );
47+
48+ static time_t last_checksum_keepalive = 0 ;
49+
50+ static inline void send_checksum_keepalive (void )
51+ {
52+ time_t now ;
53+
54+ if (!am_daemon || !always_checksum )
55+ return ;
56+
57+ now = time (NULL );
58+ if (now - last_checksum_keepalive >= 5 ) {
59+ last_checksum_keepalive = now ;
60+ maybe_send_keepalive (now , MSK_ALLOW_FLUSH );
61+ }
62+ }
4463
4564#define NNI_BUILTIN (1<<0)
4665#define NNI_EVP (1<<1)
@@ -421,8 +440,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
421440
422441 EVP_DigestInit_ex (evp , file_sum_evp_md , NULL );
423442
424- for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE )
443+ for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE ) {
425444 EVP_DigestUpdate (evp , (uchar * )map_ptr (buf , i , CHUNK_SIZE ), CHUNK_SIZE );
445+ send_checksum_keepalive ();
446+ }
426447
427448 remainder = (int32 )(len - i );
428449 if (remainder > 0 )
@@ -440,8 +461,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
440461
441462 XXH64_reset (state , 0 );
442463
443- for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE )
464+ for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE ) {
444465 XXH64_update (state , (uchar * )map_ptr (buf , i , CHUNK_SIZE ), CHUNK_SIZE );
466+ send_checksum_keepalive ();
467+ }
445468
446469 remainder = (int32 )(len - i );
447470 if (remainder > 0 )
@@ -459,8 +482,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
459482
460483 XXH3_64bits_reset (state );
461484
462- for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE )
485+ for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE ) {
463486 XXH3_64bits_update (state , (uchar * )map_ptr (buf , i , CHUNK_SIZE ), CHUNK_SIZE );
487+ send_checksum_keepalive ();
488+ }
464489
465490 remainder = (int32 )(len - i );
466491 if (remainder > 0 )
@@ -477,8 +502,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
477502
478503 XXH3_128bits_reset (state );
479504
480- for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE )
505+ for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE ) {
481506 XXH3_128bits_update (state , (uchar * )map_ptr (buf , i , CHUNK_SIZE ), CHUNK_SIZE );
507+ send_checksum_keepalive ();
508+ }
482509
483510 remainder = (int32 )(len - i );
484511 if (remainder > 0 )
@@ -495,8 +522,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
495522
496523 md5_begin (& m5 );
497524
498- for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE )
525+ for (i = 0 ; i + CHUNK_SIZE <= len ; i += CHUNK_SIZE ) {
499526 md5_update (& m5 , (uchar * )map_ptr (buf , i , CHUNK_SIZE ), CHUNK_SIZE );
527+ send_checksum_keepalive ();
528+ }
500529
501530 remainder = (int32 )(len - i );
502531 if (remainder > 0 )
@@ -513,8 +542,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
513542
514543 mdfour_begin (& m );
515544
516- for (i = 0 ; i + CSUM_CHUNK <= len ; i += CSUM_CHUNK )
545+ for (i = 0 ; i + CSUM_CHUNK <= len ; i += CSUM_CHUNK ) {
517546 mdfour_update (& m , (uchar * )map_ptr (buf , i , CSUM_CHUNK ), CSUM_CHUNK );
547+ send_checksum_keepalive ();
548+ }
518549
519550 /* Prior to version 27 an incorrect MD4 checksum was computed
520551 * by failing to call mdfour_tail() for block sizes that
0 commit comments