|
@@ -2,6 +2,7 @@ package bus
|
|
|
|
|
|
import (
|
|
|
"encoding/hex"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"net"
|
|
|
"reflect"
|
|
@@ -37,7 +38,7 @@ type DtuServer struct {
|
|
|
}
|
|
|
|
|
|
func (dtu *DtuServer) ResetChannel(chn IChannel) {
|
|
|
-
|
|
|
+ dtu.baseBus.ResetChannel(chn)
|
|
|
}
|
|
|
|
|
|
func (dtu *DtuServer) closeConn(conn net.Conn, connid int, chn IChannel) {
|
|
@@ -93,6 +94,7 @@ func (dtu *DtuServer) ClientConnect(conn net.Conn, connectID int, PassiveFlag bo
|
|
|
log.Infof("read from %s header faild err:[%v]\n", remoteAddr, err)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
log.Infof("Connect %d (passive devices port:%t) with code %X", connectID, PassiveFlag, buf[:n])
|
|
|
ic = dtu.baseBus.ScanChannel(buf[:n], connectID)
|
|
|
if ic != nil {
|
|
@@ -124,6 +126,7 @@ func (dtu *DtuServer) ClientConnect(conn net.Conn, connectID int, PassiveFlag bo
|
|
|
case msg := <-chnout:
|
|
|
conn.Write(msg.([]byte))
|
|
|
case <-after:
|
|
|
+ log.Info("timeafter for write message")
|
|
|
break
|
|
|
}
|
|
|
}
|
|
@@ -132,12 +135,14 @@ func (dtu *DtuServer) ClientConnect(conn net.Conn, connectID int, PassiveFlag bo
|
|
|
|
|
|
if ic.(*BusChannel).timeout != 0 {
|
|
|
conn.SetReadDeadline(time.Now().Add(ic.(*BusChannel).timeout))
|
|
|
+ } else {
|
|
|
+ conn.SetReadDeadline(time.Now().Add(30 * time.Minute))
|
|
|
}
|
|
|
n, err = conn.Read(buf[:])
|
|
|
if err != nil {
|
|
|
log.Errorf("read from %s msg faild err:[%v]\n", ic.ID(), err)
|
|
|
- dtu.closeConn(conn, connectID, ic)
|
|
|
- break
|
|
|
+ chnin <- "closed"
|
|
|
+ break //return and close connection
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -241,11 +246,13 @@ func (dtu *DtuServer) Send(ichn IChannel, buff interface{}) (int, error) {
|
|
|
if connID >= 0 {
|
|
|
if conn, has := dtu.connlist[connID]; has {
|
|
|
conn.Write(buff.([]byte))
|
|
|
+ return len(buff.([]byte)), nil
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return dtu.baseBus.Send(ichn, buff)
|
|
|
+
|
|
|
+ return 0, errors.New("no such connection")
|
|
|
}
|
|
|
|
|
|
func GetFtpServerConfig(param []interface{}) int {
|