diff options
Diffstat (limited to 'src/nslcd_proto/func_handlerequest.go.sh')
-rwxr-xr-x | src/nslcd_proto/func_handlerequest.go.sh | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/nslcd_proto/func_handlerequest.go.sh b/src/nslcd_proto/func_handlerequest.go.sh index 45e0ed6..de9a6b7 100755 --- a/src/nslcd_proto/func_handlerequest.go.sh +++ b/src/nslcd_proto/func_handlerequest.go.sh @@ -9,10 +9,6 @@ import ( "io" ) -type enumerator interface { - GenericGetNext() (n *interface{}, err error) -} - func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) { var version int32 read(in, &version) @@ -22,7 +18,7 @@ func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) { var action int32 read(in, &action) - var res enumerator = nil + res := make(chan interface{}) switch action { $( while read -r request; do @@ -31,7 +27,15 @@ while read -r request; do var req Request_${request} read(in, &req) fmt.Printf("request: %#v\n", req) - res = backend.${request}(cred, req) + _res := backend.${request}(cred, req) + go func() { + o, ok := <-_res + if ok { + res <- o + } else { + close(res) + } + }() EOT done < "$requests" ) @@ -44,14 +48,9 @@ done < "$requests" write(out, NSLCD_VERSION) write(out, action) - var result *interface{} - var err error - for result, err = res.GenericGetNext(); (result != nil) && (err == nil); result, err = res.GenericGetNext() { + for result, ok := <-res; ok; result, ok = <-res { write(out, NSLCD_RESULT_BEGIN) - write(out, *result) - } - if err != nil { - panic(err) + write(out, result) } write(out, NSLCD_RESULT_END) } |