-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfstack.py
More file actions
50 lines (36 loc) · 1.15 KB
/
fstack.py
File metadata and controls
50 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
"""
from __future__ import print_function, division, absolute_import
import sys
from ._compat import integer_types
from ._fstack import ffi, lib
@ffi.def_extern()
def loop_func(c_arg):
fn, args, kwargs = ffi.from_handle(c_arg)
res = fn(*args, **kwargs)
return res if isinstance(res, integer_types) else 0
class Fstack(object):
def __init__(self, config_file, proc_type, proc_id):
argv = [
sys.argv[0],
"--conf=%s" % config_file,
"--proc-type=%s" % proc_type,
"--proc-id=%s" % proc_id,
]
self.user_data = None
argc = len(argv)
argv_keepalive = [ffi.new("char[]", arg) for arg in argv]
c_argv = ffi.new("char *[]", argv_keepalive)
lib.ff_init(argc, c_argv)
def run(self, fn, *args, **kwargs):
assert self.user_data is None
self.user_data = ffi.new_handle((fn, args, kwargs))
return lib.ff_run(lib.loop_func, self.user_data)
def sysctl(name, namelen, oldp, oldlenp, newp, newlen):
pass
def route_ctl(req, flag, dst, gw, netmask):
pass
def rtioctl():
pass