Skip to content
Extraits de code Groupes Projets
Valider 79c3e5f7 rédigé par Vany Ingenzi's avatar Vany Ingenzi
Parcourir les fichiers

Pushing to switch to intel

parent f9f1b64d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Fichier supprimé
Fichier supprimé
...@@ -50,9 +50,9 @@ int handle_revents(struct pollfd * pfd) ...@@ -50,9 +50,9 @@ int handle_revents(struct pollfd * pfd)
return 1; return 1;
} }
void reception_loop(struct pollfd * pfd, con_state_t * state, pkt_t * pkt) void reception_loop(struct pollfd * pfd, con_state_t * state)
{ {
ASSERT(state != NULL || pkt != NULL); ASSERT(state != NULL);
int not_eof = 1; int not_eof = 1;
while (not_eof) while (not_eof)
{ {
...@@ -65,28 +65,6 @@ void reception_loop(struct pollfd * pfd, con_state_t * state, pkt_t * pkt) ...@@ -65,28 +65,6 @@ void reception_loop(struct pollfd * pfd, con_state_t * state, pkt_t * pkt)
} }
} }
/**
* Waits for a client to send data to the socket and then connectes to the client
* @return: 0 upon success, -1 in case of an error. a message will be displayed to the stderr
*/
int connect_to_a_client(int sfd, pkt_t * init_pkt)
{
char * buffer[PKT_MAX_LEN];
ssize_t written_in_buffer;
// We suppose that the first contact is going to be our client no need to check for more
int err = wait_for_client(sfd);
if (err != 0) return -1;
DEBUG_DUMP(buffer, written_in_buffer);
pkt_status_code status = pkt_decode((char *) buffer, (size_t) written_in_buffer, init_pkt);
if (status != PKT_OK)
{
ERROR("When encoding the init_packet got pkt_status = %d", status);
return -1;
}
return 0;
}
/** /**
* This main loop for the receiver. * This main loop for the receiver.
* @sfd: A valid socket. * @sfd: A valid socket.
...@@ -94,36 +72,19 @@ int connect_to_a_client(int sfd, pkt_t * init_pkt) ...@@ -94,36 +72,19 @@ int connect_to_a_client(int sfd, pkt_t * init_pkt)
*/ */
void receiver_read_write_loop(int sfd) void receiver_read_write_loop(int sfd)
{ {
pkt_t * pkt = pkt_new();
con_state_t * state = malloc(sizeof(con_state_t)); con_state_t * state = malloc(sizeof(con_state_t));
struct pollfd * pfd = (struct pollfd *) calloc(1, sizeof(struct pollfd)); struct pollfd * pfd = (struct pollfd *) calloc(1, sizeof(struct pollfd));
if (pkt == NULL || state == NULL || pfd == NULL) return; if (state == NULL || pfd == NULL) return;
pfd->fd = sfd; pfd->fd = sfd;
pfd->events = POLLIN | POLLOUT; pfd->events = POLLIN | POLLOUT;
int err = connect_to_a_client(sfd, pkt); int err = wait_for_client(sfd);
if (err == 0) if (err == 0)
return; return;
// Handle initial packet.
err = fwrite((void *) pkt_get_payload(pkt), sizeof(char), pkt_get_length(pkt), stdout);
err = fflush(stdout);
/*
if (err == 0) if (err == 0)
reception_loop(pfd, state, pkt); reception_loop(pfd, state);
*/
char * buffer[PKT_MAX_LEN];
size_t len = PKT_MAX_LEN;
err = pkt_encode(pkt, (char *) buffer, &len);
if (err == 0)
err = write(pfd->fd, (void *) buffer, len);
pkt_del(pkt);
free(state); free(state);
free(pfd); free(pfd);
} }
\ No newline at end of file
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