beam/examples/beamsh: utility function 'fileToConn'

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-26 12:24:28 -07:00
parent 23dd017763
commit 251353380e

View file

@ -290,16 +290,10 @@ func GetHandler(name string) Handler {
beam.Send(out, data.Empty().Set("status", "1").Set("message", err.Error()).Bytes(), nil) beam.Send(out, data.Empty().Set("status", "1").Set("message", err.Error()).Bytes(), nil)
return return
} }
var f *os.File f, err := connToFile(conn)
if connWithFile, ok := conn.(interface { File() (*os.File, error) }); !ok { if err != nil {
conn.Close() conn.Close()
continue 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) 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 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. // 'status' is a notification of a job's status.
// //