Commit 74b080a9 authored by AlexStocks's avatar AlexStocks

use ReadFromUDP as the uniform read interface

parent 8a2c5fb6
......@@ -5,7 +5,7 @@
## introdction ##
---
Getty is a asynchronous network I/O library in golang. Getty is based on "ngo" whose author is sanbit(https://github.com/sanbit). Getty works on tcp/udp/websocket network protocol and supplies [a uniform interface](https://github.com/alexstocks/getty/blob/master/getty.go#L45).
Getty is a asynchronous network I/O library in golang. Getty is based on "ngo" whose author is [sanbit](https://github.com/sanbit). Getty works on tcp/udp/websocket network protocol and supplies [a uniform interface](https://github.com/alexstocks/getty/blob/master/getty.go#L45).
In getty there are two goroutines in one connection(session), one reads tcp stream/udp packet/websocket package, the other handles logic process and writes response into network write buffer. If your logic process may take a long time, you should start a new logic process goroutine by yourself in codec.go:(Codec)OnMessage.
......
......@@ -18,6 +18,7 @@
> improvement
* nerr -> netError
* check udp connection alive after connect()
* use ReadFromUDP as the uniform UDP read interface
- 2018/03/17
> improvement
......
......@@ -387,12 +387,8 @@ func (u *gettyUDPConn) read(p []byte) (int, *net.UDPAddr, error) {
}
}
if u.ss.EndPointType() == UDP_CLIENT {
length, err = u.conn.Read(p)
} else {
length, addr, err = u.conn.ReadFromUDP(p)
}
log.Debug("now:%s, length:%d, err:%s", currentTime, length, err)
length, addr, err = u.conn.ReadFromUDP(p) // connected udp also can get return @addr
log.Debug("ReadFromUDP() = {length:%d, peerAddr:%s, error:%s}", length, addr, err)
if err == nil {
atomic.AddUint32(&u.readCount, uint32(length))
}
......@@ -441,7 +437,7 @@ func (u *gettyUDPConn) Write(udpCtx interface{}) (int, error) {
atomic.AddUint32(&u.writeCount, (uint32)(len(buf)))
length, _, err = u.conn.WriteMsgUDP(buf, nil, peerAddr)
log.Debug("now:%s, length:%d, err:%s, peerAddr:%s", currentTime, length, err, peerAddr)
log.Debug("WriteMsgUDP(peerAddr:%s) = {length:%d, error:%s}", peerAddr, length, err)
return length, err
}
......
......@@ -641,7 +641,7 @@ func (s *session) handleUDPPackage() error {
}
bufLen, addr, err = conn.read(buf)
log.Debug("conn.read() = bufLen:%d, addr:%#v, err:%s", bufLen, pkgLen, err)
log.Debug("conn.read() = bufLen:%d, addr:%#v, err:%s", bufLen, addr, err)
if netError, ok = err.(net.Error); ok && netError.Timeout() {
continue
}
......
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