减少service不必要的循环

This commit is contained in:
boyce
2019-01-30 14:55:40 +08:00
parent 34002c31a0
commit 91364a7cd8
5 changed files with 13 additions and 5 deletions

View File

@@ -105,11 +105,13 @@ func (slf *CCluster) ListenService() error {
tcpaddr, err := net.ResolveTCPAddr("tcp4", bindStr)
if err != nil {
os.Exit(1)
return err
}
tcplisten, err2 := net.ListenTCP("tcp", tcpaddr)
if err2 != nil {
os.Exit(1)
return err2
}

View File

@@ -3,6 +3,7 @@ package network
import (
"fmt"
"net/http"
"os"
"time"
)
@@ -45,6 +46,7 @@ func (slf *HttpServer) startListen() error {
err := slf.httpserver.ListenAndServe()
if err != nil {
fmt.Printf("http.ListenAndServe(%d, nil) error\n", slf.port)
os.Exit(1)
}
return nil

View File

@@ -3,6 +3,7 @@ package network
import (
"fmt"
"net/http"
"os"
"sync"
"time"
@@ -101,6 +102,7 @@ func (slf *WebsocketServer) startListen() {
err := slf.httpserver.ListenAndServe()
if err != nil {
fmt.Printf("http.ListenAndServe(%d, nil) error\n", slf.port)
os.Exit(1)
}
}

View File

@@ -139,7 +139,7 @@ func (slf *BaseService) Init(Iservice interface{}, servicetype int) error {
}
func (slf *BaseService) OnRunLoop() error {
return nil
return fmt.Errorf("None Loop")
}
func (slf *BaseService) Run(service IService, exit chan bool, pwaitGroup *sync.WaitGroup) error {
@@ -153,7 +153,9 @@ func (slf *BaseService) Run(service IService, exit chan bool, pwaitGroup *sync.W
default:
}
slf.tickTime = time.Now().UnixNano() / 1e6
service.OnRunLoop()
if service.OnRunLoop() != nil {
break
}
slf.tickTime = time.Now().UnixNano() / 1e6
}

View File

@@ -85,8 +85,8 @@ func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request
w.Write([]byte(msg))
}
if r.Method != "POST" {
writeError(http.StatusMethodNotAllowed, "rpc: POST method required, received "+r.Method)
return
//writeError(http.StatusMethodNotAllowed, "rpc: POST method required, received "+r.Method)
//return
}
defer r.Body.Close()
msg, err := ioutil.ReadAll(r.Body)
@@ -94,7 +94,7 @@ func (slf *HttpServerService) httpHandler(w http.ResponseWriter, r *http.Request
writeError(http.StatusBadRequest, "rpc: ioutil.ReadAll "+err.Error())
return
}
fmt.Printf("PATH: %s\n%s\n", r.URL.Path, string(msg))
// 在这儿处理例外路由接口
// 拼接得到rpc服务的名称