prrt.pyx 1.72 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
5
6
cdef extern from "prrt/applicationConstraints.c":
    pass

Andreas Schmidt's avatar
Andreas Schmidt committed
7
cdef extern from "prrt/stores/forwardPacketTable.c":
8
    pass
9

Andreas Schmidt's avatar
Andreas Schmidt committed
10
cdef extern from "prrt/processes/feedbackReceiver.c":
11
    pass
12

Andreas Schmidt's avatar
Andreas Schmidt committed
13
cdef extern from "prrt/processes/dataReceiver.c":
14
    pass
15

Andreas Schmidt's avatar
Andreas Schmidt committed
16
cdef extern from "prrt/processes/dataTransmitter.c":
17
    pass
18
19

cdef extern from "prrt/block.c":
20
    pass
21

Andreas Schmidt's avatar
Andreas Schmidt committed
22
cdef extern from "prrt/clock.c":
23
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
24
25

cdef extern from "prrt/channelStateInformation.c":
26
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
27

28
cdef extern from "prrt/vdmcode/block_code.c":
29
    pass
30

Andreas Schmidt's avatar
Andreas Schmidt committed
31
cdef extern from "prrt/codingParams.c":
32
    pass
33

Andreas Schmidt's avatar
Andreas Schmidt committed
34
cdef extern from "prrt/receiver.c":
35
    pass
Andreas Schmidt's avatar
Andreas Schmidt committed
36

37
cdef extern from "prrt/packet.c":
38
    pass
39
40

cdef extern from "prrt/socket.c":
41
    pass
42
43

cdef extern from "util/bptree.c":
44
    pass
45

46
47
cdef extern from "util/bitmap.c":
    pass
48

49
50
cdef extern from "util/list.c":
    pass
51
52
53

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

Andreas Schmidt's avatar
Andreas Schmidt committed
56
    def __cinit__(self, port, isSender):
Andreas Schmidt's avatar
Andreas Schmidt committed
57
58
        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
59
        self.isSender = isSender
60
61

    def recv(self):
Andreas Schmidt's avatar
Andreas Schmidt committed
62
63
64
65
66
        cdef char buffer[65536]
        cdef int32_t len
        with nogil:
            len = cprrt.PrrtSocket_recv(self._c_socket, <void*> buffer)
        return len, buffer
67
68

    def connect(self, host, port):
Andreas Schmidt's avatar
Andreas Schmidt committed
69
70
71
72
73
74
75
76
        cdef bytes encodedHost = host.encode("utf-8")
        cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port)

    def send(self, data):
        cdef bytes encodedData = data.encode("utf-8")
        cprrt.PrrtSocket_send(self._c_socket, encodedData, len(data))

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