void PortSpace::Release(const Value_t port)
{
	if(port < min_ || port > max_ || IsUsed(port) == false)
		return;

	setPort(port, false);
}
示例#2
0
/// read preference table from sql
void preferences::readDB(){

    if(QFile::exists(DBlocation.c_str())){
        db2 = QSqlDatabase::addDatabase("QSQLITE");
        db2.setDatabaseName(DBlocation.c_str());
        if(db2.open()){
            QSqlQuery query(db2);

            query = QString("SELECT * FROM pref");

            while (query.next()){
                QString QVal1 = query.value(1).toString();
                QString QVal2 = query.value(2).toString();
                QString QVal3 = query.value(3).toString();
                QString QVal4 = query.value(4).toString();
                QString QVal5 = query.value(5).toString();
                QString QVal6 = query.value(6).toString();


                setUser(QVal1.toStdString());
                setPass(QVal2.toStdString());
                setServ(QVal3.toStdString());
                setPort(QVal4.toStdString());
                setTable(QVal5.toStdString());
                setSQL(QVal6.toStdString());
            }
        }

        db2.removeDatabase("QSQLITE");
    }

}
示例#3
0
void HttpRequest::setUrl(const HttpUrl &url)
{
	m_rawurl = url.getPath();
	m_extra = url.getParams();
	setHost(url.getHost());
	setPort(url.getPort());
}
void PortSpace::Use(const Value_t port)
{
	if(IsUsed(port))
		throw UnavailablePortError(port, *this);

	setPort(port, true);
}
示例#5
0
// Parameter-Konstruktor
CDatabase_Connection::CDatabase_Connection(string user, string password, string DB, string Host, int Port)
{
    try
    {
        mysql_init(&my);
        LoadDefaults();
        setUsername(user);
        setPassword(password);
        setDB(DB);
        setHost(Host);
        setPort(Port);

        this->connected = false;
        this->initialised = false;



    }
    catch(...)
    {
		cerr << "An unexpected error occured in function 'Default-Constructor'!" << endl;
    }


}
void CSensorUSBMotionNodeAccel::closePort()
{
    if (getPort() > -1) {
        fprintf(stdout, "Closing %s sensor port...\n", getTypeStr());
    }
    if (m_node) {
        if (m_node->is_connected() && m_node->is_reading()) {
           m_node->stop();  // if started & reading
        }
        m_node->close();
        delete m_node;
        m_node = NULL;
        setPort();
        setType();
        if (getPort() > -1) {
           fprintf(stdout, "Port closed!\n");
           fflush(stdout);
        }
    }

    // close MN dll
    if (m_WinDLLHandle) {
#ifdef __USE_DLOPEN__
        if (dlclose(m_WinDLLHandle)) {
           fprintf(stderr, "%s: dlclose error %s\n", getTypeStr(), dlerror());
        }
#else // probably Windows - free library
   #ifdef _WIN32
        ::FreeLibrary(m_WinDLLHandle);
   #endif
#endif
	m_WinDLLHandle = NULL;
    }
}
示例#7
0
void SocketAddress::set(const char* hostname, int family, uint16_t port)
		throw (UnknownHostException)
{
	int addrLen = 0;

	MX_ASSERT(NULL != hostname);

	if (AF_UNSPEC == family)
	{
		if (!getAddrInfo(hostname, AF_INET6, &data_, &addrLen) && !getAddrInfo(
				hostname, AF_INET, &data_, &addrLen))
		{
			THROW2(UnknownHostException, std::string("Unknown hostname: [") + hostname + "]");
		}
	}
	else
	{
		if (!getAddrInfo(hostname, family, &data_, &addrLen))
		{
			THROW2(UnknownHostException, std::string("Unknown hostname: [") + hostname + "]");
		}
	}

	setPort(port);
}
示例#8
0
bool IPEndPoint::parse(sal_in_z const char* addressAndPort)
{
	std::string str(addressAndPort);

	// Get position of colon
	size_t pos = str.find(":");

	if (pos != std::string::npos) {
		std::string strIP = str.substr(0, pos);
		if(!mAddress.parse(strIP.c_str()))
			return false;

		// Check existence of port number after colon
		if (str.length() > pos+1) {
			int port;
			if(str2Int(str.substr(pos+1).c_str(), port))
				setPort(uint16_t(port));
			else
				return false;
		}
	} else {
		return mAddress.parse(addressAndPort);
	}

	return true;
}
 int SimpleRedisClient::redis_conect(const char* Host,int Port, int TimeOut)
 {
     setPort(Port);
     setHost(Host);
     setTimeout(TimeOut);
     return redis_conect();
 }
