@@ -40,6 +40,7 @@ static struct object_array have_obj;
40
40
static struct object_array want_obj ;
41
41
static struct object_array extra_edge_obj ;
42
42
static unsigned int timeout ;
43
+ static int keepalive = 5 ;
43
44
/* 0 for no sideband,
44
45
* otherwise maximum packet size (up to 65520 bytes).
45
46
*/
@@ -200,6 +201,7 @@ static void create_pack_file(void)
200
201
while (1 ) {
201
202
struct pollfd pfd [2 ];
202
203
int pe , pu , pollsize ;
204
+ int ret ;
203
205
204
206
reset_timeout ();
205
207
@@ -222,7 +224,8 @@ static void create_pack_file(void)
222
224
if (!pollsize )
223
225
break ;
224
226
225
- if (poll (pfd , pollsize , -1 ) < 0 ) {
227
+ ret = poll (pfd , pollsize , 1000 * keepalive );
228
+ if (ret < 0 ) {
226
229
if (errno != EINTR ) {
227
230
error ("poll failed, resuming: %s" ,
228
231
strerror (errno ));
@@ -284,6 +287,21 @@ static void create_pack_file(void)
284
287
if (sz < 0 )
285
288
goto fail ;
286
289
}
290
+
291
+ /*
292
+ * We hit the keepalive timeout without saying anything; send
293
+ * an empty message on the data sideband just to let the other
294
+ * side know we're still working on it, but don't have any data
295
+ * yet.
296
+ *
297
+ * If we don't have a sideband channel, there's no room in the
298
+ * protocol to say anything, so those clients are just out of
299
+ * luck.
300
+ */
301
+ if (!ret && use_sideband ) {
302
+ static const char buf [] = "0005\1" ;
303
+ write_or_die (1 , buf , 5 );
304
+ }
287
305
}
288
306
289
307
if (finish_command (& pack_objects )) {
@@ -785,6 +803,11 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
785
803
{
786
804
if (!strcmp ("uploadpack.allowtipsha1inwant" , var ))
787
805
allow_tip_sha1_in_want = git_config_bool (var , value );
806
+ else if (!strcmp ("uploadpack.keepalive" , var )) {
807
+ keepalive = git_config_int (var , value );
808
+ if (!keepalive )
809
+ keepalive = -1 ;
810
+ }
788
811
return parse_hide_refs_config (var , value , "uploadpack" );
789
812
}
790
813
0 commit comments