https://jira.fd.io/browse/GOVPP-21 02/33002/2
authorKusakabe Si <linux@kskb.eu.org>
Mon, 5 Jul 2021 09:03:20 +0000 (17:03 +0800)
committerOndrej Fabry <ofabry@cisco.com>
Tue, 27 Jul 2021 13:02:29 +0000 (13:02 +0000)
Signed-off-by: Kusakabe Si <linux@kskb.eu.org>
Change-Id: Ib1761e3b93dae70680646ce7fdd78a1168fd0b9f

extras/libmemif/adapter.go
extras/libmemif/examples/icmp-responder/icmp-responder.go

index eb7e209..ac8a827 100644 (file)
@@ -380,6 +380,7 @@ type Memif struct {
 
        // Interrupt
        intCh      chan uint8      // memif-global interrupt channel (value = queue ID)
+       intErrCh   chan error      // triggered when interrupt error occurs
        queueIntCh []chan struct{} // per RX queue interrupt channel
 
        // Rx/Tx queues
@@ -585,6 +586,7 @@ func CreateInterface(config *MemifConfig, callbacks *MemifCallbacks) (memif *Mem
 
        // Initialize memif-global interrupt channel.
        memif.intCh = make(chan uint8, 1<<6)
+       memif.intErrCh = make(chan error, 1<<6)
 
        // Initialize event file descriptor for stopping Rx/Tx queue polling.
        memif.stopQPollFd = int(C.eventfd(0, C.EFD_NONBLOCK))
@@ -667,6 +669,12 @@ func (memif *Memif) GetInterruptChan() (ch <-chan uint8 /* queue ID */) {
        return memif.intCh
 }
 
+// GetInterruptErrorChan returns an Error channel
+// which fires if there are errors occurred while read data.
+func (memif *Memif) GetInterruptErrorChan() (ch <-chan error /* The error */) {
+       return memif.intErrCh
+}
+
 // GetQueueInterruptChan returns an empty-data channel which fires every time
 // there are data to read on a given queue.
 // It is only valid to call this function if memif is in the connected state.
@@ -1022,6 +1030,7 @@ func (memif *Memif) Close() error {
        if err != nil {
                // Close memif-global interrupt channel.
                close(memif.intCh)
+               close(memif.intErrCh)
                // Close file descriptor stopQPollFd.
                C.close(C.int(memif.stopQPollFd))
        }
@@ -1163,6 +1172,7 @@ func pollRxQueue(memif *Memif, queueID uint8) {
                                continue
                        }
                        log.WithField("err", err).Error("epoll_wait() failed")
+                       memif.intErrCh <- err
                        return
                }
 
index 79bb9d0..a7726bf 100644 (file)
@@ -399,5 +399,13 @@ func main() {
        // Wait until an interrupt signal is received.
        sigChan := make(chan os.Signal, 1)
        signal.Notify(sigChan, os.Interrupt)
-       <-sigChan
+       var intErrch = memif.GetInterruptErrorChan()
+       select {
+       case err = <-intErrch:
+               fmt.Printf("Exit due to interface error: %v\n", err)
+               return
+       case <-sigChan:
+               fmt.Printf("Exit by os.Interrupt")
+               return
+       }
 }