Commit a0976594 authored by Andreas Schmidt's avatar Andreas Schmidt

Socket initalization now takes proper care of sender or receiver role.

parent 836e3a3f
......@@ -7,12 +7,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
find_package (Threads)
add_subdirectory(tests)
add_subdirectory(prrt)
add_library(PRRT defines.h prrt/socket.c prrt/block.c prrt/block.h prrt/packet.c prrt/packet.h prrt/processes/feedback_receiver.c prrt/processes/feedback_receiver.h prrt/processes/data_transmitter.c prrt/processes/data_transmitter.h prrt/coding_params.c prrt/coding_params.h prrt/vdmcode/block_code.c prrt/vdmcode/block_code.h prrt/coding_params.c prrt/coding_params.h prrt/collections/in_buffer.c prrt/collections/in_buffer.h prrt/stores/forward_packet_table.c prrt/stores/forward_packet_table.h)
add_library(UTIL defines.h util/common.c util/common.h util/list.c util/list.h)
add_subdirectory(tests)
add_executable(sender sender.c)
add_executable(receiver receiver.c)
add_executable(tester tester.c)
......
......@@ -21,36 +21,25 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
return -1;
}
// Bind Data Socket
struct sockaddr_in address;
memset((char*) &address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons(port);
if(bind(sock_ptr->fd_data, (struct sockaddr *) &address, sizeof(address)) < 0) {
perror("cannot bind socket");
return -1;
}
// Create Feedback Socket
if((sock_ptr->fd_feedback = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("cannot create socket");
return -1;
}
// Bind Feedback Socket
memset((char*) &address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons((uint16_t) (port + 1)); // TODO: fail if port is 65535
if(bind(sock_ptr->fd_feedback, (struct sockaddr *) &address, sizeof(address)) < 0) {
perror("cannot bind socket");
return -1;
}
if(is_sender) {
// Bind Feedback Socket
struct sockaddr_in address;
memset((char*) &address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons((uint16_t) (port + 1)); // TODO: fail if port is 65535
if(bind(sock_ptr->fd_feedback, (struct sockaddr *) &address, sizeof(address)) < 0) {
perror("cannot bind socket");
return -1;
}
pthread_mutex_init(&sock_ptr->out_queue_filled_mutex, NULL);
pthread_cond_init(&sock_ptr->out_queue_filled_cv, NULL);
......@@ -68,7 +57,19 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
exit(-1);
}
} else {
// Bind Data Socket
struct sockaddr_in address;
memset((char*) &address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons(port);
if(bind(sock_ptr->fd_data, (struct sockaddr *) &address, sizeof(address)) < 0) {
perror("cannot bind socket");
return -1;
}
PrrtForwardPacketTable_create(sock_ptr->forwardPacketTable);
}
return 0;
......
//
// Created by andreas on 16.02.16.
//
#include "forward_packet_table.h"
int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt) {
}
\ No newline at end of file
#ifndef PRRT_FORWARD_PACKET_TABLE_H
#define PRRT_FORWARD_PACKET_TABLE_H
#include <stdint.h>
typedef struct {
uint32_t data[2048]; // sequence number space is 2**16 and we have 32 bit so: 2048
uint16_t start;
} PrrtForwardPacketTable;
int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
int PrrtForwardPacketTable_test_set_number(PrrtForwardPacketTable* fpt_ptr, uint16_t seqno);
int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt);
#endif //PRRT_FORWARD_PACKET_TABLE_H
......@@ -5,7 +5,6 @@ add_subdirectory(lib/gtest-1.7.0)
enable_testing()
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runPRRTTests basic_check.cpp)
add_executable(runPRRTTests forward_packet_table_tests.cpp)
target_link_libraries(runPRRTTests gtest gtest_main)
target_link_libraries(runPRRTTests PRRT)
\ No newline at end of file
target_link_libraries(runPRRTTests gtest gtest_main PRRT)
\ No newline at end of file
#include <gtest/gtest.h>
TEST(FirstTest, HandlesBasic) {
}
\ No newline at end of file
#include <gtest/gtest.h>
#include "../prrt/stores/forward_packet_table.h"
TEST(ForwardPacketTable, ForwardPacketTable_Create) {
PrrtForwardPacketTable* forwardPacketTable = (PrrtForwardPacketTable *) malloc(sizeof(PrrtForwardPacketTable));
PrrtForwardPacketTable_create(forwardPacketTable);
}
\ No newline at end of file
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