2017-10-26 12:55:55 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2017-11-01 06:35:03 +00:00
|
|
|
"net"
|
|
|
|
"os"
|
2017-10-26 12:55:55 +00:00
|
|
|
|
2017-11-01 06:35:03 +00:00
|
|
|
"git.loafle.net/commons_go/rpc/server"
|
2017-10-26 12:55:55 +00:00
|
|
|
)
|
|
|
|
|
2017-11-01 10:05:50 +00:00
|
|
|
func NewServerHandler(addr string) *ServerHandlers {
|
2017-10-31 10:27:26 +00:00
|
|
|
sh := &ServerHandlers{}
|
2017-11-01 06:35:03 +00:00
|
|
|
sh.addr = addr
|
|
|
|
|
2017-10-26 12:55:55 +00:00
|
|
|
return sh
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServerHandlers struct {
|
2017-11-01 06:35:03 +00:00
|
|
|
server.ServerHandlers
|
2017-10-26 12:55:55 +00:00
|
|
|
|
2017-11-01 06:35:03 +00:00
|
|
|
addr string
|
2017-10-26 12:55:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 06:35:03 +00:00
|
|
|
func (sh *ServerHandlers) OnStart() {
|
|
|
|
// no op
|
|
|
|
}
|
2017-10-26 13:18:20 +00:00
|
|
|
|
2017-11-01 06:35:03 +00:00
|
|
|
func (sh *ServerHandlers) OnStop() {
|
|
|
|
// no op
|
|
|
|
}
|
2017-10-26 13:18:20 +00:00
|
|
|
|
2017-11-01 06:35:03 +00:00
|
|
|
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)
|
2017-10-26 13:18:20 +00:00
|
|
|
}
|
2017-11-01 06:35:03 +00:00
|
|
|
return l, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *ServerHandlers) OnAccept(conn net.Conn) (net.Conn, error) {
|
|
|
|
return conn, nil
|
|
|
|
}
|