summaryrefslogtreecommitdiff
path: root/src/nslcd_proto/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/nslcd_proto/util.go')
-rw-r--r--src/nslcd_proto/util.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/nslcd_proto/util.go b/src/nslcd_proto/util.go
new file mode 100644
index 0000000..38c5705
--- /dev/null
+++ b/src/nslcd_proto/util.go
@@ -0,0 +1,62 @@
+package nslcd_proto
+
+import "io"
+
+type NslcdError string
+
+func (o NslcdError) Error() string {
+ return string(o)
+}
+
+func Write(fd io.Writer, data interface{}) (err error) {
+ err = nil
+ defer func() {
+ if r := recover(); r != nil {
+ switch r := r.(type) {
+ case error:
+ err = r
+ default:
+ panic(r)
+ }
+ }
+ }()
+ write(fd, data)
+ return
+}
+
+func Read(fd io.Reader, data interface{}) (err error) {
+ err = nil
+ defer func() {
+ if r := recover(); r != nil {
+ switch r := r.(type) {
+ case error:
+ err = r
+ default:
+ panic(r)
+ }
+ }
+ }()
+ read(fd, data)
+ return
+}
+
+func HandleRequest(in io.Reader, out io.Writer, backend Backend) (err error) {
+ err = nil
+ defer func() {
+ if r := recover(); r != nil {
+ switch r := r.(type) {
+ case error:
+ err = r
+ default:
+ panic(r)
+ }
+ }
+ }()
+ handleRequest(in, out, backend)
+ return
+}
+
+// Initialize() error { func
+// e := c.SetReadDeadline(...)
+// e := c.SetWriteDeadline(...)
+// }