示例#10
0
ChatServer::ChatServer(qint16 port, QObject *parent) :
    QObject(parent)
{
    ConnectionList = new QList<ChatConnection*>();
    setPort(port);
    bActive = false;
}
示例#11
0
void TreadmillFB303::make_fb303(
    std::shared_ptr<std::thread>& server_thread,
    int server_port,
    Scheduler& scheduler) {
  {
    folly::SharedMutex::WriteHolder guard(instance_mutex);
    if (instance) {
      LOG(FATAL) << "Global Treadmill FB303 instance was already set";
    }
    instance = std::make_shared<TreadmillFB303>(scheduler);
  }

  auto server = std::make_shared<apache::thrift::ThriftServer>();
  LOG(INFO) << "FB303 running on port " << server_port;
  server->setPort(server_port);
  server->setInterface(getGlobalTreadmillFB303());
  TLSConfig::applyDefaultsToThriftServer(*server);
  server_thread.reset(
      new std::thread([server]() { server->serve(); }),
      [server](std::thread* t) {
        server->stop();
        t->join();
        delete t;
      });
}
示例#12
0
//Konstruktoren
ChatServer::ChatServer(QObject *parent) :
    QObject(parent)
{
    ConnectionList = new QList<ChatConnection*>();
    setPort(2342);
    bActive = false;
}
示例#13
0
void CSensorAndroidBuiltIn::closePort()
{
    if (m_pSensor && m_pSensorEventQueue) {
        ASensorEventQueue_disableSensor(m_pSensorEventQueue, m_pSensor);
    }
    if (m_pSensorManager && m_pSensorEventQueue) {
        ASensorManager_destroyEventQueue(m_pSensorManager, m_pSensorEventQueue);
    }

    strcpy(m_strVendor, "");
    strcpy(m_strSensor, "");

    m_pSensorManager = NULL;
    m_pSensor = NULL;
    m_pSensorEventQueue = NULL;
    m_pLooper = NULL;

    m_fResolution = 0.0f;
    m_minDelayMsec = 0;

    memset(m_xyz, 0x00, sizeof(float) * 3);
    memset(m_strSensor, 0x00, _MAX_PATH);
    memset(m_strVendor, 0x00, _MAX_PATH);

    setType();
    setPort();

}
示例#14
0
HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& socket, Session::Ptr pSession):
	HTTPClientSession(socket),
	_pContext(socket.context()),
	_pSession(pSession)
{
	setPort(HTTPS_PORT);
}
示例#15
0
bool EClientSocket::eConnect( const char *host, unsigned int port, int clientId, bool extraAuth)
{
	if( m_fd == -2) {
		getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg());
		return false;
	}

	// reset errno
	errno = 0;

	// already connected?
	if( m_fd >= 0) {
		errno = EISCONN;
		getWrapper()->error( NO_VALID_ID, ALREADY_CONNECTED.code(), ALREADY_CONNECTED.msg());
		return false;
	}

	// normalize host
	m_hostNorm = (host && *host) ? host : "127.0.0.1";

	// initialize host and port
	setHost( m_hostNorm);
	setPort( port);

	// try to connect to specified host and port
	ConnState resState = CS_DISCONNECTED;
	
    return eConnectImpl( clientId, extraAuth, &resState);
}
示例#16
0
void Ipv4SocketAddress::setAddress(std::string const& addr) {
  if (addr.empty()) {
    pImpl_->ipv4address.sin_addr.s_addr = htonl(INADDR_ANY);
  } else {
    struct addrinfo addrhints;
    struct addrinfo *res;
    int err;
    memset(&addrhints, 0, sizeof(addrhints));

    if ((err = getaddrinfo(addr.c_str(), NULL, &addrhints, &res)) != 0) {
      std::cerr << "SocketAddress::setAddress(): Error in socket address translation for " << addr << ": " <<  gai_strerror(err) << std::endl;
    } else {
      if (res->ai_canonname)
        std::cerr << "Canonical name of socket: " << res->ai_canonname << std::endl;

      switch (res->ai_family) {
        case AF_INET:
          memcpy(&pImpl_->ipv4address, res->ai_addr, sizeof(pImpl_->ipv4address));
          setPort(port()); // Fix port in sockaddr
        break;
        default:
          std::cerr << "SocketAddress::setAddress(): Socket addresses other than ipv4 not supported!" << std::endl;
        break;
      }
      freeaddrinfo(res);
    }
  }
}
示例#17
0
STDMETHODIMP HostUSBDeviceFilterWrap::COMSETTER(Port)(IN_BSTR aPort)
{
    LogRelFlow(("{%p} %s: enter aPort=%ls\n", this, "HostUSBDeviceFilter::setPort", aPort));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = setPort(BSTRInConverter(aPort).str());
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave hrc=%Rhrc\n", this, "HostUSBDeviceFilter::setPort", hrc));
    return hrc;
}
示例#18
0
/*!
 * Standard constructor using \a parent as parent
 */
