bool AgarServer::setupAndRun() { if(setupSimulation() && setupNetworking()){ simThread->start(); return true; } return false; }
int main( int argc, char **argv) { const char *multicastAddress = "236.0.0.1"; const char *multicastPort = "3636"; const char *multicastInterface = "127.0.0.1"; // Handle options for(;;) { int optionIndex = 0; static struct option options[] = { { "verbose", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' }, { "frequency", required_argument, 0, 'f' }, { "multicast-address", required_argument, 0, 'a'}, { "multicast-port", required_argument, 0, 'p' }, { "multicast-interface", required_argument, 0, 'i' }, { "min-packet", required_argument, 0, 'm' }, { "read-file", required_argument, 0, 'r' }, { "histogram", no_argument, 0, 'H' }, { "modes", no_argument, 0, 'M' }, { 0,0,0,0} }; int c = getopt_long( argc, argv, "vh?HMf:a:p:i:m:r:", options, &optionIndex ); if ( c == -1) break; switch(c) { case 'h': case '?': showHelp(stdout); return 0; case 'v': verbose = 1; break; case 'H': showHistogram = 1; break; case 'M': showModes = 1; break; case 'f': // set frequency to optarg { unsigned f = atoi( optarg); if (f==0) { fprintf(stderr,"Bad frequency: %s\n", optarg); exit(1); } centerFrequency = f; } break; case 'm': minPacket = atoi(optarg); break; case 'a': multicastAddress = optarg; break; case 'i': multicastInterface = optarg; break; case 'p': multicastPort = optarg; break; case 'r': inputFileName = optarg; break; default: fprintf(stderr,"Illegal option\n"); showHelp(stderr); exit(1); } } setupNetworking(multicastAddress, multicastPort, multicastInterface); signal(SIGINT, exitNicely); if ( inputFileName == 0) { struct rtldev *rtl = rtlOpen(NULL,0); if ( !rtl) { fprintf(stderr,"Failed to open RTL SDR device\n"); exit(1); } if ( rtlSetup( rtl, centerFrequency, sampleRate) < 0) { fprintf(stderr,"Failed to setup RTL SDR for %uHz %usamp/sec\n", centerFrequency, sampleRate); } // something must call rtlStop(rtl) to kill this, to this end we stash in a global, ick rtlToStop = rtl; if ( rtlRun( rtl, iqHandler, 0)) { fprintf(stderr, "Failed to run iqHandler\n"); } rtlToStop = 0; rtlClose(rtl); } else { FILE *in = fopen( inputFileName, "r"); if ( !in) { fprintf(stderr, "Failed to open input file '%s': %s\n", inputFileName, strerror(errno)); exit(1); } for(;;) { unsigned char buf[16384]; size_t got = fread( buf, 1, sizeof(buf), in); if ( got == 0 && feof(in)) break; if ( got == 0) { fprintf(stderr, "Error while reading input file: %s\n", strerror(errno)); exit(1); } iqHandler( buf, got, 0, 0); } fclose(in); } // // the rest of this is just in case someone is running a leak detector on us. // if ( multicastSocket != -1) { close(multicastSocket); multicastSocket = -1; } if ( multicastSockaddr) { free(multicastSockaddr); multicastSockaddr = 0; multicastSockaddrLen = 0; } return 0; }