Пример #1
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    int rc;
    
    user_data_t user_data = {
        .io_listen = -1,
        .io = -1,
        .control_io_listen = -1,
        .control_io = -1,
        .fio = NULL,
    };

    // user_context will be pointer to socket
    scpi_context.user_context = &user_data;
    
    SCPI_Init(&scpi_context);

    user_data.io_listen = createServer(5025);
    user_data.control_io_listen = createServer(CONTROL_PORT);
    
    while(1) {
        rc = waitServer(&user_data);
        
        if (rc < 0) { // failed
            perror("select failed");
            exit(-1);
        }
        
        if (rc == 0) { // timeout
            SCPI_Input(&scpi_context, NULL, 0);
        }
        
        if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) {
            processIoListen(&user_data);
        }

        if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) {
            processSrqIoListen(&user_data);
        }
        
        if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) {
            processIo(&user_data);
        }
        
        if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) {
            processSrqIo(&user_data);
        }
        
    }
    
    return (EXIT_SUCCESS);
}
Пример #2
0
    IClusterSPtr ServersManager::createCluster(IClusterSettingsBaseSPtr settings)
    {
        DCHECK(settings);

        IClusterSPtr cl;
        connectionTypes conT = settings->connectionType();
        if(conT == REDIS){
            IConnectionSettingsBaseSPtr root = settings->root();
            if(!root){
                return IClusterSPtr();
            }

            cl.reset(new RedisCluster(settings->connectionName()));
            IClusterSettingsBase::cluster_connection_type nodes = settings->nodes();
            for(int i = 0; i < nodes.size(); ++i){
                IConnectionSettingsBaseSPtr nd = nodes[i];
                if(nd){
                    IServerSPtr serv = createServer(nd);
                    cl->addServer(serv);
                }
            }
            IDriverSPtr drv = cl->root()->driver();
            DCHECK(drv->settings() == root);
        }
        else{
            NOTREACHED();
        }
        return cl;
    }
