diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-11 16:18:20 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-11 16:18:20 +0200 |
commit | a4eff12d7f749c992247579161c4ce9e60e2df47 (patch) | |
tree | 6032dd0a96ced8313d7199e569ab657f3ba91ca7 /src/conn.go | |
parent | cba1d6585ab9b12ae3e0897db85675ba452c3f09 (diff) |
Improved receive.go
- Fixed configuration listen-port semantics
- Improved receive.go code for updating listen port
- Updated under load detection, how follows the kernel space implementation
- Fixed trie bug accidentally introduced in last commit
- Added interface name to log (format still subject to change)
- Can now configure the logging level using the LOG_LEVEL variable
- Begin porting netsh.sh tests
- A number of smaller changes
Diffstat (limited to 'src/conn.go')
-rw-r--r-- | src/conn.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/conn.go b/src/conn.go new file mode 100644 index 0000000..f6472e9 --- /dev/null +++ b/src/conn.go @@ -0,0 +1,40 @@ +package main + +import ( + "net" +) + +func updateUDPConn(device *Device) error { + var err error + netc := &device.net + netc.mutex.Lock() + + // close existing connection + + if netc.conn != nil { + netc.conn.Close() + } + + // open new connection + + if device.tun.isUp.Get() { + conn, err := net.ListenUDP("udp", netc.addr) + if err == nil { + netc.conn = conn + signalSend(device.signal.newUDPConn) + } + } + + netc.mutex.Unlock() + return err +} + +func closeUDPConn(device *Device) { + netc := &device.net + netc.mutex.Lock() + if netc.conn != nil { + netc.conn.Close() + } + netc.mutex.Unlock() + signalSend(device.signal.newUDPConn) +} |