path: root/
diff options
authorJakub Narebski <>2010-05-28 19:11:24 (GMT)
committerJunio C Hamano <>2010-06-02 18:49:33 (GMT)
commitd94775e1f9a9239a823b9aa52d754f9ec2635e6d (patch)
treefe08ad9da75c39405a91958be3418178d8ed897b /
parentd1127622f5e4aa2abf6b492f6e43c0e17c3e0442 (diff)
git-instaweb: Wait for server to start before running web browser
Add generic httpd_is_ready subroutine, which busy-waits for web server to be started, by checking if $port is opened on localhost. This is used to avoid situation where web browser is started before web server is ready to accept connection, and fails. It uses IO::Socket::INET module, which is core Perl module since v5.6.0. Alternate solution, possible for those web servers that can run arbitrary code hooks after they bind the listen socket (after they start accepting connections), would be to use some kind of blocking mechanism: FIFO or lockfile, see This can be always added later, as a web server specific branch in httpd_is_ready function. Signed-off-by: Jakub Narebski <> Acked-by: Petr Baudis <> Acked-by: Eric Wong <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to '')
1 files changed, 15 insertions, 2 deletions
diff --git a/ b/
index a8c5dc0..dc8478f 100755
--- a/
+++ b/
@@ -117,6 +117,19 @@ stop_httpd () {
rm -f "$fqgitdir/pid"
+httpd_is_ready () {
+ "$PERL" -MIO::Socket::INET -e "
+local \$| = 1; # turn on autoflush
+exit if (IO::Socket::INET->new('$port'));
+print 'Waiting for \'$httpd\' to start ..';
+do {
+ print '.';
+ sleep(1);
+} until (IO::Socket::INET->new('$port'));
+print qq! (done)\n!;
while test $# != 0
case "$1" in
@@ -414,7 +427,7 @@ start_httpd
if test -n "$browser"; then
- git web--browse -b "$browser" $url || echo $url
+ httpd_is_ready && git web--browse -b "$browser" $url || echo $url
- git web--browse -c "instaweb.browser" $url || echo $url
+ httpd_is_ready && git web--browse -c "instaweb.browser" $url || echo $url