From 3b443abec254cb8214881e11af4c09e923cd2dd1 Mon Sep 17 00:00:00 2001 From: Hu Keping Date: Sat, 19 Sep 2015 17:58:43 +0800 Subject: [PATCH] Comment: add description for some code which hard to understand Signed-off-by: Hu Keping --- api/server/daemon.go | 6 +++++- daemon/stats.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/server/daemon.go b/api/server/daemon.go index df3cba9704..b8ee0fa46e 100644 --- a/api/server/daemon.go +++ b/api/server/daemon.go @@ -111,8 +111,12 @@ func (s *Server) getEvents(ctx context.Context, w http.ResponseWriter, r *http.R d := s.daemon es := d.EventsService w.Header().Set("Content-Type", "application/json") + outStream := ioutils.NewWriteFlusher(w) - outStream.Write(nil) // make sure response is sent immediately + // Write an empty chunk of data. + // This is to ensure that the HTTP status code is sent immediately, + // so that it will not block the receiver. + outStream.Write(nil) enc := json.NewEncoder(outStream) getContainerID := func(cn string) string { diff --git a/daemon/stats.go b/daemon/stats.go index bf8f2a7575..bdf4c57078 100644 --- a/daemon/stats.go +++ b/daemon/stats.go @@ -40,6 +40,9 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats } if config.Stream { + // Write an empty chunk of data. + // This is to ensure that the HTTP status code is sent immediately, + // even if the container has not yet produced any data. config.OutStream.Write(nil) }