Пример #3
0
SimpleMenu::SimpleMenu(QWidget* parent, WelcomeScreen* screen)
: QObject(parent)
, m_screen(screen)
, m_protocol(0)
, m_state(READY)
, m_player1(0)
, m_player2(0)
{
    if (m_screen) {
        // create buttons
        m_server_btn = m_screen->addButton(0, 0, QIcon(QLatin1String(iconServer)),
                                           tr("Host Game"));
        m_client_btn = m_screen->addButton(0, 1, QIcon(QLatin1String(iconClient)),
                                           tr("Connect to Game"));

        // create connections
        connect(m_server_btn, SIGNAL(clicked()),
            this, SLOT(createServer()));
        connect(m_client_btn, SIGNAL(clicked()),
            this, SLOT(createClient()));

        // WiFi direct
        wpa = new Wpa;
        wpa->setEnabled(true);

        QVariantMap args;
        args["DeviceName"] = QHostInfo::localHostName();
        const char dev_type[8] = {0x00, 0x09, 0x00, 0x50, 0xf2, 0x04, 0x00, 0x05};
        args["PrimaryDeviceType"] = QByteArray(dev_type, 8);
        wpa->setProperties(args);
    }
}
Пример #4
0
abyss_bool
ServerCreateNoAccept(TServer *    const serverP,
                     const char * const name,
                     const char * const filesPath,
                     const char * const logFileName) {

    bool const noAcceptTrue = TRUE;
    bool const userChanSwitchFalse = FALSE;

    bool success;
    const char * error;

    createServer(&serverP->srvP, noAcceptTrue,
                 NULL, userChanSwitchFalse,
                 0, &error);

    if (error) {
        TraceMsg(error);
        success = FALSE;
        xmlrpc_strfree(error);
    } else {
        success = TRUE;
        
        setNamePathLog(serverP, name, filesPath, logFileName);
    }
    return success;
}
Пример #5
0
void IOToaster::setup()
{
	// Set the pin configuration
	setupPins();

	// Open serial communication
	Serial.begin(9600);
	Serial.setTimeout(5000);	

	// Load the configuration
	if (isConfigured())
	{
		// Normal mode
		_setupMode = false;
		loadConfiguration();	
		connectServer();
		setActivityLedState(HIGH);		
	}
		
	else {
		// Setup mode
		setActivityLedState(LOW);
		_setupMode = true;		
		createServer();
	}
}
Пример #6
0
abyss_bool
ServerCreateSocket(TServer *    const serverP,
                   const char * const name,
                   TOsSocket    const socketFd,
                   const char * const filesPath,
                   const char * const logFileName) {

    abyss_bool success;
    TSocket * socketP;

    createSocketFromOsSocket(socketFd, &socketP);

    if (socketP) {
        abyss_bool const noAcceptFalse = FALSE;

        const char * error;

        createServer(&serverP->srvP, noAcceptFalse, socketP, 0, &error);

        if (error) {
            TraceMsg(error);
            success = FALSE;
            xmlrpc_strfree(error);
        } else {
            success = TRUE;
            
            setNamePathLog(serverP, name, filesPath, logFileName);
        }
    } else
        success = FALSE;

    return success;
}
Пример #7
0
abyss_bool
ServerCreate(TServer *    const serverP,
             const char * const name,
             uint16_t     const portNumber,
             const char * const filesPath,
             const char * const logFileName) {

    abyss_bool const noAcceptFalse = FALSE;

    abyss_bool success;
    const char * error;

    createServer(&serverP->srvP, noAcceptFalse, NULL, portNumber, &error);

    if (error) {
        TraceMsg(error);
        xmlrpc_strfree(error);
        success = FALSE;
    } else {
        success = TRUE;
    
        setNamePathLog(serverP, name, filesPath, logFileName);
    }

    return success;
}
Пример #8
0
int main(void)
{
    char choose;
    int media;

    printf("[?]Launch server on port 1337 ? (y/n) ");
    scanf("%c" , &choose );

    printf("[?]Media player to control:\n");
    printf("[1]VLCPLayer\n");
    printf("[2]OMXPlayer\n");
    printf("[!]Choice: ");
    scanf("%d", &media );

    //Set the Media Player to controll
    setMediaPlayer( media );

    if( choose == 'y' )
    {
        printf("[+]Create server...\n");


        createServer();
    }
    else
    {
        return 0;
    }

    printf("\n");
    return 0;
}
Пример #9
0
static void scpi_server_thread(void *arg) {
    int rc;

    (void)arg;

    user_data.evtQueue = xQueueCreate(10, sizeof(uint32_t));
    
    // user_context will be pointer to socket
    scpi_context.user_context = &user_data;
    
    SCPI_Init(&scpi_context);

    user_data.io_listen = createServer(DEVICE_PORT);
    user_data.control_io_listen = createServer(CONTROL_PORT);
    
    while(1) {
        rc = waitServer(&user_data);
        
        if (rc < 0) { // failed
            iprintf("select failed");
            break;
        }

        if (rc == 0) { // timeout
            SCPI_Input(&scpi_context, NULL, 0);
        }        
        
        if ((user_data.io_listen != NULL) && (rc == SCPI_MSG_IO_LISTEN)) {
            processIoListen(&user_data);
        }

        if ((user_data.control_io_listen != NULL) && (rc == SCPI_MSG_CONTROL_IO_LISTEN)) {
            processSrqIoListen(&user_data);
        }
        
        if ((user_data.io != NULL) && (rc == SCPI_MSG_IO)) {
            processIo(&user_data);
        }
        
        if ((user_data.control_io != NULL) && (rc == SCPI_MSG_CONTROL_IO)) {
            processSrqIo(&user_data);
        }
        
    }
    
    vTaskDelete(NULL);
}
Пример #10
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    int rc;

    int listenfd;
    char smbuffer[10];

    // user_context will be pointer to socket
    scpi_context.user_context = NULL;

    SCPI_Init(&scpi_context);

    listenfd = createServer(5025);

    while (1) {
        int clifd;
        struct sockaddr_in cliaddr;
        socklen_t clilen;

        clilen = sizeof (cliaddr);
        clifd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);

        if (clifd < 0) continue;

        printf("Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr));

        scpi_context.user_context = &clifd;

        while (1) {
            rc = waitServer(clifd);
            if (rc < 0) { // failed
                perror("  recv() failed");
                break;
            }
            if (rc == 0) { // timeout
                SCPI_Input(&scpi_context, NULL, 0);
            }
            if (rc > 0) { // something to read
                rc = recv(clifd, smbuffer, sizeof (smbuffer), 0);
                if (rc < 0) {
                    if (errno != EWOULDBLOCK) {
                        perror("  recv() failed");
                        break;
                    }
                } else if (rc == 0) {
                    printf("Connection closed\r\n");
                    break;
                } else {
                    SCPI_Input(&scpi_context, smbuffer, rc);
                }
            }
        }

        close(clifd);
    }

    return (EXIT_SUCCESS);
}
/*!   Handler for Quit button
 *
 */
