Commit 70a5a412 authored by Andreas Schmidt's avatar Andreas Schmidt

Small changes.

parent e83e7afe
......@@ -21,7 +21,6 @@ class senderThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.sock = prrt.PrrtSocket(6000, True)
print("CREATED sock")
def run(self):
print("Connecting")
......@@ -32,7 +31,9 @@ class senderThread(threading.Thread):
if __name__ == "__main__":
recvThread = receiverThread()
recvThread.daemon = True
sendThread = senderThread()
sendThread.daemon = True
recvThread.start()
sendThread.run()
sendThread.start()
from libc.stdint cimport uint32_t, uint16_t, uint8_t
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t
cdef extern from "pthread.h" nogil:
ctypedef struct pthread_t:
......@@ -10,19 +10,19 @@ cdef extern from "pthread.h" nogil:
ctypedef struct pthread_cond_t:
pass
cdef extern from "prrt/stores/forward_packet_table.h":
cdef extern from "prrt/stores/forward_packet_table.h" nogil:
cdef struct prrtForwardPacketTable:
pass
ctypedef prrtForwardPacketTable PrrtForwardPacketTable
cdef extern from "prrt/vdmcode/block_code.h":
cdef extern from "prrt/vdmcode/block_code.h" nogil:
cdef struct prrtCoder:
pass
ctypedef prrtCoder PrrtCoder
cdef extern from "prrt/coding_params.h":
cdef extern from "prrt/coding_params.h" nogil:
cdef struct prrtCodingParams:
uint8_t k;
uint8_t r;
......@@ -31,7 +31,7 @@ cdef extern from "prrt/coding_params.h":
ctypedef prrtCodingParams PrrtCodingParams
cdef extern from "util/list.h":
cdef extern from "util/list.h" nogil:
cdef struct list:
pass
......@@ -50,7 +50,7 @@ cdef extern from "util/list.h":
void *List_remove(List *list, const ListNode *node)
cdef extern from "prrt/block.h":
cdef extern from "prrt/block.h" nogil:
cdef struct prrtBlock:
uint32_t data_count
uint32_t redundancy_count
......@@ -63,7 +63,7 @@ cdef extern from "prrt/block.h":
ctypedef prrtBlock PrrtBlock
cdef extern from "prrt/packet.h":
cdef extern from "prrt/packet.h" nogil:
cdef struct prrtPacket:
uint8_t type_priority;
uint8_t index;
......@@ -73,7 +73,7 @@ cdef extern from "prrt/packet.h":
ctypedef prrtPacket PrrtPacket
cdef extern from "prrt/socket.h":
cdef extern from "prrt/socket.h" nogil:
ctypedef struct PrrtReceiver:
const char* host_name
uint16_t port
......@@ -109,14 +109,14 @@ cdef extern from "prrt/socket.h":
ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t is_sender)
int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port)
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len)
void PrrtSocket_recv(const PrrtSocket *sock_ptr, void **buf_ptr, ssize_t *length)
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length)
cdef PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t is_sender) nogil
int PrrtSocket_close(const PrrtSocket *sock_ptr) nogil
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) nogil
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len) nogil
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) nogil
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length) nogil
cdef extern from "util/bptree.h":
cdef extern from "util/bptree.h" nogil:
ctypedef struct BPTreeNode:
pass
......
......@@ -53,16 +53,20 @@ cdef extern from "util/list.c":
cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket
cdef bint isSender
def __cinit__(self, port, sender):
self._c_socket = cprrt.PrrtSocket_create(port, sender)
def __cinit__(self, port, isSender):
self._c_socket = cprrt.PrrtSocket_create(port, isSender)
self.isSender = isSender
def recv(self):
cdef char* buf = NULL
cdef Py_ssize_t length = 0
cprrt.PrrtSocket_recv(self._c_socket, <void**> &buf, &length)
cdef bytes s = buf
cdef char buf[65536]
cdef bytes s
len = cprrt.PrrtSocket_recv(self._c_socket, <void*> buf)
s = buf
s[len] = '\0'
return s
def connect(self, host, port):
print "Connecting to", host, "on port", str(port)
cprrt.PrrtSocket_connect(self._c_socket, host, port)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment