From bbc54cabb7ff6b4a5482fff38b472760c9798d68 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 26 Mar 2014 12:24:28 -0700 Subject: [PATCH] beam/examples/beamsh: utility function 'fileToConn' Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: fb1af1f0bc87712a41a47829e12a2f273b2c8a55 Component: engine --- .../engine/pkg/beam/examples/beamsh/beamsh.go | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/engine/pkg/beam/examples/beamsh/beamsh.go b/components/engine/pkg/beam/examples/beamsh/beamsh.go index 60a13c729f..837622d3e1 100644 --- a/components/engine/pkg/beam/examples/beamsh/beamsh.go +++ b/components/engine/pkg/beam/examples/beamsh/beamsh.go @@ -290,16 +290,10 @@ func GetHandler(name string) Handler { beam.Send(out, data.Empty().Set("status", "1").Set("message", err.Error()).Bytes(), nil) return } - var f *os.File - if connWithFile, ok := conn.(interface { File() (*os.File, error) }); !ok { + f, err := connToFile(conn) + if err != nil { conn.Close() continue - } else { - f, err = connWithFile.File() - if err != nil { - conn.Close() - continue - } } beam.Send(out, data.Empty().Set("type", "socket").Set("remoteaddr", conn.RemoteAddr().String()).Bytes(), f) } @@ -369,6 +363,17 @@ func GetHandler(name string) Handler { return nil } +func connToFile(conn net.Conn) (f *os.File, err error) { + if connWithFile, ok := conn.(interface { File() (*os.File, error) }); !ok { + return nil, fmt.Errorf("no file descriptor available") + } else { + f, err = connWithFile.File() + if err != nil { + return nil, err + } + } + return f, err +} // 'status' is a notification of a job's status. //