Commit 58120f8f authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Receivers are now proper lists.

parent 06862cde
...@@ -19,18 +19,16 @@ int send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -19,18 +19,16 @@ int send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
check(encodeResult >= 0, "Buffer too small."); check(encodeResult >= 0, "Buffer too small.");
// SENDING TO ALL RECEIVERS // SENDING TO ALL RECEIVERS
int i; LIST_FOREACH(sock_ptr->receivers, first, next, cur) {
for (i = 0; i < sock_ptr->receiverLength; i++) { PrrtReceiver* recv = cur->value;
PrrtReceiver recv = sock_ptr->receivers[i];
struct hostent *hp; struct hostent *hp;
struct sockaddr_in targetaddr; struct sockaddr_in targetaddr;
memset((char *) &targetaddr, 0, sizeof(targetaddr)); memset((char *) &targetaddr, 0, sizeof(targetaddr));
targetaddr.sin_family = AF_INET; targetaddr.sin_family = AF_INET;
targetaddr.sin_port = htons(recv.port); targetaddr.sin_port = htons(recv->port);
hp = gethostbyname(recv.host_name); hp = gethostbyname(recv->host_name);
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);
ssize_t sendtoRes = sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)); ssize_t sendtoRes = sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr));
......
...@@ -39,6 +39,8 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i ...@@ -39,6 +39,8 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
check(pthread_create(&sock_ptr->receiveFeedbackThread, NULL, receive_feedback_loop, (void *) sock_ptr) == EXIT_SUCCESS, "Cannot create receive feedback thread."); check(pthread_create(&sock_ptr->receiveFeedbackThread, NULL, receive_feedback_loop, (void *) sock_ptr) == EXIT_SUCCESS, "Cannot create receive feedback thread.");
check(pthread_create(&sock_ptr->sendThread, NULL, send_data_loop, (void *) sock_ptr) == EXIT_SUCCESS, "Cannot create send thread."); check(pthread_create(&sock_ptr->sendThread, NULL, send_data_loop, (void *) sock_ptr) == EXIT_SUCCESS, "Cannot create send thread.");
sock_ptr->receivers = List_create();
} else { } else {
// Bind Data Socket // Bind Data Socket
struct sockaddr_in address; struct sockaddr_in address;
...@@ -68,15 +70,11 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i ...@@ -68,15 +70,11 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
} }
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) {
PrrtReceiver recv = {host, port}; PrrtReceiver* recv = calloc(1, sizeof(PrrtReceiver));
recv->host_name = host;
if (sock_ptr->receiverLength < PRRT_MAX_RECEIVER_COUNT) { recv->port = port;
sock_ptr->receivers[sock_ptr->receiverLength] = recv;
sock_ptr->receiverLength++;
} else {
return -1;
}
List_push(sock_ptr->receivers, recv);
return 0; return 0;
} }
...@@ -126,12 +124,18 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) { ...@@ -126,12 +124,18 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
sock_ptr->blockStore = BPTree_destroy(sock_ptr->blockStore); sock_ptr->blockStore = BPTree_destroy(sock_ptr->blockStore);
} }
void **res = NULL; //void **res = NULL;
pthread_join(sock_ptr->sendThread, res); //pthread_join(sock_ptr->sendThread, res);
// TODO: shut down threads; // TODO: shut down threads;
// TODO: clean up all receivers if(sock_ptr->receivers != NULL) {
while(List_count(sock_ptr->receivers) > 0) {
free(List_shift(sock_ptr->receivers));
}
List_destroy(sock_ptr->receivers);
}
if(sock_ptr->outQueue != NULL) { if(sock_ptr->outQueue != NULL) {
pthread_mutex_destroy(&sock_ptr->outQueueFilledMutex); pthread_mutex_destroy(&sock_ptr->outQueueFilledMutex);
......
...@@ -33,8 +33,8 @@ typedef struct { ...@@ -33,8 +33,8 @@ typedef struct {
PrrtForwardPacketTable* forwardPacketTable; PrrtForwardPacketTable* forwardPacketTable;
PrrtReceiver receivers[PRRT_MAX_RECEIVER_COUNT]; List* receivers;
int receiverLength;
uint16_t packetsCount; uint16_t packetsCount;
uint16_t sequenceNumberSource; uint16_t sequenceNumberSource;
uint16_t sequenceNumberRepetition; uint16_t sequenceNumberRepetition;
......
...@@ -39,7 +39,7 @@ int main(int argc, char* const argv) { ...@@ -39,7 +39,7 @@ int main(int argc, char* const argv) {
while ((getline(&line, &len, fp)) != -1) { while ((getline(&line, &len, fp)) != -1) {
char buf[MAX_PAYLOAD_LENGTH]; char buf[MAX_PAYLOAD_LENGTH];
sprintf(buf, line); sprintf(buf, "%s", line);
PrrtSocket_send(&sock, buf, strlen(buf)); PrrtSocket_send(&sock, buf, strlen(buf));
} }
......
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