void GdbServerWindow::OnChangeSettings(wxCommandEvent& WXUNUSED(event)) {
   if (confirmDropConnection()) {
      closeServer();
      serverState = abort;
      doSettingsDialogue();
      createServer();
   }
}
Пример #12
0
ServerPtr ServerFactoryRegistry::createServer(const std::string &type,
                                              const std::string &address,
                                              uint16_t port,
                                              int numThreads) {
  auto factory = getInstance()->getFactory(type);
  ServerOptions options(address, port, numThreads);
  return factory->createServer(options);
}
Пример #13
0
 void start() {
     log() << "waiting for connections on port " << cmdLine.port << endl;
     //DbGridListener l(port);
     //l.listen();
     ShardedMessageHandler handler;
     MessageServer * server = createServer( cmdLine.port , &handler );
     server->run();
 }
Пример #14
0
int main(int argc, char* argv[]) {
	int local_port;
	char* local_interface;
	char* remote_host;
	int remote_port;
	int isClient = 0;

	if (argc < 3 || argc > 4) {
		perror("Error: improper number of args entered\nProper format: ./cs352proxy <port> <local_interface> or ./cs352proxy <remote_host> <remote_port> <local_interface>\n");
		return 0;
	} else if (argc == 3) {
		local_port = atoi(argv[1]);
		if (local_port < 1024 || local_port > 65536) {
			printf("port out of range\n");
			return 1;
		}
		local_interface = argv[2];
		isClient = 0;
	} else {
		remote_host = argv[1];
		remote_port = atoi(argv[2]);
		if (remote_port < 1024 || remote_port > 65536) {
			printf("port out of range\n");
			return 1;
		}
		local_interface = argv[3];
		isClient = 1;
	}

	if ( (tap_fd = allocate_tunnel(local_interface, IFF_TAP | IFF_NO_PI)) < 0) {
		perror("Opening tap interface failed! \n");
		exit(1);
	}

	int socketfd = socket(AF_INET, SOCK_STREAM, 0);
	if (socketfd < 0) {
		perror("Socket failed");
		exit(1);
	}

	if (!isClient) {
		TCPSocketfd = createServer(socketfd, local_port);
	} else {
		TCPSocketfd = createClient(socketfd, remote_port, remote_host);
	}

	pthread_t TAPthread, TCPthread;

	pthread_create(&TAPthread, NULL, TAPHandle, NULL);
	pthread_create(&TCPthread, NULL, TCPHandle, NULL);

 	pthread_join(TAPthread, NULL);
	pthread_join(TCPthread, NULL);

	return 0;
}
Пример #15
0
    void start( const MessageServer::Options& opts ) {
        balancer.go();
        cursorCache.startTimeoutThread();
        PeriodicTask::theRunner->go();

        ShardedMessageHandler handler;
        MessageServer * server = createServer( opts , &handler );
        server->setAsTimeTracker();
        server->run();
    }
