iowait problem solved

This commit is contained in:
Hamed Bahadorzadeh
2018-06-30 22:33:17 +04:30
parent 67a8b7c1dc
commit c45e1931cd
2 changed files with 11 additions and 5 deletions

View File

@@ -17,11 +17,11 @@ func GetUdpDialer() UdpDialer {
}
func (d UdpDialer) Dial(network, addr string) (c net.Conn, err error) {
rudpAddr, err := net.ResolveUDPAddr("udp", addr)
rudpAddr, err := net.ResolveUDPAddr(network, addr)
if err != nil {
return nil, err
}
ludpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:5050")
ludpAddr, err := net.ResolveUDPAddr(network, ":0")
if err != nil {
return nil, err
}
@@ -31,5 +31,6 @@ func (d UdpDialer) Dial(network, addr string) (c net.Conn, err error) {
}
return udp_connection{
conn: conn,
addr:nil,
}, err
}

View File

@@ -50,20 +50,25 @@ type udp_connection struct {
}
func (u udp_connection) Read(b []byte) (n int, err error) {
u.conn.ReadFromUDP(b)
n, _ , err = u.conn.ReadFrom(b)
return n, err
}
// Write writes data to the connection.
// Write can be made to time out and return an Error with Timeout() == true
// after a fixed time limit; see SetDeadline and SetWriteDeadline.
func (u udp_connection) Write(b []byte) (n int, err error) {
return u.conn.WriteToUDP(b, u.addr)
if u.addr != nil {
return u.conn.WriteToUDP(b, u.addr)
}else {
return u.conn.Write(b)
}
}
// Close closes the connection.
// Any blocked Read or Write operations will be unblocked and return errors.
func (u udp_connection) Close() error {
return u.Close()
return u.conn.Close()
}
// LocalAddr returns the local network address.