Number of fixes in response to code review

This version cannot complete a handshake.
The program will panic upon receiving any message on the UDP socket.
This commit is contained in:
Mathias Hall-Andersen
2017-08-07 15:25:04 +02:00
parent 8c34c4cbb3
commit cba1d6585a
12 changed files with 552 additions and 445 deletions

View File

@@ -7,7 +7,6 @@ import (
"net"
"os"
"path"
"time"
)
const (
@@ -26,9 +25,10 @@ const (
*/
type UAPIListener struct {
listener net.Listener // unix socket listener
connNew chan net.Conn
connErr chan error
listener net.Listener // unix socket listener
connNew chan net.Conn
connErr chan error
inotifyFd int
}
func (l *UAPIListener) Accept() (net.Conn, error) {
@@ -106,9 +106,28 @@ func NewUAPIListener(name string) (net.Listener, error) {
// watch for deletion of socket
uapi.inotifyFd, err = unix.InotifyInit()
if err != nil {
return nil, err
}
_, err = unix.InotifyAddWatch(
uapi.inotifyFd,
socketPath,
unix.IN_ATTRIB|
unix.IN_DELETE|
unix.IN_DELETE_SELF,
)
if err != nil {
return nil, err
}
go func(l *UAPIListener) {
for ; ; time.Sleep(time.Second) {
if _, err := os.Stat(socketPath); os.IsNotExist(err) {
var buff [4096]byte
for {
unix.Read(uapi.inotifyFd, buff[:])
if _, err := os.Lstat(socketPath); os.IsNotExist(err) {
l.connErr <- err
return
}