From 4dca07c803308611275f78b490ac0352c1052fe2 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Wed, 10 Jul 2019 07:14:20 +0200 Subject: Fix socketclient for VPP 19.08 - in VPP 19.08 the socket type has changed to STREAM and data has to be writtento VPP with single flush, otherwise msg might get mixed with next header and cause VPP to stop responding - this also fixes WaitReady for socketclient and vppapiclient Change-Id: I022724c0c09c9b92d4c695d1cf2be15994fff717 Signed-off-by: Ondrej Fabry --- adapter/vppapiclient/vppapiclient.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'adapter/vppapiclient') diff --git a/adapter/vppapiclient/vppapiclient.go b/adapter/vppapiclient/vppapiclient.go index d8465d7..244be43 100644 --- a/adapter/vppapiclient/vppapiclient.go +++ b/adapter/vppapiclient/vppapiclient.go @@ -40,7 +40,7 @@ import ( var ( // MaxWaitReady defines maximum duration before waiting for shared memory // segment times out - MaxWaitReady = time.Second * 15 + MaxWaitReady = time.Second * 10 ) const ( @@ -148,12 +148,11 @@ func (a *vppClient) WaitReady() error { path = filepath.Join(shmDir, a.shmPrefix+"-"+vppShmFile) } - // check if file at the path already exists + // check if file already exists if _, err := os.Stat(path); err == nil { - // file exists, we are ready - return nil + return nil // file exists, we are ready } else if !os.IsNotExist(err) { - return err + return err // some other error occurred } // file does not exist, start watching folder @@ -168,18 +167,19 @@ func (a *vppClient) WaitReady() error { return err } + timeout := time.NewTimer(MaxWaitReady) for { select { - case <-time.After(MaxWaitReady): - return fmt.Errorf("waiting for shared memory segment timed out (%s)", MaxWaitReady) + case <-timeout.C: + return fmt.Errorf("timeout waiting (%s) for shm file: %s", MaxWaitReady, path) + case e := <-watcher.Errors: return e + case ev := <-watcher.Events: - if ev.Name == path { - if (ev.Op & fsnotify.Create) == fsnotify.Create { - // file was created, we are ready - return nil - } + if ev.Name == path && (ev.Op&fsnotify.Create) == fsnotify.Create { + // file created, we are ready + return nil } } } -- cgit 1.2.3-korg