本文整理汇总了Golang中net/rpc.ServeConn函数的典型用法代码示例。如果您正苦于以下问题:Golang ServeConn函数的具体用法?Golang ServeConn怎么用?Golang ServeConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServeConn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
if err := rpc.Register(plug); err != nil {
log.Fatal(err)
}
flag.Parse()
config()
bort.PluginInit(cfg.OutboxSize)
listen, err := net.Listen("tcp", cfg.Address)
if err != nil {
log.Fatalln(err)
}
for {
con, err := listen.Accept()
if err != nil {
log.Println(err)
time.Sleep(1 * time.Second)
continue
}
log.Println("connected to bort")
rpc.ServeConn(con)
log.Println("disconnected from bort")
}
}
示例2: Start
func (rs *RpcServer) Start() error {
serverAddr, err := net.ResolveTCPAddr(rs.net, rs.addr)
if err != nil {
return err
}
serverListener, err := net.ListenTCP(rs.net, serverAddr)
if err != nil {
return err
}
rs.listener = serverListener
go func(listener *net.TCPListener) {
for {
conn, err := listener.AcceptTCP()
if err != nil {
global.Logger.Warn("the RPC server accept the client link failure: %s", err.Error())
rs.Stop()
global.Logger.Warn("the RPC server has stopped!")
return
}
rpc.ServeConn(conn)
}
}(rs.listener)
return nil
}
示例3: main
func main() {
arith := new(Arith)
rpc.Register(arith)
/*
rpc.HandleHTTP()
err := http.ListenAndServe(":1234", nil)
if err != nil {
fmt.Println(err.Error())
}
*/
tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
if err != nil {
log.Fatal("resovleTCPAddr failed.", err)
return
}
ln, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
log.Fatal("listen failed.", err)
return
}
for {
conn, err := ln.Accept()
if err != nil {
continue
}
// go routine
go rpc.ServeConn(conn)
}
}
示例4: main
func main() {
arith := new(Arith)
rpc.Register(arith)
tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
checkError(err)
listener, err := net.ListenTCP("tcp", tcpAddr)
checkError(err)
/* This works:
rpc.Accept(listener)
*/
/* and so does this:
*/
for {
conn, err := listener.Accept()
if err != nil {
continue
}
rpc.ServeConn(conn)
}
}
示例5: loop
func (this *daemon) loop() {
conn_in := make(chan net.Conn)
go func() {
for {
c, err := this.listener.Accept()
if err != nil {
panic(err)
}
conn_in <- c
}
}()
timeout := time.Duration(g_config.CloseTimeout) * time.Second
countdown := time.NewTimer(timeout)
for {
// handle connections or server CMDs (currently one CMD)
select {
case c := <-conn_in:
rpc.ServeConn(c)
countdown.Reset(timeout)
runtime.GC()
case cmd := <-this.cmd_in:
switch cmd {
case daemon_close:
return
}
case <-countdown.C:
return
}
}
}
示例6: runServer
func runServer() {
go processCommands()
go runHTTPServer()
s := new(Server)
rpc.Register(s)
l, err := net.Listen("unix", sock)
defer os.Remove(sock)
if err != nil {
fatal(err)
}
s.quit = make(chan bool)
conns := make(chan net.Conn)
go func() {
for {
c, err := l.Accept()
if err != nil {
fatal(err)
}
conns <- c
}
}()
for {
select {
case c := <-conns:
go rpc.ServeConn(c)
case <-s.quit:
fmt.Println("Quitting.")
// Give shutdown RPC time to return normally.
time.Sleep(10 * time.Millisecond)
return
}
}
}
示例7: main
func main() {
math := new(Math)
rpc.Register(math)
tcpAddr, err := net.ResolveTCPAddr("tcp", ":1234")
if err != nil {
fmt.Println("Fatal error ", err.Error())
os.Exit(1)
}
listener, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
fmt.Println("Fatal error ", err.Error())
os.Exit(1)
}
for {
conn, err := listener.Accept()
if err != nil {
continue
}
rpc.ServeConn(conn)
}
}
示例8: BenchmarkGOBRPC_pipe
func BenchmarkGOBRPC_pipe(b *testing.B) {
cli, srv := net.Pipe()
go rpc.ServeConn(srv)
client := rpc.NewClient(cli)
defer client.Close()
benchmarkRPC(b, client)
}
示例9: main
func main() {
err := rpc.Register(new(Calc))
if err != nil {
fmt.Println(err)
return
}
listen, err := net.Listen("tcp", ":6000")
if err != nil {
fmt.Println(err)
return
}
defer listen.Close()
for {
conn, err := listen.Accept()
if err != nil {
fmt.Println(err)
continue
}
defer conn.Close()
go rpc.ServeConn(conn)
}
}
示例10: Serve
func (server *UmgmtServer) Serve() error {
relog.Info("started umgmt server: %v", server.listener.Addr())
for !server.quit {
conn, err := server.listener.Accept()
if err != nil {
if checkError(err, syscall.EINVAL) {
if server.quit {
return nil
}
return err
}
// syscall.EMFILE, syscall.ENFILE could happen here if you run out of file descriptors
relog.Error("accept error %v", err)
continue
}
server.Lock()
server.connMap[conn] = true
server.Unlock()
rpc.ServeConn(conn)
server.Lock()
delete(server.connMap, conn)
server.Unlock()
}
return nil
}
示例11: Start
func Start() {
if !g.Config().Rpc.Enabled {
return
}
addr := g.Config().Rpc.Listen
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
if err != nil {
log.Fatalf("net.ResolveTCPAddr fail: %s", err)
}
listener, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
log.Fatalf("listen %s fail: %s", addr, err)
} else {
log.Println("rpc listening", addr)
}
rpc.Register(new(Judge))
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("listener.Accept occur error: %s", err)
continue
}
go rpc.ServeConn(conn)
}
}
示例12: RunCatServerListener
func RunCatServerListener(listenURL string) {
println("Server opens connection.")
csr := CatServerRPC{make(map[string]*CatInfo)}
rpc.Register(&csr)
l, e := net.Listen("tcp", ":1887")
if e != nil {
log.Println("listen error:", e)
}
conChan := make(chan *net.Conn, 100)
// Close after 2 seconds, make it flap..
time.AfterFunc(2*time.Second, func() {
println("-- Server flaps connection.")
l.Close()
for a := range conChan {
(*a).Close()
}
})
for {
c, e := l.Accept()
if e != nil {
break // We cause this error.
}
conChan <- &c
go rpc.ServeConn(c)
}
println("Server exiting.")
}
示例13: rpcInit
func rpcInit() error {
cmd := new(Cmd)
rpc.Register(cmd)
l, err := net.Listen("unix", GlobalOpt.UnixSocket)
if err != nil {
return err
}
go func() {
var tempDelay time.Duration
for {
conn, err := l.Accept()
if err != nil {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
time.Sleep(tempDelay)
continue
}
tempDelay = 0
go func() {
rpc.ServeConn(conn)
}()
}
}()
return nil
}
示例14: loop
func (this *daemon) loop() {
conn_in := make(chan net.Conn)
go func() {
for {
c, err := this.listener.Accept()
if err != nil {
panic(err)
}
conn_in <- c
}
}()
for {
// handle connections or server CMDs (currently one CMD)
select {
case c := <-conn_in:
rpc.ServeConn(c)
runtime.GC()
case cmd := <-this.cmd_in:
switch cmd {
case daemon_close:
return
}
}
}
}
示例15: Serve
func Serve(c *lemon.CLI) error {
port := c.Port
allowIP := c.Allow
LineEndingOpt = c.LineEnding
ra, err := iprange.New(allowIP)
if err != nil {
return err
}
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return err
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
return err
}
for {
conn, err := l.Accept()
if err != nil {
log.Println(err)
continue
}
log.Printf("Request from %s", conn.RemoteAddr())
if !ra.InlucdeConn(conn) {
continue
}
connCh <- conn
rpc.ServeConn(conn)
}
}