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

📄 main.c

📁 这个程序实现了FLUTE协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Author: peltotas $ $Date: 2006/03/16 13:45:54 $ $Revision: 1.138 $ *//* *   MAD-FLUTE: FLUTE application. *   Copyright (c) 2003-2006 TUT - Tampere University of Technology *   main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi * *   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 */#include "../flutelib/flute_inc.h"/* Global variables */int s_id;/**** Private functions ****/void signal_handler(int sig);void usage(void);unsigned int random_number(int max) {  return (unsigned int)(rand()%max);}/* * This function is programs main function. * * Params:	int argc: Number of command line arguments, *			char **argv: Pointer to command line arguments. * * Return: int: Different values (0, -1, -2, -3) depending on how program ends. * */int main(int argc, char **argv) {  int i;  int retval = 0;  int retcode = 0;  #ifdef WIN32  WSADATA wsd;#endif    arguments_t a;  int ch_id[MAX_CHANNELS_IN_SESSION];           /* Channel identifiers */  fdt_th_args_t fdt_th_args;  #ifdef WIN32  ULONGLONG sender_size;#else  unsigned long long sender_size;#endif    /* Set signal handler */    signal(SIGINT, signal_handler);#ifdef WIN32  signal(SIGBREAK, signal_handler);#endif    srand((unsigned)time(NULL));    retval = validateargs(argc, argv, &a);    if(retval == -1) {    usage();  }    s_id = -1;   #ifdef WIN32    if(WSAStartup(MAKEWORD(2, 2), &wsd) != 0) {    printf("WSAStartup() failed\n");        if(a.log_fd != -1) {      close(a.log_fd);    }        return -1;  }#endif    memset(ch_id, -1, MAX_CHANNELS_IN_SESSION);    if(a.alc_a.mode == SENDER) {        if(a.alc_a.calculate_session_size == true) {            sender_size = flute_sender_size(&a, &s_id, &ch_id[0]);      #ifdef WIN32      printf("Session size in bytes (including UDP/IP headers): %I64u\n", sender_size);#else      printf("Session size in bytes (including UDP/IP headers): %llu\n", sender_size);#endif            if(sender_size != 0) {		i = a.alc_a.nb_channel;		while(i) {	  	  retval = remove_alc_channel(s_id, ch_id[i - 1]);	  i--;	}	close_alc_session(s_id);      }      if(strcmp(a.sdp_file, "") != 0) {	sf_free(a.src_filt);	free(a.src_filt);	sdp_free(a.sdp);	free(a.sdp);      }      if(a.log_fd != -1) {	close(a.log_fd);      }#ifdef WIN32      WSACleanup();#endif      return 0;    }    else {      retval = flute_sender(&a, &s_id, &ch_id[0]);      #ifdef WIN32      printf("Total bytes sent: %I64u\n", get_session_sent_bytes(s_id));#else	        printf("Total bytes sent: %llu\n", get_session_sent_bytes(s_id));#endif      if(s_id == -1) {		if(strcmp(a.sdp_file, "") != 0) {	  sf_free(a.src_filt);	  free(a.src_filt);	  sdp_free(a.sdp);	  free(a.sdp);	}		if(a.log_fd != -1) {	  close(a.log_fd);	}	#ifdef WIN32	WSACleanup();#endif	return retval;      }            if(retval == -4) { /* bind failed */		if(strcmp(a.sdp_file, "") != 0) {	  sf_free(a.src_filt);	  free(a.src_filt);	  sdp_free(a.sdp);	  free(a.sdp);	}		if(a.log_fd != -1) {	  close(a.log_fd);	}	#ifdef WIN32	WSACleanup();#endif	return retval;	      }            if(retval != -1) {	if(a.alc_a.verbosity > 0) {	  printf("Sending session close packets\n");	  fflush(stdout);	}      }            while(a.alc_a.nb_channel) {		if(retval != -1) {	  	  if(a.alc_a.cc_id == Null) {	    	    for(i = 0; i < 3; i++) {	      retcode = send_session_close_packet(s_id, ch_id[a.alc_a.nb_channel - 1]);	      	      if(retcode == -1) {		break;	      }	    }#ifdef WIN32	    Sleep(500);#else	    usleep(500000);#endif	  }	  else if(a.alc_a.cc_id == RLC) {	    	    if(a.alc_a.nb_channel - 1 == 0) {	      	      for(i = 0; i < 3; i++) {		retcode = send_session_close_packet(s_id, ch_id[a.alc_a.nb_channel - 1]);				if(retcode == -1) {		  break;		}	      }#ifdef WIN32	      Sleep(500);#else	      usleep(500000);#endif	    }	  }	}		retcode = remove_alc_channel(s_id, ch_id[a.alc_a.nb_channel - 1]);	a.alc_a.nb_channel--;      }            close_alc_session(s_id);            if(strcmp(a.sdp_file, "") != 0) {	sf_free(a.src_filt);	free(a.src_filt);	sdp_free(a.sdp);	free(a.sdp);      }    }  }  else if(a.alc_a.mode == RECEIVER) {	      retval = flute_receiver(&a, &s_id, &ch_id[0], &fdt_th_args);        if(((retval == -1) && (s_id == -1))) {            if(strcmp(a.sdp_file, "") != 0) {	sf_free(a.src_filt);	free(a.src_filt);	sdp_free(a.sdp);	free(a.sdp);      }      if(a.log_fd != -1) {	close(a.log_fd);      }      #ifdef WIN32      WSACleanup();#endif      return retval;    }        if(retval == -2) {    }        if(retval == -3) {      if(a.alc_a.verbosity > 0) {	printf("Sender closed the session\n");	fflush(stdout);      }    }        if(retval == -4) { /* bind failed */            if(strcmp(a.sdp_file, "") != 0) {	sf_free(a.src_filt);	free(a.src_filt);	sdp_free(a.sdp);	free(a.sdp);      }            if(a.log_fd != -1) {	close(a.log_fd);      }      #ifdef WIN32      WSACleanup();#endif			      return retval;	    }        if(retval == -5) { /* Exiting in start time waiting period */      

⌨️ 快捷键说明

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