void PaloLoader::load(bool autoLoadDb, bool autoAddDb) { loadServer(); // add any new database found in the path if (autoLoadDb && autoAddDb) { addNewDatabases(); } // autoload other databases if (autoLoadDb) { autoLoadDatabases(); } }
int main(int argc, char **argv) { ServerConfig config; if (argc != 2) { //printf("Usage: %s {ConfigFileName}", argv[0]); //exit(1); printf("Read config file from default path...\n"); config = loadServer("/etc/multiswitch/server.ini"); } else config = loadServer(argv[1]); printf("This is a UDP server, I will received message from client and reply with same message\n"); totalLinkNum = config.linkCount; initMemory(); init_sock_s(0, config.receivePort);//init the Socket and addr init_sock_local("127.0.0.1", config.localForwardPort); //printf("Socket init....finish\n"); //srand(time(NULL)); currLinkNow = 0; Maxtot = 0; pthread_t pt_f; pthread_create(&pt_f, NULL, ForwardUDP, NULL); fd_set inputs; char buff[BUFFLENGTH]; while (true) { FD_ZERO(&inputs); FD_SET(Socket[0], &inputs); int result = select(FD_SETSIZE, &inputs, NULL, NULL, NULL); //wait until some messages arrive if (result <= 0)continue; if (FD_ISSET(Socket[0], &inputs)) { int msglen = Recvfrom(0, buff); printf("%s %u says: %s\n", inet_ntoa(RecvAddr[0].sin_addr), ntohs(RecvAddr[0].sin_port), buff); int pi, LinkNow_c; pi = buff[0] - '0'; LinkNow_c = buff[1] - '0'; if (pi < 0 || pi > totalLinkNum - 1 || LinkNow_c < 0 || LinkNow_c > totalLinkNum) { printf("Invalid package.\n"); continue; } UpdateAddr(&SendAddr[pi], &RecvAddr[0]);//update destination address of this link if (buff[1] == '0' + totalLinkNum)// if the packet is a data packet, not a test packet. { printf("!!receive UDP data packet from client!: \n"); SendToLocal(&buff[2], msglen - 2); continue; } //for debug, sleep to simulate net delay //int WaitTime = rand()%400; //usleep(WaitTime * 1000); SendToClient(pi, buff, msglen);//send msg printf("sent: %s\n", buff); long long tot; sscanf(&buff[2], "%lld", &tot); if (tot > Maxtot || (Maxtot - tot) > MAXMINUS) { Maxtot = tot; if (LinkNow_c != currLinkNow) { ChangeNet(LinkNow_c); } } } } }