/* * Copyright (c) 2003 INRIA - All rights reserved * main authors: Christoph Neumann - christoph.neumann@inrialpes.fr * Vincent Roca - vincent.roca@inrialpes.fr * Julien Laboure - julien.laboure@inrialpes.fr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * frecv.c * * flute receiver side functions */ #include "flute.h" void FluteRecv(void) { int mcl_option; #if defined(ALC) if (optimode == OPTIMIZE_SPACE) { mcl_option = 1; if (mcl_ctl(id, MCL_OPT_FLUTE_DELIVERY, NULL,0)) EXIT(("mcl_ctl: MCL_OPT_FLUTE_DELIVERY failed\n")) mcl_option = 0; if (mcl_ctl(id, MCL_OPT_POSTPONE_FEC_DECODING, (void*)&mcl_option, sizeof(mcl_option))) { /* non critical... ignore! */ //EXIT(("mcl_ctl: MCL_OPT_POSTPONE_FEC_DECODING failed\n")) } } else if (optimode == OPTIMIZE_SPEED) { mcl_option = 1; if (mcl_ctl(id, MCL_OPT_FLUTE_DELIVERY, NULL,0)) EXIT(("mcl_ctl: MCL_OPT_FLUTE_DELIVERY failed\n")) mcl_option = 0; if (mcl_ctl(id, MCL_OPT_POSTPONE_FEC_DECODING, (void*)&mcl_option, sizeof(mcl_option))) { /* non critical... ignore! */ //EXIT(("mcl_ctl: MCL_OPT_POSTPONE_FEC_DECODING failed\n")) } } else if (optimode == OPTIMIZE_CPU) { mcl_option = 0; if (mcl_ctl(id, MCL_OPT_FLUTE_DELIVERY, NULL, 0)) EXIT(("mcl_ctl: MCL_OPT_FLUTE_DELIVERY failed\n")) mcl_option = 1; if (mcl_ctl(id, MCL_OPT_POSTPONE_FEC_DECODING, (void*)&mcl_option, sizeof(mcl_option))) { /* * non critical... ignore! * for instance, this is only valid if RSE is used, * but does not apply to LDPC/LDGM */ //EXIT(("mcl_ctl: MCL_OPT_POSTPONE_FEC_DECODING failed\n")) } } else { EXIT(("FATAL ERROR: invalid optimization mode!")) } #endif /* RM_PROTOCOL */ if (src_addr > 0) /* in host format! */ { if (mcl_ctl(id, MCL_OPT_SRC_ADDR, (void*)&src_addr, sizeof(src_addr))) EXIT(("mcl_ctl: MCL_OPT_SRC_ADDR failed\n")) } if (!interactive) /* in host format! */ { if (mcl_ctl(id, MCL_OPT_FLUTE_DELIVER_ALL_ADU, (void*) NULL,0)) EXIT(("mcl_ctl: MCL_OPT_FLUTE_DELIVER_ALL_ADU failed\n")) } PRINT(("Waiting for data...\n")) RecvFiles(); mcl_close(id); PRINT(("\nFluteRecv completed\n")) } void RecvFiles(void) { char *buf_file = NULL; /* buffer for recv'd fragment */ int len = 0; pFFile ThisFile=NULL; unsigned int toi; int max_fragment_size; /* Big files are fragmented into fragments of this size */ /* determine the maximum fragment size (pessimistic evaluation that * does not take FEC used into account) */ max_fragment_size = RSE_MAX_FRAGMENT_SIZE; #ifdef ALC max_fragment_size = max(max_fragment_size, LDPC_MAX_FRAGMENT_SIZE); #endif /* RM_PROTOCOL */ max_fragment_size = max(max_fragment_size, NO_FEC_MAX_FRAGMENT_SIZE); /* Objects contain a file of fdt*/ if(!(buf_file = (char*)malloc(max_fragment_size))) { EXIT(("Error: Cannot alloc memory!\n")) } /* Receiving ALL Objects... */ while((len = mcl_recv_flute(id, buf_file, max_fragment_size, &toi)) != -1) { #ifdef DEBUG PRINT(("New Object Received (%d Bytes), TOI: %lu\n", len, toi)) #endif #if 0 /* Realloc the Buffer to fit our needs */ if (!(buf_file = (char*)realloc(buf_file, len))) { EXIT(("Error: Cannot realloc memory (RecvFiles)!\n")) } #endif pthread_mutex_lock(&flutemutex); if(toi==0) /*we have an fdt instance */ { updateFDT(buf_file); if (!interactive) myfiles=updateFFile(myfiles); } else if((ThisFile=FFileFindTOI(toi, myfiles))!=NULL) /*reception of a known & selected file */ { PRINT(("Received file %s \n", ThisFile->fullname)) if(ThisFile->writeIt && ThisFile->fd != 0) { if (write((int)ThisFile->fd, buf_file, len) < 0) EXIT(("mclrecv: write failed\n")) PRINT(("Writing file \"%s\" (%ld Bytes).\n", ThisFile->fullname, ThisFile->filesize)) ASSERT(ThisFile->fd != 0) close(ThisFile->fd); ThisFile->received=1; //FFileRemove(ThisFile->fullname,&myFiles); } else { PRINT(("Skipped file %s \n", ThisFile->fullname)) } } else /*received unknown or unwanted file*/ { PRINT(("WARNING: Received unknown file\n")) } pthread_mutex_unlock(&flutemutex); if (!(buf_file = (char*)realloc(buf_file, max_fragment_size + MAX_TRAILER_SIZE))) { EXIT(("Error: Cannot realloc memory (RecvFiles)!\n")) } } if(buf_file) free(buf_file); return; }