xref: /libevent-2.1.12/make_epoll_table.py (revision b1b69ac7)
14b5f32a5SRoss Lagerwall#!/usr/bin/python2
28c83eb69SNick Mathewson
3*b1b69ac7SDiego Giagiodef get(old,wc,rc,cc):
4*b1b69ac7SDiego Giagio    if ('xxx' in (rc, wc, cc)):
5*b1b69ac7SDiego Giagio        return "0",255
68c83eb69SNick Mathewson
7*b1b69ac7SDiego Giagio    if ('add' in (rc, wc, cc)):
88c83eb69SNick Mathewson        events = []
98c83eb69SNick Mathewson        if rc == 'add' or (rc != 'del' and 'r' in old):
108c83eb69SNick Mathewson            events.append("EPOLLIN")
118c83eb69SNick Mathewson        if wc == 'add' or (wc != 'del' and 'w' in old):
128c83eb69SNick Mathewson            events.append("EPOLLOUT")
13*b1b69ac7SDiego Giagio        if cc == 'add' or (cc != 'del' and 'c' in old):
14*b1b69ac7SDiego Giagio            events.append("EPOLLRDHUP")
158c83eb69SNick Mathewson
168c83eb69SNick Mathewson        if old == "0":
178c83eb69SNick Mathewson            op = "EPOLL_CTL_ADD"
188c83eb69SNick Mathewson        else:
198c83eb69SNick Mathewson            op = "EPOLL_CTL_MOD"
208c83eb69SNick Mathewson        return "|".join(events), op
218c83eb69SNick Mathewson
22*b1b69ac7SDiego Giagio    if ('del' in (rc, wc, cc)):
23*b1b69ac7SDiego Giagio        delevents = []
24*b1b69ac7SDiego Giagio        modevents = []
258c83eb69SNick Mathewson        op = "EPOLL_CTL_DEL"
26*b1b69ac7SDiego Giagio
278c83eb69SNick Mathewson        if 'r' in old:
28*b1b69ac7SDiego Giagio            modevents.append("EPOLLIN")
29*b1b69ac7SDiego Giagio        if 'w' in old:
30*b1b69ac7SDiego Giagio            modevents.append("EPOLLOUT")
31*b1b69ac7SDiego Giagio        if 'c' in old:
32*b1b69ac7SDiego Giagio            modevents.append("EPOLLRDHUP")
33*b1b69ac7SDiego Giagio
34*b1b69ac7SDiego Giagio        for item, event in [(rc,"EPOLLIN"),
35*b1b69ac7SDiego Giagio                            (wc,"EPOLLOUT"),
36*b1b69ac7SDiego Giagio                            (cc,"EPOLLRDHUP")]:
37*b1b69ac7SDiego Giagio            if item == 'del':
38*b1b69ac7SDiego Giagio                delevents.append(event)
39*b1b69ac7SDiego Giagio                if event in modevents:
40*b1b69ac7SDiego Giagio                    modevents.remove(event)
41*b1b69ac7SDiego Giagio
42*b1b69ac7SDiego Giagio        if modevents:
43*b1b69ac7SDiego Giagio            return "|".join(modevents), "EPOLL_CTL_MOD"
448c83eb69SNick Mathewson        else:
45*b1b69ac7SDiego Giagio            return "|".join(delevents), "EPOLL_CTL_DEL"
468c83eb69SNick Mathewson
478c83eb69SNick Mathewson    return 0, 0
488c83eb69SNick Mathewson
498c83eb69SNick Mathewson
50*b1b69ac7SDiego Giagiodef fmt(op, ev, old, wc, rc, cc):
518c83eb69SNick Mathewson    entry = "{ %s, %s },"%(op, ev)
52*b1b69ac7SDiego Giagio    print "\t/* old=%3s, write:%3s, read:%3s, close:%3s */\n\t%s" % (
53*b1b69ac7SDiego Giagio        old, wc, rc, cc, entry)
54*b1b69ac7SDiego Giagio    return len(entry)
558c83eb69SNick Mathewson
56*b1b69ac7SDiego Giagiofor old in ('0','r','w','rw','c','cr','cw','crw'):
578c83eb69SNick Mathewson    for wc in ('0', 'add', 'del', 'xxx'):
588c83eb69SNick Mathewson        for rc in ('0', 'add', 'del', 'xxx'):
59*b1b69ac7SDiego Giagio            for cc in ('0', 'add', 'del', 'xxx'):
608c83eb69SNick Mathewson
61*b1b69ac7SDiego Giagio                op,ev = get(old,wc,rc,cc)
628c83eb69SNick Mathewson
63*b1b69ac7SDiego Giagio                fmt(op, ev, old, wc, rc, cc)
64