prrt.pyx 2.22 KB
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t
2 3
cimport cprrt

4
cdef extern from "proto/applicationConstraints.c":
5 6
    pass

7
cdef extern from "proto/stores/dataPacketStore.c":
8 9
    pass

10
cdef extern from "proto/stores/forwardPacketTable.c":
11
    pass
12

13
cdef extern from "proto/stores/lossGatherer.c":
14 15
    pass

16
cdef extern from "proto/stores/packetTimeoutTable.c":
17 18
    pass

19
cdef extern from "proto/stores/repairBlockStore.c":
20 21
    pass

22
cdef extern from "proto/processes/feedbackReceiver.c":
23
    pass
24

25
cdef extern from "proto/processes/cleaner.c":
26 27
    pass

28
cdef extern from "proto/processes/dataReceiver.c":
29
    pass
30

31
cdef extern from "proto/processes/dataTransmitter.c":
32
    pass
33

34
cdef extern from "proto/block.c":
35
    pass
36

37
cdef extern from "proto/clock.c":
38
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
39

40
cdef extern from "proto/channelStateInformation.c":
41
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
42

43
cdef extern from "proto/vdmcode/block_code.c":
44
    pass
45

46
cdef extern from "proto/codingParams.c":
47
    pass
48

49
cdef extern from "proto/receiver.c":
50
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
51

52
cdef extern from "proto/packet.c":
53
    pass
54

55
cdef extern from "proto/socket.c":
56
    pass
57 58

cdef extern from "util/bptree.c":
59
    pass
60

61 62
cdef extern from "util/bitmap.c":
    pass
63

64 65
cdef extern from "util/list.c":
    pass
66 67 68

cdef class PrrtSocket:
    cdef cprrt.PrrtSocket* _c_socket
Andreas Schmidt's avatar
Andreas Schmidt committed
69
    cdef bint isSender
70

Andreas Schmidt's avatar
Andreas Schmidt committed
71
    def __cinit__(self, port, isSender):
Andreas Schmidt's avatar
Andreas Schmidt committed
72 73
        self._c_socket = cprrt.PrrtSocket_create(isSender)
        cprrt.PrrtSocket_bind(self._c_socket, "0.0.0.0", port)
Andreas Schmidt's avatar
Andreas Schmidt committed
74
        self.isSender = isSender
75

76 77
    @property
    def target_delay(self):
78
        return cprrt.PrrtSocket_get_sock_opt(self._c_socket, "targetdelay")
79 80

    @target_delay.setter
Andreas Schmidt's avatar
Andreas Schmidt committed
81
    def target_delay(self, value):
82 83
        cprrt.PrrtSocket_set_sock_opt(self._c_socket, "targetdelay", value)

84
    def recv(self):
Andreas Schmidt's avatar
Andreas Schmidt committed
85 86 87 88
        cdef char buffer[65536]
        cdef int32_t len
        with nogil:
            len = cprrt.PrrtSocket_recv(self._c_socket, <void*> buffer)
89
        return buffer[:len]
90 91

    def connect(self, host, port):
Andreas Schmidt's avatar
Andreas Schmidt committed
92 93 94 95
        cdef bytes encodedHost = host.encode("utf-8")
        cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port)

    def send(self, data):
96
        cprrt.PrrtSocket_send(self._c_socket, data, len(data))
Andreas Schmidt's avatar
Andreas Schmidt committed
97 98

    def close(self):
Andreas Schmidt's avatar
Andreas Schmidt committed
99
        cprrt.PrrtSocket_close(self._c_socket)