Commit f83552e6 authored by alexstocks's avatar alexstocks

use goext

parent 99e8cdfa
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
## develop history ## ## develop history ##
--- ---
- 2016/09/26
> 1 move utils.go's function to github.com/AlexStocks/goext and delete it
- 2016/09/20 - 2016/09/20
> 1 just invoke OnError when session got error > 1 just invoke OnError when session got error
> >
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
) )
import ( import (
"github.com/AlexStocks/goext/net"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
) )
...@@ -67,7 +68,7 @@ func (this *Server) Bind(network string, host string, port int) error { ...@@ -67,7 +68,7 @@ func (this *Server) Bind(network string, host string, port int) error {
return errors.New("port<=0 illegal") return errors.New("port<=0 illegal")
} }
return this.Listen(network, HostAddress(host, port)) return this.Listen(network, gxnet.HostAddress(host, port))
} }
func (this *Server) Listen(network string, addr string) error { func (this *Server) Listen(network string, addr string) error {
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
) )
import ( import (
"github.com/AlexStocks/goext/time"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
) )
...@@ -361,7 +362,7 @@ func (this *Session) handleLoop() { ...@@ -361,7 +362,7 @@ func (this *Session) handleLoop() {
err error err error
flag bool flag bool
// start time.Time // start time.Time
counter CountWatch counter gxtime.CountWatch
ticker *time.Ticker ticker *time.Ticker
inPkg interface{} inPkg interface{}
outPkg interface{} outPkg interface{}
......
/******************************************************
# DESC : getty utility
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-22 17:44
# FILE : utils.go
******************************************************/
package getty
import (
"net"
"strconv"
"time"
)
/////////////////////////////////////////
// network utility
/////////////////////////////////////////
// HostAddress composes a ip:port style address. Its opposite function is net.SplitHostPort.
func HostAddress(host string, port int) string {
return net.JoinHostPort(host, strconv.Itoa(port))
}
func HostAddress2(host string, port string) string {
return net.JoinHostPort(host, port)
}
func HostPort(addr string) (string, string, error) {
return net.SplitHostPort(addr)
}
/////////////////////////////////////////
// count watch
/////////////////////////////////////////
type CountWatch struct {
start time.Time
}
func (w *CountWatch) Start() {
var t time.Time
if t.Equal(w.start) {
w.start = time.Now()
}
}
func (w *CountWatch) Reset() {
w.start = time.Now()
}
func (w *CountWatch) Count() int64 {
return time.Since(w.start).Nanoseconds()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment