⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alc_rx.c

📁 这个程序实现了FLUTE协议
💻 C
📖 第 1 页 / 共 3 页
字号:
		if(!object_exists) {			while(to != NULL) {				if(to->toi == toi) {					object_exists = 1;					break;				}				to = to->next;			}			if(to == NULL) {				continue;			}		}		obj_completed = object_completed(to);		if(((s->state == STxStopped) && (!obj_completed))) {			/*printf("alc_recv() STxStopped, toi: %i\n", toi);			fflush(stdout);*/			*retval = -3;			return NULL;			}#ifdef WIN32		Sleep(1);#else		usleep(1000);#endif	}	printf("\n");	remove_wanted_object(s_id, toi);	/* Parse data from object to data buffer, return buffer and buffer length */	to = object_exist(toi, s, 1);	if(to->fec_enc_id == COM_NO_C_FEC_ENC_ID) {		buf = null_fec_decode_object(to, data_len, s);	}        else if(to->fec_enc_id == SIMPLE_XOR_FEC_ENC_ID) {                buf = xor_fec_decode_object(to, data_len, s);        }	else if(to->fec_enc_id == SB_SYS_FEC_ENC_ID && to->fec_inst_id == REED_SOL_FEC_INST_ID) {		buf = rs_fec_decode_object(to, data_len, s);	}				if(buf == NULL) {		*retval = -1;	}	free_object(to, s, 1);	return buf;}/*  * This function gives any object to application, when it is completely received. * * Params:	int s_id: Session identifier, *			ULONGLONG/unsigned long long *toi: Pointer to Transport Object Identifier, *			ULONGLONG/unsigned long long *datalen: Pointer to object length, *			int *retval: Return value in error cases/stopping situations. * * Return:	char*: Pointer to buffer which contains object's data, *			NULL: In errors/stopping situations * */char* alc_recv2(int s_id,#ifdef WIN32			   			   ULONGLONG *toi,			   ULONGLONG *data_len,#else			   unsigned long long *toi,			   unsigned long long *data_len,#endif			   int *retval) {	bool obj_completed = false;	alc_session_t *s;#ifdef WIN32			   	ULONGLONG tmp_toi = 0;#else	unsigned long long tmp_toi = 0;#endif	char *buf = NULL; /* Buffer where to construct the object from data units */	trans_obj_t *to;		s = get_alc_session(s_id);	while(1) {				to = s->obj_list;		if(s->state == SExiting) {			/*printf("alc_recv2() SExiting\n");			fflush(stdout);*/			*retval = -2;			return NULL;			}		else if(s->state == SClosed) {			/*printf("alc_recv2() SClosed\n");			fflush(stdout);*/			*retval = 0;			return NULL;			}		else if(((s->state == STxStopped) && (to == NULL))) {			/*printf("alc_recv2() STxStopped\n");			fflush(stdout);*/			*retval = -3;			return NULL;			}		while(to != NULL) {			if(s->state == SExiting) {				/*printf("alc_recv2() SExiting\n");				fflush(stdout);*/				*retval = -2;				return NULL;				}			else if(s->state == SClosed) {				/*printf("alc_recv2() SClosed\n");				fflush(stdout);*/				*retval = 0;				return NULL;				}			obj_completed = object_completed(to);			if(obj_completed) {				tmp_toi = to->toi;				break;			}			if(((s->state == STxStopped) && (!obj_completed))) {				/*printf("alc_recv2() STxStopped\n");				fflush(stdout);*/				*retval = -3;				return NULL;				}			to = to->next;		}			if(obj_completed) {			break;		}#ifdef WIN32		Sleep(1);#else		usleep(1000);#endif	}	printf("\n");	remove_wanted_object(s_id, tmp_toi);	/* Parse data from object to data buffer, return buffer length */	to = object_exist(tmp_toi, s, 1);	if(to->fec_enc_id == COM_NO_C_FEC_ENC_ID) {		buf = null_fec_decode_object(to, data_len, s);	}        else if(to->fec_enc_id == SIMPLE_XOR_FEC_ENC_ID) {                buf = xor_fec_decode_object(to, data_len, s);        }	else if(to->fec_enc_id == SB_SYS_FEC_ENC_ID && to->fec_inst_id == REED_SOL_FEC_INST_ID) {		buf = rs_fec_decode_object(to, data_len, s);	}				if(buf == NULL) {		*retval = -1;	}	else {		*toi = tmp_toi;	}	free_object(to, s, 1);	return buf;}/* * This function gives temp filename of object to application, when object is completely received. * * Params:	int s_id: Session identifier, *			ULONGLONG/unsigned long long *toi: Pointer to Transport Object Identifier, *			char *tmp_filename: Pointer to object's temporary filename. *			int *retval: Return value in error cases/stopping situations. * * Return:	char*: Pointer to buffer which contains temporary filename, *			NULL: In errors/stopping situations. * */char* alc_recv3(int s_id,#ifdef WIN32			   				ULONGLONG *toi,#else				unsigned long long *toi,#endif				int *retval) {	bool obj_completed = false;	alc_session_t *s;#ifdef WIN32			   	ULONGLONG tmp_toi = 0;#else	unsigned long long tmp_toi = 0;#endif	trans_obj_t *to;	char *tmp_filename = NULL;		s = get_alc_session(s_id);	while(1) {				to = s->obj_list;		if(s->state == SExiting) {			/*printf("alc_recv3() SExiting\n");			fflush(stdout);*/			*retval = -2;			return NULL;			}		else if(s->state == SClosed) {			/*printf("alc_recv3() SClosed\n");			fflush(stdout);*/			*retval = 0;			return NULL;			}		else if(((s->state == STxStopped) && (to == NULL))) {			/*printf("alc_recv3() STxStopped, to == NULL\n");			fflush(stdout);*/			*retval = -3;			return NULL;			}		while(to != NULL) {			obj_completed = false;			if(s->state == SExiting) {				/*printf("alc_recv3() SExiting\n");				fflush(stdout);*/				*retval = -2;				return NULL;				}			else if(s->state == SClosed) {				/*printf("alc_recv3() SClosed\n");				fflush(stdout);*/				*retval = 0;				return NULL;				}			else if(s->state == STxStopped) {				break;                	}			obj_completed = object_completed(to);			if(obj_completed) {				tmp_toi = to->toi;				break;			}			to = to->next;		}			if(obj_completed) {			break;		}		else if(s->state == STxStopped) {			/* Check if there is completed object after A-flag is received */			to = s->obj_list;			while(to != NULL) {                        	obj_completed = object_completed(to);                        	if(obj_completed) {                                	tmp_toi = to->toi;                                	break;                        	}                        	to = to->next;                	}			if(obj_completed) {                        	break;                	}			else {                        	/*printf("alc_recv3() STxStopped, any object not completed\n");                        	fflush(stdout);*/                        	*retval = -3;                        	return NULL;                	}			}#ifdef WIN32		Sleep(1);#else		usleep(1000);#endif	}	remove_wanted_object(s_id, tmp_toi);	if(!(tmp_filename = (char*)calloc((strlen(to->tmp_filename) + 1), sizeof(char)))) {		printf("Could not alloc memory for tmp_filename!\n");		*retval = -1;		return NULL;    	}	memcpy(tmp_filename, to->tmp_filename, strlen(to->tmp_filename));	free_object(to, s, 1);	*toi = tmp_toi;  	return tmp_filename;}/*  * This function gives an FDT Instance to application, when it is completely received. * * Params:	int s_id: Session identifier, *			ULONGLONG/unsigne dlong long *data_len: Pointer to FDT Instance length, *			int *retval: Return value in error cases/stopping situations. *			unsigned char *content_enc_algo: Location where to store used content encoding, * * Return:	char*: Pointer to buffer which contains FDT Instance's data, *			NULL: in errors/stopping situations * */ char* fdt_recv(int s_id,#ifdef WIN32				ULONGLONG *data_len,#else				unsigned long long *data_len,#endif				int *retval,				unsigned char *content_enc_algo,	                        int* fdt_instance_id) {		alc_session_t *s;                                                                                                                                          	char *buf = NULL; /* Buffer where to construct the object from data units */                                                                                                                                     	trans_obj_t *to;        	s = get_alc_session(s_id);        	while(1) {		to = s->fdt_list;		if(s->state == SExiting) {			/*printf("fdt_recv() SExiting\n");			fflush(stdout);*/            *retval = -2;            return NULL;        }        else if(s->state == SClosed) {            /*printf("fdt_recv() SClosed\n");            fflush(stdout);*/            *retval = 0;            return NULL;        }		else if(s->state == STxStopped) {			/*printf("fdt_recv() STxStopped\n");			fflush(stdout);*/			*retval = -3;			return NULL;			}			if(to == NULL) {			                                                                                                                                              #ifdef WIN32			Sleep(1);#else			usleep(1000);#endif			continue;			}				do {			if(object_completed(to)) {				set_received_instance(s, (unsigned int)to->toi);				*content_enc_algo = to->content_enc_algo;				*fdt_instance_id = (int)to->toi;				if(to->fec_enc_id == COM_NO_C_FEC_ENC_ID) {			      		buf = null_fec_decode_object(to, data_len, s);				}        			else if(to->fec_enc_id == SIMPLE_XOR_FEC_ENC_ID) {                			buf = xor_fec_decode_object(to, data_len, s);        			}				else if(to->fec_enc_id == SB_SYS_FEC_ENC_ID && to->fec_inst_id == REED_SOL_FEC_INST_ID) {					buf = rs_fec_decode_object(to, data_len, s);				}				if(buf == NULL) {					*retval = -1;				}				free_object(to, s, 0);				return buf;			}			to = to->next;		} while(to != NULL);#ifdef WIN32        Sleep(1);#else		usleep(1000);#endif	}	return buf;}/*  * This function checks if received unit belongs to an object which already exists in session or not.  * * Params:	ULONGLONG/unsigned long long toi: Transport Object Identifier, *			alc_session_t *s: Pointer to session, *			int type: Type of object to be checked (0 = FDT Instance, 1 = normal object) * * Return:	trans_obj_t*: Pointer to object in success, NULL otherwise  * */trans_obj_t* object_exist(#ifdef WIN32						  ULONGLONG toi,#else						  unsigned long long toi,#endif						  alc_session_t *s, int type) {		trans_obj_t *trans_obj = NULL;	if(type == 0) {		trans_obj = s->fdt_list;	}	else if(type == 1) {		trans_obj = s->obj_list;	}	if(trans_obj != NULL) {		for(;;) {			if(trans_obj->toi == toi) {				break;			}			if(trans_obj->next == NULL) {				trans_obj = NULL;				break;			}			trans_obj = trans_obj->next;		}	}	return trans_obj;}/* * This function checks if received unit belongs to a source block, which already exists or not.  * * Params:	unsigned int sbn: Source Block Number, *			trans_obj_t *trans_obj: Pointer to object * * Return:	trans_block_t*: Pointer to block in success, NULL otherwise  * *//*trans_block_t* block_exist(unsigned int sbn, trans_obj_t *trans_obj) {		trans_block_t *trans_block;	trans_block = trans_obj->block_list_start;	if(trans_block != NULL) {		for(;;) {			if(trans_block->sbn == sbn) {				break;			}			if(trans_block->next == NULL) {				trans_block = NULL;				break;			}			trans_block = trans_block->next;		}	}	return trans_block;}*//* * This function checks if the object has been received completely. * * Params:	trans_obj_t *to: Transport Object to be checked * * Return:	bool: true when object ready, false otherwise * *//*bool object_completed(trans_obj_t *to) {  bool ready = false;  trans_block_t *tb = to->block_list_start;  if(to->nb_of_created_blocks != to->bs->N) {    return ready;  }    while(tb != NULL) {        if(tb->nb_of_rx_units < tb->k) {      return ready;    }    tb = tb->next;  }    ready = true;    return ready;}*//* * This function checks if the object has been received completely. * * Params:      trans_obj_t *to: Transport Object to be checked * * Return:      bool: true when object ready, false otherwise * */bool object_completed(trans_obj_t *to) {     bool ready = false;    /*  trans_block_t *tb = to->block_list_start;    if(to->nb_of_created_blocks != to->bs->N) {    return ready;  }    while(tb != NULL) {        if(!tb->completed) {      return ready;    }    tb = tb->next;  }    ready = true;   */      if(to->nb_of_ready_blocks == to->bs->N) {    ready = true;  }    return ready;}/* * This function checks if the block has been received completely. * * Params:      trans_block_t *tb: Pointer to block * * Return:      bool: true when object ready, false otherwise * */bool block_ready_to_decode(trans_block_t *tb) {	bool ready = false;	if(tb->nb_of_rx_units >= tb->k) {		ready = true;	}	return ready;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -