Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7adba5f

Browse files
carlosmnvmg
authored andcommitted
Keep sending want lines if the server doesn't anwer a flush
Some servers take a long time to answer and expect us to keep sending want lines; otherwise they close the connection. Avoid this by waiting for one second for the server to answer. If the timeout runs out, treat is as a NAK and keep sending want lines. Signed-off-by: Carlos Martín Nieto <[email protected]>
1 parent 427ca3d commit 7adba5f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/transport_git.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* Boston, MA 02110-1301, USA.
2424
*/
2525

26+
#include <sys/select.h>
27+
2628
#include "git2/net.h"
2729
#include "git2/common.h"
2830
#include "git2/types.h"
@@ -388,6 +390,27 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
388390
git_pkt *pkt;
389391
git_pkt_send_flush(t->socket);
390392
while (1) {
393+
fd_set fds;
394+
struct timeval tv;
395+
396+
FD_ZERO(&fds);
397+
FD_SET(t->socket, &fds);
398+
tv.tv_sec = 1; /* Wait for max. 1 second */
399+
tv.tv_usec = 0;
400+
401+
/* The select(2) interface is silly */
402+
error = select(t->socket + 1, &fds, NULL, NULL, &tv);
403+
if (error < GIT_SUCCESS) {
404+
error = git__throw(GIT_EOSERR, "Error in select");
405+
} else if (error == 0) {
406+
/*
407+
* Some servers don't respond immediately, so if this
408+
* happens, we keep sending information until it
409+
* answers.
410+
*/
411+
break;
412+
}
413+
391414
error = gitno_recv(&buf);
392415
if (error < GIT_SUCCESS) {
393416
error = git__rethrow(error, "Error receiving data");

0 commit comments

Comments
 (0)