LogReceiver::LogReceiver(QObject *parent) :
    QObject(parent),
    m_socket(new QUdpSocket(this))
{
    setPort(45454);
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
}
示例#19
0
文件: server.cpp 项目: fagg/nutmeg
void Server::start()
{
    int findingPort = 50;
    while (findingPort) {
        try {
            startServer();
            setRunning(true);
            findingPort = 0;
            qDebug() << "Connected to port" << m_port;
            if (m_mainWindow) {
                m_mainWindow->notify("Server Started", "Port set to " + QString::number(m_port));
            }
        }
        catch (const nzmqt::ZMQException& ex) {
            if (ex.num() == 48) {
                findingPort--;
                setPort(m_port + 1);
            } else {
                qWarning() << Q_FUNC_INFO << "Exception:" << ex.num() << ex.what();
                findingPort = 0;
                emit failure(ex.what());
                emit finished();
            }
        }
    }
}
示例#20
0
u_result SocketAddress::setAddressFromString(const char * address_string,  SocketAddress::address_type_t type)
{
    int ans = 0;
    int prevPort = getPort();
    switch (type) {
        case ADDRESS_TYPE_INET:
            reinterpret_cast<sockaddr_storage *>(_platform_data)->ss_family = AF_INET;
            ans = _inet_pton(AF_INET, 
                            address_string, 
                            &reinterpret_cast<sockaddr_in *>(_platform_data)->sin_addr);
        break;


        case ADDRESS_TYPE_INET6:
            
            reinterpret_cast<sockaddr_storage *>(_platform_data)->ss_family = AF_INET6;
            ans = _inet_pton(AF_INET6, 
                            address_string, 
                            &reinterpret_cast<sockaddr_in6  *>(_platform_data)->sin6_addr);
        break;

        default:
            return RESULT_INVALID_DATA;

    }
    setPort(prevPort);

    return ans<=0?RESULT_INVALID_DATA:RESULT_OK;
}
示例#21
0
void SocketAddress::setAnyAddress(SocketAddress::address_type_t type)
{
    int prevPort = getPort();
    switch (type) {
        case ADDRESS_TYPE_INET:
            {
                sockaddr_in * addrv4 = reinterpret_cast<sockaddr_in *>(_platform_data);
                addrv4->sin_family = AF_INET;
                addrv4->sin_addr.s_addr = htonl(INADDR_ANY);
            }
            break;
        case ADDRESS_TYPE_INET6:
            {
                sockaddr_in6  * addrv6 = reinterpret_cast<sockaddr_in6  *>(_platform_data);
                addrv6->sin6_family = AF_INET6;
                addrv6->sin6_addr = in6addr_any;

            }
            break;
        default:
            return;
    }

    setPort(prevPort);


}
示例#22
0
UnixClient::UnixClient() {
	char * localhost = new char[10];
	strcpy(localhost, "127.0.0.1");
	setIP(localhost);
	setPort(12345);
	setLogStream(&std::cout);
}
示例#23
0
FileServer::FileServer()
{
    setPort(uHTTP::HTTP::DEFAULT_PORT);
    setRootDirectory(".");
    setVerbose(false);
    addRequestListener(this);
}
示例#24
0
文件: chatbox.cpp 项目: jesyspa/4DGo
void Chatbox::parseString(QString str) {
	if (str[0] != '!') {
		emit message(str);
		return;
	}
	str[0] = ' ';
	str = str.trimmed().toLower();
	QStringList list = str.split(QRegExp("\\s+"));
	QStringList::const_iterator it = list.begin();
	if (it->contains(rgxPos)) {
		emit playStone(Position(*it));
	} else if (*it == "pass" || *it == "p") {
		emit pass();
	} else if (*it == "undo" || *it == "u") {
		emit undo();
	} else if (*it == "kill" || *it == "k") {
		if (++it == list.end() || !it->contains(rgxPos))
			display("Expected position as second argument.");
		else
			emit kill(Position(*it));
	} else if (*it == "exit" || *it == "e") {
		emit exit();
	} else if (*it == "connect" || *it == "c") {
		if (++it != list.end()) {
			emit setHost(*it);
			if (++it != list.end()) {
				emit setPort(it->toInt());
			}
		}
		emit cl_connect();
	} else if (*it == "disconnect" || *it == "dc") {
		emit cl_disconnect();
	} else if (*it == "yes" || *it == "y") {
		emit confirm(true);
	} else if (*it == "no" || *it == "n") {
		emit confirm(false);
	} else if (*it == "save" || *it == "s") {
		if (++it == list.end())
			display("Expected filename as second argument.");
		else
			emit writeLogToDisk(*it);
	} else if (*it == "help" || *it == "h" ) {
		display("4DGo -- A four-dimensional goban for online play.");
		display("All commands start with a '!'. Any input that does not is treated as a chat message. All comands are case-insensitive.");
		display("  Commands:");
		display("!connect [hostname] [port]: connect to the game server. By default, localhost:15493 will be used.");
		display("!disconnect: break connection to server and clear the goban.");
		display("!A4d4: on slice A4 (top-left), on intersection d4 (top-right).");
		display("!pass: end your turn without playing a stone.");
		display("!undo: request that your last move be undone.");
		display("!yes: allow the action your opponent requested (usually an undo or kill).");
		display("!yes: refuse to allow the action your opponent requested (usually an undo or kill).");
		display("!kill: request a certain group to be immediately taken off the board. Useful in endgame, to not need to play out all captures.");
		display("!save filename: save the current history to file filename.");
		display("!exit: disconnect and close the window.");
	} else {
		tbCBox_->append(QString("Unknown command: ")+*it);
	}
}
示例#25
0
// config vars have changed
void ConnectionDialog::updateConfig()
{
    setURL( serverURL );
    setPort( serverPort );
    setNick( userNick );
    ui->serverCombo->clear();
    ui->serverCombo->addItems( serverList );
}
示例#26
0
HTTPSClientSession::HTTPSClientSession(const std::string& host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession):
	HTTPClientSession(SecureStreamSocket(pContext, pSession)),
	_pContext(pContext),
	_pSession(pSession)
{
	setHost(host);
	setPort(port);
}
示例#27
0
void MaemoDebugSupport::startExecution()
{
    if (m_state == Inactive)
        return;

    ASSERT_STATE(StartingRunner);

    if (!useGdb() && m_debuggingType != RemoteLinuxRunConfiguration::DebugQmlOnly) {
        if (!setPort(m_gdbServerPort))
            return;
    }
    if (m_debuggingType != RemoteLinuxRunConfiguration::DebugCppOnly) {
        if (!setPort(m_qmlPort))
            return;
    }

    if (useGdb()) {
        handleAdapterSetupDone();
        return;
    }

    setState(StartingRemoteProcess);
    m_gdbserverOutput.clear();
    connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this,
        SLOT(handleRemoteErrorOutput(QByteArray)));
    connect(m_runner, SIGNAL(remoteOutput(QByteArray)), this,
        SLOT(handleRemoteOutput(QByteArray)));
    if (m_debuggingType == RemoteLinuxRunConfiguration::DebugQmlOnly) {
        connect(m_runner, SIGNAL(remoteProcessStarted()),
            SLOT(handleRemoteProcessStarted()));
    }
    const QString &remoteExe = m_runner->remoteExecutable();
    QString args = m_runner->arguments();
    if (m_debuggingType != RemoteLinuxRunConfiguration::DebugCppOnly) {
        args += QString(QLatin1String(" -qmljsdebugger=port:%1,block"))
            .arg(m_qmlPort);
    }

    const QString remoteCommandLine = m_debuggingType == RemoteLinuxRunConfiguration::DebugQmlOnly
        ? QString::fromLocal8Bit("%1 %2 %3").arg(m_runner->commandPrefix()).arg(remoteExe).arg(args)
        : QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4").arg(m_runner->commandPrefix())
              .arg(m_gdbServerPort).arg(remoteExe).arg(args);
    connect(m_runner, SIGNAL(remoteProcessFinished(qint64)),
        SLOT(handleRemoteProcessFinished(qint64)));
    m_runner->startExecution(remoteCommandLine.toUtf8());
}
    void STidSTRLEDBuzzerDisplay::setPort(bool red, bool green, bool buzzer)
    {
        d_red_led = red;
        d_green_led = green;
        d_buzzer = buzzer;

        setPort();
    }
示例#29
0
void InetAddrSIM::setAddress(const std::string& address,
                                          const vpr::Uint32 port)
{
   mAddress = vpr::sim::DNS::instance()->lookupAddress(address);
   setPort( port );
   setFamily( vpr::SocketTypes::INET );
   setDebugData();
}
示例#30
0
void dlgEditProfile::openMudList ()
{
  const cMUDEntry *e = dlgMudList::getEntry (this);
  if (!e) return;
  setName (e->name);
  setServer (e->host);  // TODO: perhaps add an ability to set IP instead of name ?
  setPort (e->port);
}