Commit cd3cff30 authored by Andreas Schmidt's avatar Andreas Schmidt

Extract PrrtReceiver to own module.

parent eb7f6c12
Pipeline #56 passed with stage
......@@ -74,11 +74,12 @@ cdef extern from "prrt/packet.h":
ctypedef prrtPacket PrrtPacket
cdef extern from "prrt/socket.h":
cdef extern from "prrt/receiver.h":
ctypedef struct PrrtReceiver:
const char* host_name
uint16_t port
cdef extern from "prrt/socket.h":
cdef struct prrtSocket:
int dataSocketFd
int feedbackSocketFd
......@@ -100,8 +101,8 @@ cdef extern from "prrt/socket.h":
PrrtForwardPacketTable* forwardPacketTable
PrrtReceiver receivers[10]
int receiverLength
List* receivers
uint16_t packetsCount
uint16_t sequenceNumberSource
uint16_t sequenceNumberRepetition
......
add_library(PRRT ../defines.h socket.c block.c block.h packet.c packet.h processes/feedback_receiver.c processes/feedback_receiver.h processes/data_transmitter.c processes/data_transmitter.h coding_params.c coding_params.h vdmcode/block_code.c vdmcode/block_code.h coding_params.c coding_params.h stores/forward_packet_table.c stores/forward_packet_table.h processes/data_receiver.c processes/data_receiver.h)
\ No newline at end of file
add_library(PRRT ../defines.h socket.c block.c block.h packet.c packet.h receiver.c receiver.h processes/feedback_receiver.c processes/feedback_receiver.h processes/data_transmitter.c processes/data_transmitter.h coding_params.c coding_params.h vdmcode/block_code.c vdmcode/block_code.h coding_params.c coding_params.h stores/forward_packet_table.c stores/forward_packet_table.h processes/data_receiver.c processes/data_receiver.h)
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include "../../defines.h"
#include "../socket.h"
#include "../block.h"
#include "../receiver.h"
#include "../../util/dbg.h"
#include "../../util/common.h"
#include "data_transmitter.h"
......
#include <malloc.h>
#include "../util/dbg.h"
#include "receiver.h"
PrrtReceiver *PrrtReceiver_create(const char *host, uint16_t port)
{
PrrtReceiver *recv = calloc(1, sizeof(PrrtReceiver));
check_mem(recv);
uint32_t hostLength = (uint32_t) strlen(host);
recv->host_name = calloc(1, hostLength + 1);
memcpy((void *) recv->host_name, host, hostLength);
recv->port = port;
return recv;
error:
if(recv != NULL) { free(recv); }
return NULL;
}
bool PrrtReceiver_destroy(PrrtReceiver *receiver)
{
free((void *) receiver->host_name);
free(receiver);
return true;
}
#ifndef PRRT_RECEIVER_H
#define PRRT_RECEIVER_H
#include <stdbool.h>
#include <stdint.h>
typedef struct prrtReceiver {
const char* host_name;
uint16_t port;
} PrrtReceiver;
PrrtReceiver* PrrtReceiver_create(const char *host, uint16_t port);
bool PrrtReceiver_destroy(PrrtReceiver* receiver);
#endif //PRRT_RECEIVER_H
......@@ -14,6 +14,7 @@
#include "processes/data_receiver.h"
#include "socket.h"
#include "block.h"
#include "receiver.h"
PrrtSocket* PrrtSocket_create(const uint16_t port, const uint8_t is_sender) {
PrrtSocket *sock_ptr = (PrrtSocket*) calloc(1, sizeof(PrrtSocket));
......@@ -87,12 +88,7 @@ PrrtSocket* PrrtSocket_create(const uint16_t port, const uint8_t is_sender) {
}
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) {
PrrtReceiver *recv = calloc(1, sizeof(PrrtReceiver));
uint32_t hostLength = (uint32_t) strlen(host);
recv->host_name = calloc(1, hostLength + 1);
memcpy((void *) recv->host_name, host, hostLength);
recv->port = port;
PrrtReceiver *recv = PrrtReceiver_create(host, port);
List_push(sock_ptr->receivers, recv);
return 0;
}
......@@ -216,10 +212,8 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
if (sock_ptr->receivers != NULL) {
while (List_count(sock_ptr->receivers) > 0) {
// TODO: properly destroy receiver object
PrrtReceiver *recv = List_shift(sock_ptr->receivers);
free((void *) recv->host_name);
free(recv);
PrrtReceiver_destroy(recv);
}
List_destroy(sock_ptr->receivers);
sock_ptr->receivers = NULL;
......
......@@ -7,10 +7,6 @@
#include "../util/list.h"
#include "../util/bptree.h"
typedef struct prrtReceiver {
const char* host_name;
uint16_t port;
} PrrtReceiver;
typedef struct prrtSocket {
int dataSocketFd;
......
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