USBDM_ErrorCode GdbServerWindow::execute(bool skipOpeningDialogue) {
   if (!skipOpeningDialogue) {
      doSettingsDialogue();
   }
   Show();

   createServer();

   return BDM_RC_OK;
}
Пример #17
0
Файл: main.c Проект: anjsxz/c
int main(void){
     const unsigned int serverPort = 0xC001;
     DiagnosticsServerPtr server = createServer(serverPort);
     if(NULL == server) {
        error("Failed to create the server");
}
     /* Enter the eternal reactive event loop. */
     for(;;){
        HandleEvents();
} }
Пример #18
0
void MainWindow::setupActions()
{
    KStandardGameAction::gameNew(m_main, SLOT(newGame()), actionCollection());
    KStandardGameAction::restart(m_main, SLOT(restart()), actionCollection());
    KStandardGameAction::highscores(m_main, SLOT(highscores()), actionCollection());
    
    KStandardGameAction::quit(this, SLOT(close()), actionCollection());
    
    QAction* action;
    action = new QAction(i18n("&Single Player"), this);
    action->setIcon(QIcon::fromTheme( QLatin1String( SimpleMenu::iconLocal)));
    actionCollection()->addAction("game_local", action);
    connect(action, SIGNAL(triggered()), m_main, SLOT(localGame()));
    action = new QAction(i18n("&Host Game..."), this);
    action->setIcon(QIcon::fromTheme( QLatin1String( SimpleMenu::iconServer)));
    actionCollection()->addAction("game_create_server", action);
    connect(action, SIGNAL(triggered()), m_main, SLOT(createServer()));
    action = new QAction(i18n("&Connect to Game..."), this);
    action->setIcon(QIcon::fromTheme( QLatin1String( SimpleMenu::iconClient))),
    actionCollection()->addAction("game_create_client", action);
    connect(action, SIGNAL(triggered()), m_main, SLOT(createClient()));
    // settings
    action = new QAction(i18n("Change &Nickname..."), this);
    actionCollection()->addAction("options_nickname", action);
    connect(action, SIGNAL(triggered()), m_main, SLOT(changeNick()));
    action = new KToggleAction(i18n("&Play Sounds"), this);
    actionCollection()->addAction("options_sounds", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleSounds(bool)));
    // This action will be disabled when a game is being run
    action = new KToggleAction(i18n("&Adjacent Ships"), this);
    action->setChecked(Settings::adjacentShips());
    actionCollection()->addAction("options_adjacent", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleAdjacent(bool)));
    // This action will be disabled when a game is being run
    action = new KToggleAction(i18n("&Multiple Ships"), this);
    action->setChecked(Settings::severalShips());
    actionCollection()->addAction("options_multiple_ships", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleMultiple(bool)));
    // config end of game message
    action = new KToggleAction(i18n("Show End-of-Game Message"), this);
    action->setChecked(true);
    actionCollection()->addAction("options_show_endgame_message", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleEndOfGameMessage(bool)));
    // actions for grid
    action = new KToggleAction(i18n("Show &Left Grid"), this);
    action->setChecked(true);
    actionCollection()->addAction("options_showleftgrid", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleLeftGrid(bool)));
    action = new KToggleAction(i18n("Show &Right Grid"), this);
    action->setChecked(true);
    actionCollection()->addAction("options_showrightgrid", action);
    connect(action, SIGNAL(triggered(bool)), m_main, SLOT(toggleRightGrid(bool)));
    
    setupGUI();
}
Пример #19
0
void
ServerCreateSocket2(TServer *     const serverP,
                    TSocket *     const socketP,
                    const char ** const errorP) {
    
    abyss_bool const noAcceptFalse = FALSE;

    assert(socketP);

    createServer(&serverP->srvP, noAcceptFalse, socketP, 0, errorP);
}
Пример #20
0
    void start( const MessageServer::Options& opts ) {
        setThreadName( "mongosMain" );
        installChunkShardVersioning();
        balancer.go();
        cursorCache.startTimeoutThread();
        PeriodicTask::theRunner->go();

        ShardedMessageHandler handler;
        MessageServer * server = createServer( opts , &handler );
        server->setAsTimeTracker();
        server->run();
    }
