static char *test_pkt_create() { packet p = pkt_create(ERROR, 1, 2, 3, 4); mu_assert("FAIL: test_pkt_create [1]", pkt_get_type(p) == ERROR); mu_assert("FAIL: test_pkt_create [2]", pkt_get_source(p) == 1); mu_assert("FAIL: test_pkt_create [3]", pkt_get_arg_pos(p) == 2); mu_assert("FAIL: test_pkt_create [4]", pkt_get_sub(p) == 3); mu_assert("FAIL: test_pkt_create [6]", pkt_get_payload(p) == 4); return NULL; }
void receiver(int socket, char *filename) { fd_set read, write; char readed[520]; int f; if(filename==NULL) f=STDOUT_FILENO; else f=open(filename,O_WRONLY|O_CREAT|O_TRUNC); while(1){ FD_ZERO(&read); FD_ZERO(&write); FD_SET(socket,&write); FD_SET(socket,&read); FD_SET(f,&write); if(select(socket+1,&read,&write, NULL,NULL)==-1) { fprintf(stderr,"Error selectreceiver\n"); return; } if(FD_ISSET(socket,&write) && FD_ISSET(socket,&read)) { printf("receiver readwritesocket\n"); int rd=readSocket(socket,readed,520); if(rd>=0) { pkt_t *pkt=pkt_new(); pkt_status_code errdec=pkt_decode((const char *)readed,(size_t)rd,pkt); printf("lu : %s\n",pkt_get_payload(pkt)); if(errdec==PKT_OK) { if(pkt_get_type(pkt)==PTYPE_DATA) { printf("On doit créer ACK/NACK\n"); } } else { fprintf(stderr,"Error receiver decode\n"); return; } pkt_del(pkt); printf("after del\n"); } } else if(FD_ISSET(f,&write)) { printf("Write file\n"); break; } } }
static char *test_pkt_get_payload() { packet p = pkt_create(REFERENCE, 1, 2, 3, 4); mu_assert("FAIL: test_pkt_get_payload [1]", pkt_get_payload(p) == 4); return NULL; }