Example #1
0
 def push(self, value: self.ValueType, flags: int = 0):
     """
     Push an element onto the map.
     """
     try:
         value = self.ValueType(value)
     except TypeError:
         pass
     ret = Lib.bpf_map_update_elem(self._map_fd, None, ct.byref(value),
                                   flags)
     if ret < 0:
         raise KeyError(f'Unable to push value: {cerr(ret)}')
Example #2
0
 def update(self, key: self.KeyType, value: self.ValueType, flags: int):
     """
     Update a map value, operating according to specified flags.
     This provides more control than the traditional map[key] = value method.
     """
     try:
         key = self.KeyType(key)
     except TypeError:
         pass
     try:
         value = self.ValueType(value)
     except TypeError:
         pass
     ret = Lib.bpf_map_update_elem(self._map_fd, ct.byref(key),
                                   ct.byref(value), flags)
     if ret < 0:
         raise KeyError(f'Unable to update item: {cerr(ret)}')