Commit a0cd6a2e authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Fix error codes and bool handling.

parent c5936fed
Pipeline #43 passed with stage
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
#define MAX_PAYLOAD_LENGTH 65528 // maximum UDP packet length (2^16 - 8) #define MAX_PAYLOAD_LENGTH 65528 // maximum UDP packet length (2^16 - 8)
#define TRUE 1
#define FALSE 0
#define GF_BITS 8 #define GF_BITS 8
#define K_START 4 #define K_START 4
...@@ -22,10 +19,6 @@ ...@@ -22,10 +19,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef WINDOWS
#define bool char
#define false 0
#define true 1
#endif
#endif //PRRT_DEFINES_H #endif //PRRT_DEFINES_H
...@@ -73,55 +73,54 @@ int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t b ...@@ -73,55 +73,54 @@ int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t b
return 0; return 0;
} }
int PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket) bool PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket)
{ {
int found = FALSE; bool found = false;
LIST_FOREACH(prrtBlock->dataPackets, first, next, cur) { LIST_FOREACH(prrtBlock->dataPackets, first, next, cur) {
PrrtPacket *pkt = cur->value; PrrtPacket *pkt = cur->value;
if(pkt->seqno == prrtPacket->seqno) { if(pkt->seqno == prrtPacket->seqno) {
found = TRUE; found = true;
} }
} }
if(found == FALSE) { if(found == false) {
List_push(prrtBlock->dataPackets, prrtPacket); List_push(prrtBlock->dataPackets, prrtPacket);
prrtBlock->largestDataLength = (uint32_t) MAX(prrtBlock->largestDataLength, prrtBlock->largestDataLength = (uint32_t) MAX(prrtBlock->largestDataLength,
prrtPacket->payload_len - PRRT_PACKET_DATA_HEADER_SIZE); prrtPacket->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
return EXIT_SUCCESS; return true;
} else { } else {
return EXIT_FAILURE; return false;
} }
} }
int PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, const PrrtPacket *ptr) bool PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, const PrrtPacket *ptr)
{ {
int found = FALSE; bool found = false;
LIST_FOREACH(block_ptr->redundancyPackets, first, next, cur) { LIST_FOREACH(block_ptr->redundancyPackets, first, next, cur) {
PrrtPacket *pkt = cur->value; PrrtPacket *pkt = cur->value;
if(pkt->seqno == ptr->seqno) { if(pkt->seqno == ptr->seqno) {
found = TRUE; found = true;
} }
} }
if(found == FALSE) { if(found == false) {
List_push(block_ptr->redundancyPackets, ptr); List_push(block_ptr->redundancyPackets, ptr);
block_ptr->largestDataLength = (uint32_t) MAX(block_ptr->largestDataLength, block_ptr->largestDataLength = (uint32_t) MAX(block_ptr->largestDataLength,
ptr->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE); ptr->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
return EXIT_SUCCESS; return true;
} else { } else {
return EXIT_FAILURE; return false;
} }
} }
int PrrtBlock_encode_ready(const PrrtBlock *block_ptr) bool PrrtBlock_encode_ready(const PrrtBlock *block_ptr)
{ {
return (List_count(block_ptr->dataPackets) == block_ptr->codingParams.k) ? TRUE : FALSE; return (List_count(block_ptr->dataPackets) == block_ptr->codingParams.k);
} }
int PrrtBlock_decode_ready(const PrrtBlock *block_ptr) bool PrrtBlock_decode_ready(const PrrtBlock *block_ptr)
{ {
return (List_count(block_ptr->dataPackets) + List_count(block_ptr->redundancyPackets) == block_ptr->codingParams.k) return (List_count(block_ptr->dataPackets) + List_count(block_ptr->redundancyPackets) == block_ptr->codingParams.k);
? TRUE : FALSE;
} }
PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr) PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr)
...@@ -166,7 +165,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) ...@@ -166,7 +165,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno)
PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr); PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr);
} }
block_ptr->isCoded = TRUE; block_ptr->isCoded = true;
PrrtCoder_destroy(coder); PrrtCoder_destroy(coder);
...@@ -212,8 +211,8 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) ...@@ -212,8 +211,8 @@ void PrrtBlock_decode(PrrtBlock *block_ptr)
for(j = 0; j < k; j++) { for(j = 0; j < k; j++) {
if(idx_p[j] >= k) { if(idx_p[j] >= k) {
PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (uint16_t) (baseSequenceNumber + j)); PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (uint16_t) (baseSequenceNumber + j));
int insertRes = PrrtBlock_insert_data_packet(block_ptr, packet); bool insertRes = PrrtBlock_insert_data_packet(block_ptr, packet);
if(insertRes == EXIT_FAILURE) { if(insertRes == false) {
debug("Tried to insert unnecessary packet."); debug("Tried to insert unnecessary packet.");
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
} }
......
...@@ -11,7 +11,7 @@ typedef struct { ...@@ -11,7 +11,7 @@ typedef struct {
uint16_t baseSequenceNumber; uint16_t baseSequenceNumber;
List*dataPackets; List*dataPackets;
List*redundancyPackets; List*redundancyPackets;
uint8_t isCoded; bool isCoded;
} PrrtBlock; } PrrtBlock;
...@@ -25,11 +25,11 @@ int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t b ...@@ -25,11 +25,11 @@ int PrrtBlock_create(PrrtBlock *mblock, const PrrtCodingParams *cpar, uint16_t b
*/ */
void PrrtBlock_destroy(PrrtBlock *mblock); void PrrtBlock_destroy(PrrtBlock *mblock);
int PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket); bool PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket);
int PrrtBlock_insert_redundancy_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket); bool PrrtBlock_insert_redundancy_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPacket);
int PrrtBlock_encode_ready(const PrrtBlock *block_ptr); bool PrrtBlock_encode_ready(const PrrtBlock *block_ptr);
int PrrtBlock_decode_ready(const PrrtBlock *block_ptr); bool PrrtBlock_decode_ready(const PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr); PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <src/util/dbg.h> #include <src/util/dbg.h>
#include <src/util/common.h> #include <src/util/common.h>
#include <stdbool.h>
#include "packet.h" #include "packet.h"
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet); void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
...@@ -123,7 +124,7 @@ PrrtPacket *create_header(uint8_t priority, uint16_t seqno, uint32_t size, uint8 ...@@ -123,7 +124,7 @@ PrrtPacket *create_header(uint8_t priority, uint16_t seqno, uint32_t size, uint8
PERROR("Could not create packet.%s", ""); PERROR("Could not create packet.%s", "");
} }
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
{ {
void *payload = packet_ptr->payload; void *payload = packet_ptr->payload;
...@@ -143,12 +144,12 @@ int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -143,12 +144,12 @@ int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_FEEDBACK_HEADER_SIZE); PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else { } else {
perror("NOT IMPLEMENTED"); perror("NOT IMPLEMENTED");
return -1; return false;
} }
return 0; return true;
error: error:
return -1; return false;
} }
void *encode_redundancy_header(void *buf_ptr, const void *payload) void *encode_redundancy_header(void *buf_ptr, const void *payload)
...@@ -260,7 +261,7 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) ...@@ -260,7 +261,7 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet)
return buf_ptr; return buf_ptr;
} }
int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket) bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket)
{ {
uint32_t payload_len = (uint32_t) (srcBufferSize - PRRT_PACKET_GENERAL_HEADER_SIZE); uint32_t payload_len = (uint32_t) (srcBufferSize - PRRT_PACKET_GENERAL_HEADER_SIZE);
targetPacket->type_priority = *(uint8_t *) srcBuffer; targetPacket->type_priority = *(uint8_t *) srcBuffer;
...@@ -290,10 +291,10 @@ int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targe ...@@ -290,10 +291,10 @@ int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targe
} else { } else {
printf("NOT IMPLEMENTED\n"); printf("NOT IMPLEMENTED\n");
} }
return 0; return true;
error: error:
return EXIT_FAILURE; return false;
} }
void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer) void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include <src/prrt/coding_params.h> #include <src/prrt/coding_params.h>
#include <stdbool.h>
#define PACKET_TYPE_DATA 0 #define PACKET_TYPE_DATA 0
#define PACKET_TYPE_REPETITION 1 #define PACKET_TYPE_REPETITION 1
...@@ -73,8 +74,8 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u ...@@ -73,8 +74,8 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer, uint32_t payloadLength, PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer, uint32_t payloadLength,
uint16_t sequenceNumber, uint8_t index, uint16_t baseSequenceNumber, PrrtCodingParams codingParams); uint16_t sequenceNumber, uint8_t index, uint16_t baseSequenceNumber, PrrtCodingParams codingParams);
int PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket); bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr); bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet); int PrrtPacket_destroy(PrrtPacket *packet);
#define PrrtPacket_copy_payload_to_buffer(dst, packet, header_size) memcpy(dst, packet->payload + header_size, packet->payload_len - header_size); #define PrrtPacket_copy_payload_to_buffer(dst, packet, header_size) memcpy(dst, packet->payload + header_size, packet->payload_len - header_size);
......
...@@ -15,12 +15,11 @@ void retrieve_data_blocks(PrrtSocket *sock_ptr, uint16_t base_seqno, uint8_t k, ...@@ -15,12 +15,11 @@ void retrieve_data_blocks(PrrtSocket *sock_ptr, uint16_t base_seqno, uint8_t k,
LIST_FOREACH(res, first, next, cur) { LIST_FOREACH(res, first, next, cur) {
PrrtPacket *packetPtr = cur->value; PrrtPacket *packetPtr = cur->value;
int insertRes = PrrtBlock_insert_data_packet((PrrtBlock *) block, packetPtr); check(PrrtBlock_insert_data_packet((PrrtBlock *) block, packetPtr), "Insert failed!")
check(insertRes == EXIT_SUCCESS, "Insert failed!")
sock_ptr->dataStore = BPTree_delete(sock_ptr->dataStore, packetPtr->seqno); sock_ptr->dataStore = BPTree_delete(sock_ptr->dataStore, packetPtr->seqno);
} }
error: error:
List_destroy(res); List_destroy(res);
} }
void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block, uint16_t base_seqno) void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block, uint16_t base_seqno)
...@@ -46,7 +45,7 @@ void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block, uint16_t base_seqno) ...@@ -46,7 +45,7 @@ void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block, uint16_t base_seqno)
} }
} }
int send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote) bool send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote)
{ {
uint16_t remote_port = ntohs(remote.sin_port); uint16_t remote_port = ntohs(remote.sin_port);
char *remote_host = inet_ntoa(remote.sin_addr); char *remote_host = inet_ntoa(remote.sin_addr);
...@@ -60,23 +59,21 @@ int send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote) ...@@ -60,23 +59,21 @@ int send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote)
hp = gethostbyname(remote_host); hp = gethostbyname(remote_host);
memcpy((void *) &targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length); memcpy((void *) &targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);
PrrtPacket *feedback_pkt_ptr = PrrtPacket_create_feedback_packet(0, 19, 4715, 7, 3, 50, 4, 6, 8, 9, 5, 1); PrrtPacket *feedback_pkt_ptr = PrrtPacket_create_feedback_packet(0, 19, 4715, 7, 3, 50, 4, 6, 8, 9, 5, 1);
uint8_t buf[MAX_PAYLOAD_LENGTH]; uint8_t buf[MAX_PAYLOAD_LENGTH];
memset(buf, 0, MAX_PAYLOAD_LENGTH); memset(buf, 0, MAX_PAYLOAD_LENGTH);
uint32_t length = PrrtPacket_size(feedback_pkt_ptr); uint32_t length = PrrtPacket_size(feedback_pkt_ptr);
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr) == EXIT_SUCCESS, check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr), "Buffer for encoding feedback is too small");
"Buffer for encoding feedback is too small");
check(sendto(sock_ptr->feedbackSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) == check(sendto(sock_ptr->feedbackSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) ==
length, "Sending feedback failed."); length, "Sending feedback failed.");
PrrtPacket_destroy(feedback_pkt_ptr); PrrtPacket_destroy(feedback_pkt_ptr);
return EXIT_SUCCESS; return true;
error: error:
return EXIT_FAILURE; return false;
} }
void *receive_data_loop(void *ptr) void *receive_data_loop(void *ptr)
...@@ -91,7 +88,7 @@ void *receive_data_loop(void *ptr) ...@@ -91,7 +88,7 @@ void *receive_data_loop(void *ptr)
while(1) { while(1) {
memset(buffer, 0, MAX_PAYLOAD_LENGTH); memset(buffer, 0, MAX_PAYLOAD_LENGTH);
n = recvfrom(sock_ptr->dataSocketFd, buffer, MAX_PAYLOAD_LENGTH, 0, (struct sockaddr *) &remote, &addrlen); n = recvfrom(sock_ptr->dataSocketFd, buffer, MAX_PAYLOAD_LENGTH, 0, (struct sockaddr *) &remote, &addrlen);
check(send_feedback(sock_ptr, remote) == EXIT_SUCCESS, "Sending feedback failed."); check(send_feedback(sock_ptr, remote), "Sending feedback failed.");
PrrtPacket *packet = (PrrtPacket *) calloc(1, sizeof(PrrtPacket)); PrrtPacket *packet = (PrrtPacket *) calloc(1, sizeof(PrrtPacket));
check_mem(packet); check_mem(packet);
...@@ -102,17 +99,16 @@ void *receive_data_loop(void *ptr) ...@@ -102,17 +99,16 @@ void *receive_data_loop(void *ptr)
// TODO: packet.timestamp + packet.timeout < now: break // TODO: packet.timestamp + packet.timeout < now: break
if(PrrtForwardPacketTable_test_set_is_number_relevant(sock_ptr->forwardPacketTable, packet->seqno) == if(PrrtForwardPacketTable_test_set_is_number_relevant(sock_ptr->forwardPacketTable, packet->seqno) ==
FALSE) { false) {
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
} else { } else {
uint16_t baseSequenceNumber = packet->seqno - packet->index; uint16_t baseSequenceNumber = packet->seqno - packet->index;
PrrtPacket* reference = PrrtPacket_copy(packet); PrrtPacket *reference = PrrtPacket_copy(packet);
PrrtBlock *block = BPTree_get(sock_ptr->blockStore, baseSequenceNumber); PrrtBlock *block = BPTree_get(sock_ptr->blockStore, baseSequenceNumber);
if(block != NULL) { if(block != NULL) {
int res = PrrtBlock_insert_data_packet(block, reference); check(PrrtBlock_insert_data_packet(block, reference), "Inserting failed");
check(res == EXIT_SUCCESS, "Inserting failed")
decode_block(sock_ptr, block, baseSequenceNumber); decode_block(sock_ptr, block, baseSequenceNumber);
} else { } else {
// Check for duplicate data packet. // Check for duplicate data packet.
...@@ -156,8 +152,7 @@ void *receive_data_loop(void *ptr) ...@@ -156,8 +152,7 @@ void *receive_data_loop(void *ptr)
retrieve_data_blocks(sock_ptr, redundancyPayload->base_seqno, block->codingParams.k, block); retrieve_data_blocks(sock_ptr, redundancyPayload->base_seqno, block->codingParams.k, block);
int res = PrrtBlock_insert_redundancy_packet(block, packet); if(PrrtBlock_insert_redundancy_packet(block, packet)) {
if(res == EXIT_SUCCESS) {
decode_block(sock_ptr, block, redundancyPayload->base_seqno); decode_block(sock_ptr, block, redundancyPayload->base_seqno);
} else { } else {
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
......
...@@ -10,13 +10,12 @@ ...@@ -10,13 +10,12 @@
#include "data_transmitter.h" #include "data_transmitter.h"
int send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
uint8_t buf[MAX_PAYLOAD_LENGTH]; uint8_t buf[MAX_PAYLOAD_LENGTH];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
uint32_t length = PrrtPacket_size(packet); uint32_t length = PrrtPacket_size(packet);
int encodeResult = PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet); check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet), "Buffer too small.");
check(encodeResult >= 0, "Buffer too small.");
// SENDING TO ALL RECEIVERS // SENDING TO ALL RECEIVERS
LIST_FOREACH(sock_ptr->receivers, first, next, cur) { LIST_FOREACH(sock_ptr->receivers, first, next, cur) {
...@@ -37,11 +36,11 @@ int send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -37,11 +36,11 @@ int send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
return EXIT_SUCCESS; return true;
error: error:
PERROR("Something is wrong%s.", "") PERROR("Something is wrong%s.", "")
return EXIT_FAILURE; return false;
} }
void * send_data_loop(void *ptr) { void * send_data_loop(void *ptr) {
......
...@@ -12,7 +12,7 @@ void *receive_feedback_loop(void *ptr) { ...@@ -12,7 +12,7 @@ void *receive_feedback_loop(void *ptr) {
PrrtSocket *sock_ptr = ptr; PrrtSocket *sock_ptr = ptr;
pthread_mutex_lock(&sock_ptr->closingMutex); pthread_mutex_lock(&sock_ptr->closingMutex);
while (sock_ptr->closing == FALSE) { while (sock_ptr->closing == false) {
pthread_mutex_unlock(&sock_ptr->closingMutex); pthread_mutex_unlock(&sock_ptr->closingMutex);
memset(bufin, 0, MAX_PAYLOAD_LENGTH); memset(bufin, 0, MAX_PAYLOAD_LENGTH);
PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH); PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender) { bool PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender) {
sock_ptr->sequenceNumberSource = 1; sock_ptr->sequenceNumberSource = 1;
sock_ptr->sequenceNumberRedundancy = 1; sock_ptr->sequenceNumberRedundancy = 1;
...@@ -76,11 +76,11 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i ...@@ -76,11 +76,11 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
"Cannot create data receiving thread."); "Cannot create data receiving thread.");
} }
return EXIT_SUCCESS; return true;
error: error:
PrrtSocket_close(sock_ptr); PrrtSocket_close(sock_ptr);
return EXIT_FAILURE; return false;
} }
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) { int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) {
...@@ -132,7 +132,7 @@ int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) { ...@@ -132,7 +132,7 @@ int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) {
int PrrtSocket_interrupt(PrrtSocket *sock_ptr) { int PrrtSocket_interrupt(PrrtSocket *sock_ptr) {
pthread_mutex_lock(&sock_ptr->closingMutex); pthread_mutex_lock(&sock_ptr->closingMutex);
sock_ptr->closing = TRUE; sock_ptr->closing = true;
pthread_mutex_unlock(&sock_ptr->closingMutex); pthread_mutex_unlock(&sock_ptr->closingMutex);
void **res = NULL; void **res = NULL;
......
...@@ -46,7 +46,7 @@ typedef struct { ...@@ -46,7 +46,7 @@ typedef struct {
} PrrtSocket; } PrrtSocket;
int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender); bool PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender);
int PrrtSocket_interrupt(PrrtSocket *sock_ptr); int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
int PrrtSocket_close(PrrtSocket *sock_ptr); int PrrtSocket_close(PrrtSocket *sock_ptr);
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port); int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
int is_position_relevant(const PrrtForwardPacketTable *fpt_ptr, uint16_t seqno) { int is_position_relevant(const PrrtForwardPacketTable *fpt_ptr, uint16_t seqno) {
uint16_t stop = (uint16_t) (SEQNO_SPACE / 2 + fpt_ptr->start); uint16_t stop = (uint16_t) (SEQNO_SPACE / 2 + fpt_ptr->start);
if (fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) { if (fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) {
return FALSE; return false;
} else if (!(seqno <= stop || fpt_ptr->start <= seqno)) { } else if (!(seqno <= stop || fpt_ptr->start <= seqno)) {
return FALSE; return false;
} else { } else {
uint16_t which_byte = (uint16_t) (seqno / 32); uint16_t which_byte = (uint16_t) (seqno / 32);
uint16_t which_bit = (uint16_t) (seqno % 32); uint16_t which_bit = (uint16_t) (seqno % 32);
...@@ -57,9 +57,10 @@ int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *f ...@@ -57,9 +57,10 @@ int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *f
return res; return res;
} }
int PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable * forwardPacketTable, uint16_t start, uint16_t length) { bool PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable *forwardPacketTable, uint16_t start,
uint16_t length) {
// TODO: implement efficiently // TODO: implement efficiently
int res = FALSE; bool res = false;
int i; int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
......
...@@ -15,6 +15,7 @@ int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt); ...@@ -15,6 +15,7 @@ int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, uint16_t seqno); int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, uint16_t seqno);
int PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable * forwardPacketTable, uint16_t start, uint16_t length); bool PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable *forwardPacketTable, uint16_t start,