diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-07-10 07:14:20 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-07-10 07:14:20 +0200 |
commit | 4dca07c803308611275f78b490ac0352c1052fe2 (patch) | |
tree | efb52ff663ef3b16f4bd6957379a572c5fd49de0 /adapter/vppapiclient | |
parent | b1006dced4cc0c23d9dc754e97d89500aeb55170 (diff) |
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 <ofabry@cisco.com>
Diffstat (limited to 'adapter/vppapiclient')
-rw-r--r-- | adapter/vppapiclient/vppapiclient.go | 24 |
1 files changed, 12 insertions, 12 deletions
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 } } } |