Пример #21
0
int main(void)
{
	int serverSockFd;
	int clientSockFd;
	struct sockaddr_in clientAddr;
	unsigned int addrLen;
	char addrBuff[20];
	pthread_t tId;

	
	if(pthread_mutex_init(&mutex, 0)) {
		perror("mutex");
		exit(0);
	} else {
		puts("Mutex Setting");
	}

	srand(time(0)); // Rand Port를 생성하려고

	serverSockFd = createServer(SERVER_PORT);
	puts("Waiting Client.....");

	while(1) {
		addrLen = sizeof(clientAddr);
		clientSockFd = accept(serverSockFd, (struct sockaddr*)&clientAddr, &addrLen);

		if(clientSockFd == -1) {
			perror("accept");
		}

		inet_ntop(AF_INET, &clientAddr.sin_addr.s_addr, addrBuff, sizeof(addrBuff));
		printf("Connected IP: %s\n", addrBuff);

		pthread_mutex_lock(&mutex);
		accessUserArr[accessUserNum++].fd = clientSockFd;
		
		LOG(
			int i;
			for(i=0; i<accessUserNum; i++) {
				printf("%d ", accessUserArr[i].fd);
			}
			puts("");
		)

		pthread_mutex_unlock(&mutex);

		if(pthread_create(&tId, 0, connectClient, &clientSockFd) != 0) {
			perror("thread create");
		}
		//pthread_detach(tId);    // 독립적인 자원관리
	}
Пример #22
0
    void start( const MessageServer::Options& opts ){
        setThreadName( "mongosMain" );
        installChunkShardVersioning();
        balancer.go();
        cursorCache.startTimeoutThread();

        log() << "waiting for connections on port " << cmdLine.port << endl;
        //DbGridListener l(port);
        //l.listen();
        ShardedMessageHandler handler;
        MessageServer * server = createServer( opts , &handler );
        server->setAsTimeTracker();
        server->run();
    }
Пример #23
0
    void start( const MessageServer::Options& opts ) {
        balancer.go();
        cursorCache.startTimeoutThread();
        UserCacheInvalidator cacheInvalidatorThread(getGlobalAuthorizationManager());
        cacheInvalidatorThread.go();

        PeriodicTask::startRunningPeriodicTasks();

        ShardedMessageHandler handler;
        MessageServer * server = createServer( opts , &handler );
        server->setAsTimeTracker();
        server->setupSockets();
        server->run();
    }
Пример #24
0
void
ServerCreateSwitch(TServer *     const serverP,
                   TChanSwitch * const chanSwitchP,
                   const char ** const errorP) {
    
    bool const noAcceptFalse = FALSE;
    bool const userChanSwitchTrue = TRUE;

    assert(serverP);
    assert(chanSwitchP);

    createServer(&serverP->srvP, noAcceptFalse,
                 chanSwitchP, userChanSwitchTrue,
                 0, errorP);
}
Пример #25
0
	void start()
	{
		QCoreApplication *app = application();
		
		QServer* tcpServer = createServer();
		if (tcpServer)
		{
			tcpServer->listen();

			if (!tcpServer->isListening()) {
				logMessage(QString("Failed to bind to port %1").arg(tcpServer->serverPort()), QtServiceBase::Error);
				app->quit();
			}
		}
	}	
Пример #26
0
/**
 * @brief Start listening on the specified address.
 * @param port the port to listen on
 * @param address listening address
 * @return true on success
 */
bool MultiServer::start(quint16 port, const QHostAddress& address) {
	Q_ASSERT(_state == NOT_STARTED);
	_state = RUNNING;
	if(!createServer())
		return false;

	if(!_server->listen(address, port)) {
		logger::error() << _server->errorString();
		delete _server;
		_server = 0;
		_state = NOT_STARTED;
		return false;
	}

	logger::info() << "Started listening on port" << port << "at address" << address.toString();
	return true;
}
Пример #27
0
int main(int argc, char *argv[]) {
	uint32_t clilen;
	uint8_t gpioOutputPortLight1;
	uint8_t gpioOutputPortLight2;
	int clientSocket, portno;
	int sockfd;
	struct sockaddr_in cli_addr;

	// If there are no enough parameters, abort.
	if (argc < 4) {
		fprintf(stderr,
				"ERROR, provide args: port number, pin for light 1, pin for light 2\n");
		exit(1);
	}
	portno = atoi(argv[1]);
	gpioOutputPortLight1 = atoi(argv[2]);
	gpioOutputPortLight2 = atoi(argv[3]);

	setupGpioOutput(gpioOutputPortLight1);
	setupGpioOutput(gpioOutputPortLight2);
	// Create a socket.
	sockfd = createServer(portno);

	clilen = sizeof(cli_addr);
	while (1) {
		fprintf(stderr, "Waiting for client...\n");
		// Block until a client has connected to the server.  This returns a file descriptor for the connection.
		clientSocket = accept(sockfd, (struct sockaddr*) &cli_addr, &clilen);

		// If the return is less than 0l, there is an error.
		if (clientSocket < 0) {
			error("ERROR on accept");
		} else {
			fprintf(stderr, "Client connected\n");
			startThreadForClient(clientSocket, gpioOutputPortLight1,
					gpioOutputPortLight2);
		}

		sleep(1);
	}

	gpio_unexport(gpioOutputPortLight1);
	gpio_unexport(gpioOutputPortLight2);
	return 0;
}
Пример #28
0
    void listen(int port) {
        //testTheDb();
        MessageServer::Options options;
        options.port = port;
        options.ipList = cmdLine.bind_ip;

        MessageServer * server = createServer( options , new MyMessageHandler() );
        server->setAsTimeTracker();

        startReplication();
        if ( !noHttpInterface )
            boost::thread web( boost::bind(&webServerThread, new RestAdminAccess() /* takes ownership */));

#if(TESTEXHAUST)
        boost::thread thr(testExhaust);
#endif
        server->run();
    }
Пример #29
0
/**
 * @brief Start listening on the given file descriptor
 * @param fd
 * @return true on success
 */
bool MultiServer::startFd(int fd)
{
	Q_ASSERT(_state == NOT_STARTED);
	_state = RUNNING;
	if(!createServer())
		return false;

	if(!_server->setSocketDescriptor(fd)) {
		logger::error() << "Couldn't set server socket descriptor!";
		delete _server;
		_server = 0;
		_state = NOT_STARTED;
		return false;
	}

	logger::info() << "Started listening on passed socket";
	return true;
}
Пример #30
0
int main(int argc, char **argv)
{
	int i;
	scanf("%d",&i);
	int portno;
	scanf("%d", &portno);
	
	if( i==0)
	{
		createServer(portno);
		game(argc, argv , 0);
	}
	else
	{
		createClient(portno , "ubuntu");
		game(argc, argv , 1);
	}
}