fix: mml enhancement
This commit is contained in:
@@ -21,10 +21,10 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
//经过测试,linux下,延时需要大于100ms
|
||||
TIME_DELAY_AFTER_WRITE = 200
|
||||
)
|
||||
// const (
|
||||
// //经过测试,linux下,延时需要大于100ms
|
||||
// TIME_DELAY_AFTER_WRITE = 200
|
||||
// )
|
||||
|
||||
type Response struct {
|
||||
Data []string `json:"data"`
|
||||
@@ -48,6 +48,15 @@ var (
|
||||
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
|
||||
)
|
||||
|
||||
// func init() {
|
||||
// if config.GetYamlConfig().MML.Sleep != 0 {
|
||||
// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||
// }
|
||||
// if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||
// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||
// }
|
||||
// }
|
||||
|
||||
func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("PostMMLToNF processing... ")
|
||||
|
||||
@@ -56,6 +65,16 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
log.Error("Request error:", err)
|
||||
return
|
||||
}
|
||||
// 经过测试,linux下,延时需要大于100ms
|
||||
var TIME_DELAY_AFTER_WRITE time.Duration = 200
|
||||
var TIME_DEAD_LINE time.Duration = 10
|
||||
if config.GetYamlConfig().MML.Sleep != 0 {
|
||||
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
|
||||
}
|
||||
if config.GetYamlConfig().MML.DeadLine != 0 {
|
||||
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
|
||||
}
|
||||
|
||||
pack := "mml"
|
||||
vars := mux.Vars(r)
|
||||
module := vars["managedType"]
|
||||
@@ -73,6 +92,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
token, r.Method, module, neType, neId[0], pack)
|
||||
|
||||
var buf [20 * 1024]byte
|
||||
//buf := make([]byte, 0)
|
||||
var n int
|
||||
var mmlResult []string
|
||||
|
||||
@@ -215,7 +235,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||
|
||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||
_, err = conn.Write([]byte(loginStr))
|
||||
@@ -254,7 +274,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符
|
||||
//re := regexp.MustCompile(`[\x00-\x1F\x7F]`)
|
||||
// upf telnet buffer只能读取一次,需要去掉前面的多余字符
|
||||
result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
||||
//result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "")
|
||||
result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "")
|
||||
result = re2.ReplaceAllString(result, "")
|
||||
mmlResult = append(mmlResult, result)
|
||||
conn.Close()
|
||||
@@ -286,7 +307,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
// services.ResponseWithJson(w, http.StatusOK, response)
|
||||
// return
|
||||
// }
|
||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||
|
||||
_, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n"))
|
||||
if err != nil {
|
||||
@@ -405,7 +426,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
|
||||
// return
|
||||
// }
|
||||
|
||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
|
||||
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)
|
||||
_, err = conn.Write([]byte(loginStr))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user