Skip to content
Extraits de code Groupes Projets
Valider 8f5fd02f rédigé par Samuel de Meester de Ravestein's avatar Samuel de Meester de Ravestein
Parcourir les fichiers

make progress on the sender

parent 41d422fa
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -7,7 +7,7 @@ HEADERS_DIR = -Iheaders
LDFLAGS = -lz
# Adapt these as you want to fit with your project
SENDER_SOURCES = $(wildcard src/sender.c src/log.c src/our_utils.c src/packet_interface.c)
SENDER_SOURCES = $(wildcard src/sender.c src/log.c src/our_utils.c src/packet_interface.c src/sender_utils.c)
RECEIVER_SOURCES = $(wildcard src/receiver.c src/log.c src/our_utils.c src/packet_interface.c src/receiver_utils.c)
SENDER_OBJECTS = $(SENDER_SOURCES:.c=.o)
......
#ifndef __SENDER_UTILS_H_
#define __SENDER_UTILS_H_
#include <fcntl.h>
#include <poll.h>
#include <stdlib.h>
......@@ -14,3 +17,5 @@
#include "packet_interface.h"
#endif
\ No newline at end of file
#include "../headers/sender.h"
#include "../headers/sender_utils.h"
int print_usage(char *prog_name) {
ERROR("Usage:\n\t%s [-f filename] [-s stats_filename] [-c] receiver_ip receiver_port", prog_name);
......@@ -55,6 +55,7 @@ int main(int argc, char **argv) {
DEBUG("You can only see me if %s", "you built me using `make debug`");
ERROR("This is not an error, %s", "now let's code!");
// Now let's code!
// Alright :-)
......@@ -77,8 +78,8 @@ int main(int argc, char **argv) {
}
// *** Step 2: Prepare to send ***
int fd = open(filename, O_RDONLY);
if (fd == -1)
int sending_fd = open(filename, O_RDONLY);
if (sending_fd == -1)
{
close(socket_fd);
ERROR("An error occured while trying to open the file\n");
......@@ -88,20 +89,56 @@ int main(int argc, char **argv) {
// *** Step: Time for sending ***
struct pollfd *pfd = (struct pollfd *) calloc(1, sizeof(struct pollfd));
if (pfd == NULL)
if (pfds == NULL)
{
close(socket_fd);
close(sending_fd);
ERROR("Calloc failed\n");
return EXIT_FAILURE;
}
pfd->fd = socket_fd;
pfd->events = POLLIN | POLLOUT; // want to read and write from the socket
// Socket -> we want to read and write from it
pfd[0].fd = socket_fd;
pfd[0].events = POLLIN | POLLOUT;
bool connected = true;
while (connected)
bool sending_file_read = false;
bool ack_received = false;
int rvalue;
while (!(sending_file_read && ack_received))
{
/* code */
// Blocking calling system
rvalue = poll(pfd, 1, -1); // -1 means waits forever
if (rvalue == -1)
{
close(socket_fd);
close(sending_fd);
ERROR("poll function failed\n");
return EXIT_FAILURE;
}
if ( !(sending_file_read) && (pfd->revents & POLLOUT) )
{
rvalue = read_and_send();
if (rvalue == -1)
{
close(socket_fd);
close(sending_fd);
ERROR("poll function failed\n");
return EXIT_FAILURE;
}
}
else if (pfd->revents & POLLIN)
{
rvalue = handle_returning_pkt();
if (rvalue == -1)
{
close(socket_fd);
close(sending_fd);
ERROR("poll function failed\n");
return EXIT_FAILURE;
}
}
}
......@@ -156,7 +193,7 @@ int main(int argc, char **argv) {
// }
// pkt_del(pkt);
close(fd);
close(sending_fd);
close(socket_fd);
return EXIT_SUCCESS;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter