mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
减少service不必要的循环
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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服务的名称
|
||||
|
||||
Reference in New Issue
Block a user