mirror of
https://github.com/hbahadorzadeh/stunning.git
synced 2025-12-24 13:38:08 +08:00
iowait problem solved
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user