Loading examples/sender.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ host = sys.argv[1] port = int(sys.argv[2]) localport = int(sys.argv[3]) s = prrt.PrrtSocket(("127.0.1.1", localport)) s = prrt.PrrtSocket(("127.0.1.1", localport), mtu=150) s.connect((host, port)) for i in range(10): Loading prrt/cprrt.pxd +1 −1 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ cdef extern from "proto/socket.h": ctypedef prrtSocket PrrtSocket cdef PrrtSocket* PrrtSocket_create(const uint32_t target_delay) cdef PrrtSocket* PrrtSocket_create(const uint32_t mtu, const uint32_t target_delay) bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port) int PrrtSocket_close(const PrrtSocket *sock_ptr) int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port) Loading prrt/proto/socket.c +9 −3 Original line number Diff line number Diff line Loading @@ -50,12 +50,12 @@ struct timespec abstime_from_now(prrtTimedelta_t wait_time) { return deadline; } PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us) { PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us) { assert(sizeof(float) == 4); PrrtSocket *s = (PrrtSocket *) calloc(1, sizeof(PrrtSocket)); check_mem(s); s->mtu = mtu; s->isHardwareTimestamping = false; s->interfaceName = NULL; Loading Loading @@ -219,6 +219,10 @@ int PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port) { } int PrrtSocket_send(PrrtSocket *s, const uint8_t *data, const size_t data_len) { if (data_len > s->mtu) { PERROR("Data to be sent (%d bytes) is too long, as MTU is %d.\n", data_len, s->mtu); return -1; } XlapTimestampPlaceholder tsph; XlapTimestampPlaceholderInitialize(&tsph); XlapTimeStampClock(&tsph, ts_any_packet, 0, PrrtSendStart); Loading Loading @@ -425,8 +429,10 @@ int PrrtSocket_close(PrrtSocket *s) { uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name) { if (strcmp(name, "targetdelay") == 0) { return PrrtApplicationConstraints_get_target_delay(s->applicationConstraints); } else if (strcmp(name, "mtu") == 0) { return s->mtu; } else { PERROR("Unknwon property %s", name); PERROR("Unknown property %s\n", name); return 0; } } Loading prrt/proto/socket.h +2 −1 Original line number Diff line number Diff line Loading @@ -78,10 +78,11 @@ typedef struct prrtSocket { char *interfaceName; atomic_bool isThreadPinning; prrtByteCount_t mtu; } PrrtSocket; PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us); PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us); bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interface_name); Loading prrt/prrt.pyx +11 −3 Original line number Diff line number Diff line Loading @@ -92,6 +92,9 @@ cdef extern from "util/mpsc_queue.c": cdef sockaddr_to_addr_and_port(sockaddr_in addr): return (cprrt.PrrtSocket_inet_ntoa(&addr.sin_addr).decode("utf8"), cprrt.PrrtSocket_ntohs(addr.sin_port)) class PayloadTooBigException(Exception): pass class PrrtCodingConfiguration: def __init__(self, n, k, n_cycle=None): if n < k: Loading @@ -118,10 +121,10 @@ class PrrtCodingConfiguration: cdef class PrrtSocket: cdef cprrt.PrrtSocket* _c_socket def __cinit__(self, address, target_delay = 1, thread_pinning = False): def __cinit__(self, address, mtu = 1500, target_delay = 1, thread_pinning = False): host, port = address target_delay_us = target_delay * 1000**2 self._c_socket = cprrt.PrrtSocket_create(target_delay_us) self._c_socket = cprrt.PrrtSocket_create(mtu, target_delay_us) if thread_pinning: cprrt.PrrtSocket_enable_thread_pinning(self._c_socket) cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port) Loading Loading @@ -182,7 +185,12 @@ cdef class PrrtSocket: cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port) def send(self, data): cprrt.PrrtSocket_send(self._c_socket, data, len(data)) mtu = cprrt.PrrtSocket_get_sock_opt(self._c_socket, "mtu") data_len = len(data) if len(data) < mtu: cprrt.PrrtSocket_send(self._c_socket, data, data_len) else: raise PayloadTooBigException("Sending packet of {} bytes on a socket with MTU of {} bytes failed.".format(data_len, mtu)) # Receiving Loading Loading
examples/sender.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ host = sys.argv[1] port = int(sys.argv[2]) localport = int(sys.argv[3]) s = prrt.PrrtSocket(("127.0.1.1", localport)) s = prrt.PrrtSocket(("127.0.1.1", localport), mtu=150) s.connect((host, port)) for i in range(10): Loading
prrt/cprrt.pxd +1 −1 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ cdef extern from "proto/socket.h": ctypedef prrtSocket PrrtSocket cdef PrrtSocket* PrrtSocket_create(const uint32_t target_delay) cdef PrrtSocket* PrrtSocket_create(const uint32_t mtu, const uint32_t target_delay) bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port) int PrrtSocket_close(const PrrtSocket *sock_ptr) int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port) Loading
prrt/proto/socket.c +9 −3 Original line number Diff line number Diff line Loading @@ -50,12 +50,12 @@ struct timespec abstime_from_now(prrtTimedelta_t wait_time) { return deadline; } PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us) { PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us) { assert(sizeof(float) == 4); PrrtSocket *s = (PrrtSocket *) calloc(1, sizeof(PrrtSocket)); check_mem(s); s->mtu = mtu; s->isHardwareTimestamping = false; s->interfaceName = NULL; Loading Loading @@ -219,6 +219,10 @@ int PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port) { } int PrrtSocket_send(PrrtSocket *s, const uint8_t *data, const size_t data_len) { if (data_len > s->mtu) { PERROR("Data to be sent (%d bytes) is too long, as MTU is %d.\n", data_len, s->mtu); return -1; } XlapTimestampPlaceholder tsph; XlapTimestampPlaceholderInitialize(&tsph); XlapTimeStampClock(&tsph, ts_any_packet, 0, PrrtSendStart); Loading Loading @@ -425,8 +429,10 @@ int PrrtSocket_close(PrrtSocket *s) { uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name) { if (strcmp(name, "targetdelay") == 0) { return PrrtApplicationConstraints_get_target_delay(s->applicationConstraints); } else if (strcmp(name, "mtu") == 0) { return s->mtu; } else { PERROR("Unknwon property %s", name); PERROR("Unknown property %s\n", name); return 0; } } Loading
prrt/proto/socket.h +2 −1 Original line number Diff line number Diff line Loading @@ -78,10 +78,11 @@ typedef struct prrtSocket { char *interfaceName; atomic_bool isThreadPinning; prrtByteCount_t mtu; } PrrtSocket; PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us); PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us); bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interface_name); Loading
prrt/prrt.pyx +11 −3 Original line number Diff line number Diff line Loading @@ -92,6 +92,9 @@ cdef extern from "util/mpsc_queue.c": cdef sockaddr_to_addr_and_port(sockaddr_in addr): return (cprrt.PrrtSocket_inet_ntoa(&addr.sin_addr).decode("utf8"), cprrt.PrrtSocket_ntohs(addr.sin_port)) class PayloadTooBigException(Exception): pass class PrrtCodingConfiguration: def __init__(self, n, k, n_cycle=None): if n < k: Loading @@ -118,10 +121,10 @@ class PrrtCodingConfiguration: cdef class PrrtSocket: cdef cprrt.PrrtSocket* _c_socket def __cinit__(self, address, target_delay = 1, thread_pinning = False): def __cinit__(self, address, mtu = 1500, target_delay = 1, thread_pinning = False): host, port = address target_delay_us = target_delay * 1000**2 self._c_socket = cprrt.PrrtSocket_create(target_delay_us) self._c_socket = cprrt.PrrtSocket_create(mtu, target_delay_us) if thread_pinning: cprrt.PrrtSocket_enable_thread_pinning(self._c_socket) cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port) Loading Loading @@ -182,7 +185,12 @@ cdef class PrrtSocket: cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port) def send(self, data): cprrt.PrrtSocket_send(self._c_socket, data, len(data)) mtu = cprrt.PrrtSocket_get_sock_opt(self._c_socket, "mtu") data_len = len(data) if len(data) < mtu: cprrt.PrrtSocket_send(self._c_socket, data, data_len) else: raise PayloadTooBigException("Sending packet of {} bytes on a socket with MTU of {} bytes failed.".format(data_len, mtu)) # Receiving Loading