Commit 4c5f38ef authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Consistent naming. Small fixes.

parent 526cb9fc
......@@ -6,18 +6,18 @@
#include "socket.h"
void * send_data_loop(void *ptr) {
prrt_socket *sock_ptr = ptr;
PrrtSocket *sock_ptr = ptr;
while(1) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
while(List_count(sock_ptr->out_queue) == 0) {
pthread_cond_wait(&sock_ptr->out_queue_filled_cv, &sock_ptr->out_queue_filled_mutex);
}
prrt_packet* packet = List_shift(sock_ptr->out_queue);
PrrtPacket * packet = List_shift(sock_ptr->out_queue);
uint8_t buf[MAX_PAYLOAD_LENGTH];
uint32_t length = packet_size(packet);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, packet) < 0) {
uint32_t length = PrrtPacket_size(packet);
if(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet) < 0) {
perror("BUF too small.");
exit(0);
}
......@@ -25,7 +25,7 @@ void * send_data_loop(void *ptr) {
// SENDING TO ALL RECEIVERS
int i;
for(i = 0; i < sock_ptr->receiver_len; i++) {
prrt_receiver recv = sock_ptr->receivers[i];
PrrtReceiver recv = sock_ptr->receivers[i];
struct hostent *hp;
......@@ -43,7 +43,7 @@ void * send_data_loop(void *ptr) {
break;
}
}
delete_packet(packet);
PrrtPacket_destroy(packet);
pthread_mutex_unlock(&sock_ptr->out_queue_filled_mutex);
usleep(1);
......
......@@ -7,13 +7,13 @@
void *receive_feedback_loop(void *ptr) {
char bufin[MAX_PAYLOAD_LENGTH];
prrt_socket *sock_ptr = ptr;
PrrtSocket *sock_ptr = ptr;
while(1) {
memset(bufin, 0, MAX_PAYLOAD_LENGTH);
prrt_packet *t = prrt_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
if(t != NULL) {
delete_packet(t);
PrrtPacket_destroy(t);
}
usleep(1000);
}
......
......@@ -5,7 +5,7 @@
#include <netinet/in.h>
#include "packet.h"
void *encode_general_header(void *buf_ptr, const prrt_packet *packet);
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
void *encode_data_header(void *buf_ptr, void *payload);
......@@ -15,36 +15,36 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr);
void *decode_feedback_header(void *buf_ptr, void *payload_ptr);
uint8_t packet_type(prrt_packet *packet_ptr) {
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr) {
return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F);
}
uint8_t packet_priority(prrt_packet *packet_ptr) {
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr) {
return (uint8_t) (packet_ptr->type_priority & 0x0F);
}
uint16_t packet_size(prrt_packet *packet_ptr) {
uint16_t PrrtPacket_size(PrrtPacket *packet_ptr) {
return (uint16_t) (packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE);
}
int print_packet(prrt_packet *packet_ptr) {
int PrrtPacket_print(PrrtPacket *packet_ptr) {
printf(" 0 1 2 3\n"
" 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n"
"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
uint8_t type = packet_type(packet_ptr);
uint8_t type = PrrtPacket_type(packet_ptr);
printf("| %5u | %5u | %13u | %29u |\n", type, packet_priority(packet_ptr), packet_ptr->index, packet_ptr->seqno);
printf("| %5u | %5u | %13u | %29u |\n", type, PrrtPacket_priority(packet_ptr), packet_ptr->index, packet_ptr->seqno);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
if(type == PACKET_TYPE_DATA) {
prrt_packet_data_payload * payload = packet_ptr->payload;
PrrtPacketDataPayload * payload = packet_ptr->payload;
printf("| %61u |\n", payload->timestamp);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->group_round_trip_time, payload->packet_timeout);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
}
else if(type == PACKET_TYPE_FEEDBACK) {
prrt_packet_feedback_payload * payload = packet_ptr->payload;
PrrtPacketFeedbackPayload * payload = packet_ptr->payload;
printf("| %61u |\n", payload->group_round_trip_time);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->forward_trip_time);
......@@ -67,7 +67,7 @@ int print_packet(prrt_packet *packet_ptr) {
return 0;
}
int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
void * payload = packet_ptr->payload;
if(buf_size < packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE) {
......@@ -77,7 +77,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
uint8_t type = packet_type(packet_ptr);
uint8_t type = PrrtPacket_type(packet_ptr);
if(type == PACKET_TYPE_DATA) {
buf_ptr = encode_data_header(buf_ptr, payload);
memcpy(buf_ptr, payload + PRRT_PACKET_DATA_HEADER_SIZE, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
......@@ -92,7 +92,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
}
void *encode_feedback_header(void *buf_ptr, void *payload) {
prrt_packet_feedback_payload * feedback_payload = payload;
PrrtPacketFeedbackPayload * feedback_payload = payload;
uint32_t *receiver_ip = (uint32_t *) buf_ptr;
*receiver_ip = htonl(feedback_payload->receiver_addr);
......@@ -138,7 +138,7 @@ void *encode_feedback_header(void *buf_ptr, void *payload) {
}
void *encode_data_header(void *buf_ptr, void *payload) {
prrt_packet_data_payload * data_payload = payload;
PrrtPacketDataPayload * data_payload = payload;
uint32_t *timestamp = (uint32_t *) buf_ptr;
*timestamp = htonl(data_payload->timestamp);
......@@ -162,7 +162,7 @@ void *encode_data_header(void *buf_ptr, void *payload) {
return buf_ptr;
}
void *encode_general_header(void *buf_ptr, const prrt_packet *packet) {
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
uint8_t *type_priority = (uint8_t *) buf_ptr;
*type_priority = packet->type_priority;
buf_ptr += 1;
......@@ -178,7 +178,7 @@ void *encode_general_header(void *buf_ptr, const prrt_packet *packet) {
return buf_ptr;
}
int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
uint32_t payload_len = (uint32_t) (buf_size - PRRT_PACKET_GENERAL_HEADER_SIZE);
packet_ptr->type_priority = *(uint8_t*) buf_ptr;
buf_ptr += 1;
......@@ -193,10 +193,10 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
packet_ptr->payload = payload_buffer;
packet_ptr->payload_len = payload_len;
if(packet_type(packet_ptr) == PACKET_TYPE_DATA) {
if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_DATA) {
buf_ptr = decode_data_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_DATA_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if(packet_type(packet_ptr) == PACKET_TYPE_FEEDBACK) {
} else if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_FEEDBACK) {
buf_ptr = decode_feedback_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_FEEDBACK_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else {
......@@ -206,7 +206,7 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
}
void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
prrt_packet_feedback_payload *feedback_payload = (prrt_packet_feedback_payload *) payload_ptr;
PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) payload_ptr;
uint32_t *receiver_addr = (uint32_t *) buf_ptr;
feedback_payload->receiver_addr = ntohl(*receiver_addr);
......@@ -252,7 +252,7 @@ void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
}
void *decode_data_header(void *buf_ptr, const void *payload_ptr) {
prrt_packet_data_payload * data_payload = (prrt_packet_data_payload *) payload_ptr;
PrrtPacketDataPayload * data_payload = (PrrtPacketDataPayload *) payload_ptr;
uint32_t *timestamp = (uint32_t *) buf_ptr;
data_payload->timestamp = ntohl(*timestamp);
......@@ -276,7 +276,7 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr) {
return buf_ptr;
}
int delete_packet(prrt_packet *packet_ptr) {
int PrrtPacket_destroy(PrrtPacket *packet_ptr) {
if(packet_ptr->payload != NULL) {
free(packet_ptr->payload);
}
......@@ -285,17 +285,18 @@ int delete_packet(prrt_packet *packet_ptr) {
}
// PACKET SPECIFIC CODE
int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *data_ptr, unsigned long data_len) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(prrt_packet_data_payload));
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
unsigned long data_len) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketDataPayload));
packet_ptr->type_priority = PACKET_TYPE_DATA << 4;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = 17; // TODO: replace with sensible value
packet_ptr->seqno = 4711; // TODO: replace with sensible value
void *content_buf = malloc(sizeof(prrt_packet_data_payload) + data_len);
void *content_buf = malloc(sizeof(PrrtPacketDataPayload) + data_len);
prrt_packet_data_payload * source_payload = content_buf;
PrrtPacketDataPayload * source_payload = content_buf;
struct timeval tv;
gettimeofday(&tv,NULL);
......@@ -308,22 +309,24 @@ int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *da
source_payload->feedback_timeout = 170; // TODO: payload->feedback_timer
packet_ptr->payload = content_buf;
memcpy(content_buf + sizeof(prrt_packet_data_payload), data_ptr, data_len);
memcpy(content_buf + sizeof(PrrtPacketDataPayload), data_ptr, data_len);
packet_ptr->payload_len = payload_length;
return 0;
}
prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint16_t ngap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint32_t buffer_feedback) {
prrt_packet *packet_ptr = malloc(sizeof(prrt_packet));
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
uint16_t ngap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback) {
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
packet_ptr->type_priority = PACKET_TYPE_FEEDBACK << 4;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = index;
packet_ptr->seqno = seqno;
prrt_packet_feedback_payload * payload = malloc(sizeof(prrt_packet_feedback_payload));
PrrtPacketFeedbackPayload * payload = malloc(sizeof(PrrtPacketFeedbackPayload));
payload->group_round_trip_time = round_trip_time;
payload->forward_trip_time = forward_trip_time;
......@@ -336,7 +339,7 @@ prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t se
payload->buffer_feedback = buffer_feedback;
packet_ptr->payload = (void*) payload;
packet_ptr->payload_len = (uint32_t) (sizeof(prrt_packet_feedback_payload));
packet_ptr->payload_len = (uint32_t) (sizeof(PrrtPacketFeedbackPayload));
return packet_ptr;
}
\ No newline at end of file
......@@ -5,8 +5,10 @@
#define PACKET_TYPE_DATA 0
#define PACKET_TYPE_REPETITION 1
#define PACKET_TYPE_PARITY 2
#define PACKET_TYPE_REDUNDANCY 2
#define PACKET_TYPE_FEEDBACK 3
#define PACKET_TYPE_PRE_REDUNDANCY 4
#define PACKET_TYPE_CHANNEL_FEEDBACK 5
#define PRRT_PACKET_GENERAL_HEADER_SIZE 4
typedef struct {
......@@ -15,7 +17,7 @@ typedef struct {
uint16_t seqno;
void* payload;
uint32_t payload_len;
} prrt_packet;
} PrrtPacket;
#define PRRT_PACKET_DATA_HEADER_SIZE 12
typedef struct {
......@@ -24,7 +26,7 @@ typedef struct {
uint16_t packet_timeout;
uint16_t decoding_timeout;
uint16_t feedback_timeout;
} prrt_packet_data_payload;
} PrrtPacketDataPayload;
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
typedef struct {
......@@ -38,33 +40,29 @@ typedef struct {
uint16_t nburst;
uint32_t bandwidth_estimate;
uint32_t buffer_feedback;
} prrt_packet_feedback_payload;
} PrrtPacketFeedbackPayload;
uint8_t packet_type(prrt_packet *packet_ptr);
uint8_t packet_priority(prrt_packet *packet_ptr);
uint16_t packet_size(prrt_packet *packet_ptr);
int print_packet(prrt_packet *packet_ptr);
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr);
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
uint16_t PrrtPacket_size(PrrtPacket *packet_ptr);
int PrrtPacket_print(PrrtPacket *packet_ptr);
// CREATE: PRRT_PACKET
// ENCODE: PRRT_PACKET -> BYTES
// DECODE: BYTES -> PRRT_PACKET
// DELETE:
// DESTROY:
int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr);
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
unsigned long data_len);
int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *data_ptr, unsigned long data_len);
int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr);
int delete_packet(prrt_packet *packet_ptr);
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback);
int create_packet_repetition(prrt_packet packet, uint8_t priority);
int create_packet_parity(prrt_packet packet, uint8_t priority);
prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint16_t ngap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint32_t buffer_feedback);
int encode_packet_feedback(void *buf_ptr, uint16_t buf_size, prrt_packet *pkt_ptr);
int decode_packet_feedback(void* buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr);
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet_ptr);
#endif //PRRT_FRAME_H
......@@ -10,7 +10,7 @@
#include "feedback_receiver.h"
#include "data_transmitter.h"
int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender) {
int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender) {
// Create Data Socket
if((sock_ptr->fd_data = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("cannot create socket");
......@@ -70,8 +70,8 @@ int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender)
return 0;
}
int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) {
prrt_receiver recv = {host , port};
int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port) {
PrrtReceiver recv = {host , port};
if(sock_ptr->receiver_len < PRRT_MAX_RECEIVER_COUNT) {
sock_ptr->receivers[sock_ptr->receiver_len] =recv;
......@@ -83,11 +83,11 @@ int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) {
return 0;
}
int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) {
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
prrt_packet* packet = malloc(sizeof(prrt_packet));
create_packet_data(packet, 5, data, data_len);
PrrtPacket * packet = malloc(sizeof(PrrtPacket));
PrrtPacket_create_data_packet(packet, 5, data, data_len);
List_push(sock_ptr->out_queue, packet);
pthread_cond_signal(&sock_ptr->out_queue_filled_cv);
......@@ -96,7 +96,7 @@ int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) {
return 0;
}
prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
PrrtPacket *PrrtSocket_recv(PrrtSocket *sock_ptr) {
unsigned char buffer[MAX_PAYLOAD_LENGTH];
// RECEIVE DATA
......@@ -108,8 +108,8 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
uint16_t remote_port = ntohs(remote.sin_port);
char *remote_host = inet_ntoa(remote.sin_addr);
prrt_packet *packet = malloc(sizeof(prrt_packet));
decode_packet(buffer, (uint16_t) n, packet);
PrrtPacket *packet = malloc(sizeof(PrrtPacket));
PrrtPacket_decode(buffer, (uint16_t) n, packet);
// REPLY
struct sockaddr_in targetaddr;
......@@ -121,11 +121,11 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
hp = gethostbyname(remote_host);
memcpy((void *)&targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);
prrt_packet* feedback_pkt_ptr = create_packet_feedback(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];
uint32_t length = packet_size(feedback_pkt_ptr);
uint32_t length = PrrtPacket_size(feedback_pkt_ptr);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr) < 0) {
if(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr) < 0) {
perror("BUF too small.");
} else {
if((sendto(sock_ptr->fd_feedback, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) < 0)) {
......@@ -137,7 +137,7 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
return packet;
}
int prrt_close_socket(prrt_socket *sock_ptr) {
int PrrtSocket_close(PrrtSocket *sock_ptr) {
// TODO: shut down threads;
// TODO: clean up all receivers
......@@ -151,7 +151,7 @@ int prrt_close_socket(prrt_socket *sock_ptr) {
return 0;
}
prrt_packet * prrt_recv_feedback(prrt_socket *sock_ptr, void *bufin, size_t length) {
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, void *bufin, size_t length) {
ssize_t n;
struct sockaddr_in remote;
socklen_t addrlen = sizeof(remote);
......@@ -165,7 +165,7 @@ prrt_packet * prrt_recv_feedback(prrt_socket *sock_ptr, void *bufin, size_t leng
char *remote_host = inet_ntoa(remote.sin_addr);
printf("RECV FEEDBACK: %s:%d\n", remote_host, remote_port);
prrt_packet * packet_ptr = malloc(sizeof(prrt_packet));
decode_packet(bufin, (uint16_t) n, packet_ptr);
PrrtPacket * packet_ptr = malloc(sizeof(PrrtPacket));
PrrtPacket_decode(bufin, (uint16_t) n, packet_ptr);
return packet_ptr;
}
......@@ -12,7 +12,7 @@
typedef struct {
char* host_name;
uint16_t port;
} prrt_receiver;
} PrrtReceiver;
typedef struct {
int fd_data;
......@@ -24,21 +24,21 @@ typedef struct {
pthread_cond_t out_queue_filled_cv;
List *out_queue;
prrt_receiver receivers[PRRT_MAX_RECEIVER_COUNT];
PrrtReceiver receivers[PRRT_MAX_RECEIVER_COUNT];
int receiver_len;
uint16_t packets_count;
uint16_t seqno_source;
uint16_t seqno_repetition;
uint16_t seqno_parity;
uint16_t seqno_feedback;
} prrt_socket;
} PrrtSocket;
int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender);
int prrt_close_socket(prrt_socket *sock_ptr);
int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port);
int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len);
prrt_packet *prrt_recv(prrt_socket *sock_ptr);
prrt_packet * prrt_recv_feedback(prrt_socket *sock_ptr, void *bufin, size_t length);
int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender);
int PrrtSocket_close(PrrtSocket *sock_ptr);
int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port);
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len);
PrrtPacket *PrrtSocket_recv(PrrtSocket *sock_ptr);
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, void *bufin, size_t length);
#endif // PRRT_SOCKET_H
......@@ -12,17 +12,17 @@ int main(int argc, char* const argv[]) {
uint16_t port = (uint16_t) atoi(argv[1]);
prrt_socket sock;
prrt_packet *pkt;
PrrtSocket sock;
PrrtPacket *pkt;
printf("PRRT - RECEIVER\n");
if(prrt_create_socket(&sock, port, 0) < 0) {
if(PrrtSocket_create(&sock, port, 0) < 0) {
perror("could not create socket");
return 0;
}
while(1) {
pkt = prrt_recv(&sock);
pkt = PrrtSocket_recv(&sock);
if(pkt == NULL) {
perror("Error receiving data");
break;
......@@ -36,7 +36,7 @@ int main(int argc, char* const argv[]) {
usleep(1);
}
prrt_close_socket(&sock);
PrrtSocket_close(&sock);
pthread_exit(NULL);
......
......@@ -11,31 +11,31 @@ int main(int argc, char* const argv) {
}
uint16_t local_port = 6000;
prrt_socket sock = {};
PrrtSocket sock = {};
printf("PRRT - SENDER\n");
if(prrt_create_socket(&sock, local_port, TRUE) < 0) {
if(PrrtSocket_create(&sock, local_port, TRUE) < 0) {
perror("socket failed");
return 0;
}
char *remote_host = "localhost";
uint16_t remote_port = 5000;
prrt_connect(&sock, remote_host, remote_port);
PrrtSocket_connect(&sock, remote_host, remote_port);
char *remote_host2 = "localhost";
uint16_t remote_port2 = 5004;
prrt_connect(&sock, remote_host2, remote_port2);
PrrtSocket_connect(&sock, remote_host2, remote_port2);
printf("SENDING\n");
for(i= 0; i < 5; i++) {
char buf[30];
sprintf(buf, "this is a message %d", i);
prrt_send(&sock, buf, strlen(buf));
PrrtSocket_send(&sock, buf, strlen(buf));
}
usleep(1000*1000);
prrt_close_socket(&sock);
PrrtSocket_close(&sock);
printf("COMPLETELY CLOSED\n");
return 0;
}
Supports Markdown
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