//Init network socket int network_init() { #ifndef _WIN32 //Init server UNIX signal(SIGPIPE, SIG_IGN); initServer(si_data, conf_port_data, &s_data); #else //Init server Winsock (Windows) WORD wVersionRequested; WSADATA wsaData; int err; /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) { /* Tell the user that we could not find a usable */ /* Winsock DLL. */ printf("WSAStartup failed with error: %d\n", err); return 1; } initServer(si_data, conf_port_data, &data_socket); #endif //Create thread to wait for connection if ( pthread_create(&wait_for_client_thread, NULL, waiting_for_client, NULL) ) { fprintf(stderr, "Error on pthread_create() for data\n"); return -1; } return 0; }
void t_chessGui::run() { chessCegui.init(); loadImages(); loadSprites(); initCegui(); initServer(); initConnect(); RedBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(255,0,0)); BlackBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(0,255,0)); BlueBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(0,0,255)); BrownBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(255,255,0)); PurpleBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(160,32,240)); PinkBox = sf::Shape::Rectangle(0,0,100,100,sf::Color(255,182,193)); while (App.IsOpened()) { processEvents(); checkBuffer(); App.Clear(); drawBoard(); CEGUI::System::getSingleton().renderGUI(); App.Display(); } return; }
int main(int argc, char *argv[]) { setupSingalHandler(); initServer(); startServer(); return 0; }
int main(int argc, char** argv) { signal(SIGABRT, &sighandler); signal(SIGTERM, &sighandler); signal(SIGINT, &sighandler); initServer(); aeEventLoop* eventLoop = aeCreateEventLoop(server.max_process_client + SHTTPSVR_EVENTLOOP_FDSET_INCR); server.el = eventLoop; int listen_socket = anetTcpServer(NULL, 80, NULL, server.tcp_backlog); anetNonBlock(NULL, listen_socket); if (listen_socket > 0 && AE_ERR == aeCreateFileEvent(eventLoop, listen_socket, AE_READABLE, tAcceptProc, NULL)) { ERRLOG("aeCreateFileEvent error!"); exit(1); } aeSetBeforeSleepProc(eventLoop, tBeforeSleepProc); initTimeEvent(eventLoop); aeMain(eventLoop); aeDeleteEventLoop(eventLoop); return 0; }
void initProgram(int argc, char ** argv, char ** envp) { cfg.argc = argc; cfg.argv = argv; cfg.envp = envp; cfg.help = 0; cfg.debug = 0; cfg.daemon = 0; cfg.version = 0; cfg.syslog = 0; cfg.port = 0; cfg.passkey = NULL; initOptions(); printDebug(); printHelp(); printVersion(); signal(SIGINT, mySignal); daemonize(); initLogging(); initServer(); }
int main(int argc, char **argv) { // Basic init FILE * hittite = fopen("/dev/hittite", "w+"); // Resetting GPIB bus fprintf(hittite, "*IDN?\n"); char id[1024]; efgets(id, 1023, hittite); printf("*IDN? : %s", id); char socketBuffer[1024]; int sockfd = initServer(atoi(argv[1])); while(1) { int clientfd = eaccept(sockfd); int ret = myRead( clientfd, socketBuffer, 1024 ); while( ret > 0 ) { printf("Received: %s\n", socketBuffer); handleRequest(socketBuffer, &clientfd, hittite); ret = myRead(clientfd, socketBuffer, 1024); } close(clientfd); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]){ if(argc < 3) { fprintf(stderr, "Please add drop and corrupt rates\n"); exit(0); } setRates(atoi(argv[1]), atoi(argv[2])); //begin cleint initServer(); printf("Server has begun.\n"); char buffer[PACKET_SIZE]; char testbuffer[PACKET_SIZE]; strcpy(testbuffer, "Testdatafromserver."); int n = 0; while(1){ //check for command comming in checkCommands(buffer); int rsend = (rand() % 100)+1; if(n == 0 && rsend > 95){ //n = dataLinkSend(testbuffer, strlen(testbuffer)); } } return(1); }
int main(int argc, char **argv) { time_t start; initServerConfig(); if (argc == 2) { resetServerSaveParams(); loadServerConfig(argv[1]); } if (server.daemonize) daemonize(); initServer(); linuxOvercommitMemoryWarning(); start = time(NULL); if (server.appendonly) { loadAppendOnlyFile(server.appendfilename); } else { rdbLoad(server.dbfilename); } aeSetBeforeSleepProc(server.el,beforeSleep); aeMain(server.el); aeDeleteEventLoop(server.el); return 0; }
bool CServerApp::startServer() { // skip if already started or starting if (s_serverState == kStarting || s_serverState == kStarted) { return true; } // initialize if necessary if (s_serverState != kInitialized) { if (!initServer()) { // hard initialization failure return false; } if (s_serverState == kInitializing) { // not ready to start s_serverState = kInitializingToStart; return true; } assert(s_serverState == kInitialized); } double retryTime; CClientListener* listener = NULL; try { listener = openClientListener(args().m_config->getSynergyAddress()); s_server = openServer(*args().m_config, s_primaryClient); s_listener = listener; updateStatus(); LOG((CLOG_NOTE "started server")); s_serverState = kStarted; return true; } catch (XSocketAddressInUse& e) { LOG((CLOG_WARN "cannot listen for clients: %s", e.what())); closeClientListener(listener); updateStatus(CString("cannot listen for clients: ") + e.what()); retryTime = 10.0; } catch (XBase& e) { LOG((CLOG_CRIT "failed to start server: %s", e.what())); closeClientListener(listener); return false; } if (args().m_restartable) { // install a timer and handler to retry later assert(s_timer == NULL); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); s_timer = EVENTQUEUE->newOneShotTimer(retryTime, NULL); EVENTQUEUE->adoptHandler(CEvent::kTimer, s_timer, new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler)); s_serverState = kStarting; return true; } else { // don't try again return false; } }
STDMETHODIMP IECrossfireBHO::SetSite(IUnknown* pUnkSite) { HRESULT hr = S_OK; if (pUnkSite) { if (m_webBrowser) { m_webBrowser->Release(); m_webBrowser = NULL; } hr = pUnkSite->QueryInterface(IID_IWebBrowser2, (void**)&m_webBrowser); if (FAILED(hr)) { Logger::error("IECrossfireBHO.SetSite(): QI(IWebBrowser2) failed", hr); } else { hr = DispEventAdvise(m_webBrowser); if (FAILED(hr)) { Logger::error("IECrossfireBHO.SetSite(): DispEventAdvise() failed", hr); } } initServer(false); } else { if (m_eventsHooked) { HRESULT hr = DispEventUnadvise(m_webBrowser); if (SUCCEEDED(hr)) { m_eventsHooked = false; } else { Logger::error("IECrossfireBHO.SetSite(): DispEventUnadvise() failed", hr); } } m_webBrowser->Release(); m_webBrowser = NULL; } //return IObjectWithSiteImpl<IECrossfireBHO>::SetSite(pUnkSite); return hr; }
int main(void){ int i, j; __sighandler_t ret; //JOINMsg joinMsg; initServer(); /* //test contents of AssignArr[] and LikeMatrix[][] for(i=0; i<MAXNUMCLIENTS; i++){ printf("AssignArr[%d] = %d ", i, AssignArr[i]); printf("LikeMatrix[%d]: ", i); for(j=0; j<MAXNUMCLIENTS; j++) printf("\"%c\", ", LikeMatrix[i][j]); printf("\n"); } */ printf("Press ^C to quit server process.\n"); ret = signal(SIGINT, signalHandler); if (ret == SIG_ERR){ fprintf(stderr,"Oops--SIGINT cannot be caught\n"); exit(1); } monitorJoinQueue(); return 0; }
int main(int argc, char* argv[]) { //get port from user if(argc < 2) { printf("usage: %s <port number>\n", argv[0]); return 1; } //Start Server if(!initServer(atoi(argv[1]))) return -1; listen(sockt, 5); clientLen = sizeof(cli_addr); while(1) { client = accept(sockt, (struct sockaddr*) &cli_addr, &clientLen); if(client < 0) printf("Failed to accept\n"); pid = fork(); if(pid == 0) { listenToClient(); printf("Client Disconected\n"); exit(0); } else { close(client); } } close(sockt); return 0; }
int main(int argc, const char *argv[]) { text[0] = '\0'; if (argc == 2) { if (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0) { help(argv[0]); return EXIT_SUCCESS; } else if (strcmp("-t", argv[1]) == 0) { text[0] = '1'; } else { int sock = initClient(); sendMessage(sock, argv[1]); close(sock); return EXIT_SUCCESS; } } else if (argc > 2) { help(argv[0]); return EXIT_FAILURE; } int sock = initServer(); pid_t pid = fork(); if (pid == 0) processMessages(sock); close(sock); return pid >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
WMTSI::WMTSI(const std::string& name, const std::string& cfgFile) : _name(name), data_process(DataProcess::getInstance()), iMutex(new IceUtil::Mutex()) { initServer(cfgFile); // 初始化TileEngine的数据源信息 std::cout << "WMTS servant 初始化成功" << std::endl; }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT resetCC3000StateMachine(); // Start CC3000 State Machine initDriver(); // Initialize Board and CC3000 unsolicicted_events_timer_init(); // Initialize CC3000 Unsolicited Events Timer __enable_interrupt(); // Enable interrupts for UART DefaultWifiConnection(); // Do a default connection while (1) { hci_unsolicited_event_handler(); // Handle any un-solicited event if required - the function shall be triggered few times in a second unsolicicted_events_timer_init(); if(currentCC3000State() & CC3000_IP_ALLOC) { turnLedOn(CC3000_IP_ALLOC_IND); unsolicicted_events_timer_disable(); // Attempt to start data server initServer(); if(currentCC3000State() & CC3000_SERVER_INIT) { waitForConnection(); } else//Wait for a bit, and try again. { __delay_cycles(100000); } unsolicicted_events_timer_init(); } } }
int startServer( appnetServer *serv ) { int sockfd[2]; int sock_count = 0; set_daemon( serv ); // memory alloc initServer( serv ); listenToPort( serv->listen_ip , serv->port , sockfd , &sock_count ); serv->listenfd = sockfd[0]; createWorkerProcess( serv ); createReactorThreads( serv ); __SLEEP_WAIT__; runMainReactor( serv ); destroyServer( serv ); __SLEEP_WAIT__; return 0; }
int main(int argc, char **argv) { initGlut(&argc, argv); initServer(&argc, argv); glutMainLoop(); // Loop forever return 0; }
void CServerApp::retryHandler(const CEvent&, void*) { // discard old timer assert(s_timer != NULL); stopRetryTimer(); // try initializing/starting the server again switch (s_serverState) { case kUninitialized: case kInitialized: case kStarted: assert(0 && "bad internal server state"); break; case kInitializing: LOG((CLOG_DEBUG1 "retry server initialization")); s_serverState = kUninitialized; if (!initServer()) { EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); } break; case kInitializingToStart: LOG((CLOG_DEBUG1 "retry server initialization")); s_serverState = kUninitialized; if (!initServer()) { EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); } else if (s_serverState == kInitialized) { LOG((CLOG_DEBUG1 "starting server")); if (!startServer()) { EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); } } break; case kStarting: LOG((CLOG_DEBUG1 "retry starting server")); s_serverState = kInitialized; if (!startServer()) { EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); } break; } }
bool init() { if (!isInit) { initServer(); isInit = InitMessageHeader(); } return isInit; }
void WebInterfacePlugin::load() { initServer(); pref = new WebInterfacePrefPage(this); getGUI()->addPrefPage(pref); }
int main(int argc, char** argv) { int status; char forking; message_t message; pid_t pid, cpid; ipc_t ipc; grid_t grid = gnew(); LOGPID("Using IPC method: %s.\n", IPC_METHOD); /* Before doing anything else, map data should be loaded! */ /* (so as to know the number of ants beforehand, at least */ if((status = loadGrid(grid, "configurationFile")) != NO_ERRORS) { printf("An error occurred while loading the configuration file\n"); exit(status); } /* This process will act as IPC server/simulation control */ sid = 1; /* Control has simulation ID 1 */ pid = getpid(); /* and it's pid, obviously */ LOGPID("Control process started.\n"); ipc = initServer(); /* Good! IPC server working. Let's spawn those ants. */ if (cpid = fork()) { /* Control code here */ int aux; if((aux = launchControl(ipc, grid)) != NO_ERROR){ printf("Simulation fail: %d\n", aux ); }else{ LOGPID("Simulation ended succesfully!\n"); } } else { /* Ants here */ do { sid++; pid = getpid(); ipc = initClient(); if (forking = (sid - 1 < grid->antsQuant)) forking = ((cpid = fork()) == 0); /* Child will keep forking */ } while (forking); /* We can do our own stuff now */ status = antLoop(ipc, grid); exit(status); } freeGrid(grid); }
void WebInterfacePlugin::load() { LogSystemManager::instance().registerSystem(i18n("Web Interface"), SYS_WEB); initServer(); pref = new WebInterfacePrefWidget(0); getGUI()->addPrefPage(pref); connect(getCore(), SIGNAL(settingsChanged()), this, SLOT(preferencesUpdated())); }
void onServerStatusChanged(GtkWidget *widget, gpointer data) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { initServer(); } else { closeServer(); } }
UDPServer::UDPServer(std::string multicastAddr, std::string multicastInterface, std::string port, ServerController *parent) : parent(parent), lastFileId(0) { if (initServer(multicastAddr, multicastInterface, port)) { logger::info << "Serwer UDP zostal uruchomiony.\n"; } else { logger::error << "Wystapil blad podczas uruchamiania serwera UDP.\n"; } }
bool CDaemon::start(){ //get daemon pid from file char buf[640]; int masterPid; string strName = m_runPath + daemon_pid_file; strName = strName + "." + m_pName; if ( 0<read1LineFromFile(strName.c_str(), buf, 64, "r") &&(masterPid = atoi(buf)) != 0){ if(kill(masterPid, 0) == 0){ printf("Instance's running, ready to quit!\n"); return true; } } initAsDaemon(); sprintf(buf, "%d", getpid()); if(!writeBuff2File(strName.c_str(), buf, "w")){ fprintf(stderr, "Write master pid fail!\n"); } while(true){//daemon fork and son do jobs pid_t pid = fork(); if (pid == 0){ signal(SIGUSR1, sigChildHandler); signal(SIGPIPE, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); if(!initServer()){ fprintf(stderr, "Server init fail!\n"); return false; } fprintf(stdout, "Server init ok pid = %d\n",(int)getpid()); if(!runServer()){ fprintf(stderr, "run fail!\n"); return false; } fprintf(stdout, "Server run ok!\n"); exit(0); } m_nChildPid=pid; int status; pid = wait(&status); if(!isAbnormalExit(pid, status)){ fprintf(stdout, "Child exit!\n"); break; } } return true; }
void IECrossfireBHO::onServerStateChanged(WPARAM wParam, LPARAM lParam) { m_serverState = wParam; initServer(false); /* If a connection was just established then create a context on the server for the current page */ if (m_serverState != STATE_CONNECTED) { return; } HRESULT hr = m_server->registerBrowser(GetCurrentProcessId(), this); if (FAILED(hr)) { Logger::error("IECrossfireBHO.onServerStateChanged(): registerBrowser() failed", hr); /* continue */ } CComBSTR url = NULL; hr = m_webBrowser->get_LocationURL(&url); if (FAILED(hr)) { Logger::error("IECrossfireBHO.onServerStateChanged(): get_LocationURL() failed", hr); return; } DWORD processId = GetCurrentProcessId(); DWORD threadId = GetCurrentThreadId(); hr = m_server->contextCreated(processId, threadId, url); if (FAILED(hr)) { Logger::error("IECrossfireBHO.onServerStateChanged(): contextCreated() failed", hr); return; } if (m_isCurrentContext) { hr = m_server->setCurrentContext(processId); if (FAILED(hr)) { Logger::error("IECrossfireBHO.onServerStateChanged(): setCurrentContext() failed", hr); } } /* * If the current page is fully-loaded then inform the server. If the current * page is still loading then the server will be notified of its completion * from the usual OnDocumentComplete listener. */ VARIANT_BOOL busy; hr = m_webBrowser->get_Busy(&busy); if (SUCCEEDED(hr) && !busy) { hr = m_server->contextLoaded(processId); if (FAILED(hr)) { Logger::error("IECrossfireBHO.onServerStateChanged(): contextLoaded() failed", hr); return; } } }
int main(void) { Server server; if (initServer(&server) < 0) { printf("ERROR: Can`t initialize server by \"%s\"\n", FILE_NAME); return -1; } return runServer(&server); return 0; }
void main(void) { /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); W5200_nRESET = 0; __delay_us(5); W5200_nRESET = 1; __delay_ms(50); __delay_ms(50); __delay_ms(50); __delay_ms(50); /* Initialize application settings */ InitSettings(); /* Initialize TCP server */ initServer(&macAddress, &gateway, &netmask); startServer(&localEndpoint); LED = 1; while(1) { if(clientConnected()) { if(dataAvailable()) { uint16_t length = getReceivedLength(); if(length > MAX_BUFFER) { // Limit maximum buffer size to avoid ram saturation due to packet flooding, a normal communication is shorter anyway length = MAX_BUFFER; } uint8_t buffer[MAX_BUFFER]; getReceivedData(buffer, length); parseCommand(buffer[0], buffer, length); stopServer(); startServer(&localEndpoint); } checkClientDisconnection(); } } }
void WebInterfacePlugin::preferencesUpdated() { if( http_server && http_server->port() != WebInterfacePluginSettings::port()) { //stop and delete http server bt::Globals::instance().getPortList().removePort(http_server->port(),net::TCP); delete http_server; http_server = 0; // reinitialize server initServer(); } }
int main(int argc, char **argv) { memset(&mserver, 0, sizeof server); memset(&sslServer, 0, sizeof sslServer); if (argc > 1) { mserver.port = atoi(argv[1]) + 1; sslServer.port = atoi(argv[1]); } else { mserver.port = MOCK_MEMCACHED_PORT; sslServer.port = MOCK_MEMCACHED_SSL_PORT; } if (argc > 2) { sslServer.ctx = CreateAndLoadContext(argv[2]); } //create a new thread for non ssl memcached port pthread_t serverProc, sslserverProc; initServer(&mserver); initServer(&sslServer); #if 0 int mserver_tid = 0; mserver_tid = pthread_create(&serverProc, NULL, (void *)&runServer, (void *) &mserver); if (mserver_tid) { fprintf(stderr, "Unable to create a new server thread"); } #endif int sslmserver_tid = 0; sslmserver_tid = pthread_create(&sslserverProc, NULL, (void *)&runServer, (void *) &sslServer); //pthread_join(serverProc, NULL); pthread_join(sslserverProc, NULL); return 0; }