overflow_discovery/server/server_handlers.go
crusader 1f366db739 ing
2017-11-01 19:05:50 +09:00

43 lines
671 B
Go

package server
import (
"net"
"os"
"git.loafle.net/commons_go/rpc/server"
)
func NewServerHandler(addr string) *ServerHandlers {
sh := &ServerHandlers{}
sh.addr = addr
return sh
}
type ServerHandlers struct {
server.ServerHandlers
addr string
}
func (sh *ServerHandlers) OnStart() {
// no op
}
func (sh *ServerHandlers) OnStop() {
// no op
}
func (sh *ServerHandlers) Listen() (net.Listener, error) {
os.Remove(sh.addr)
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sh.addr, Net: "unix"})
if nil == err {
os.Chmod(sh.addr, 0777)
}
return l, err
}
func (sh *ServerHandlers) OnAccept(conn net.Conn) (net.Conn, error) {
return conn, nil
}