Пример #1
0
int AutoAdapter::onTryConnectEcu(bool sendReply)
{
    int protocol = 0;
    connected_ = false;
    sts_ = REPLY_NO_DATA;
    sampleSent_ = false;
        
    // CAN
    protocol = doConnect(ADPTR_CAN, sendReply);
    if (protocol > 0)
        return protocol;

    // CAN 29
    return doConnect(ADPTR_CAN_EXT, sendReply);
}
Пример #2
0
// Constructor
OsDatagramSocket::OsDatagramSocket(int remoteHostPortNum, const char* remoteHost,
                                   int localHostPortNum, const char* localHost)
: mNumTotalWriteErrors(0)
, mNumRecentWriteErrors(0)
, mSimulatedConnect(FALSE)     // Simulated connection is off until
                               // activated in doConnect.
{
    int error = ctorCommonCode();
    if (error != 0)
    {
        OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                      "OsDatagramSocket::OsDatagramSocket( %s:%d %s:%d) failed w/ errno %d)",
                      remoteHost, remoteHostPortNum, localHost ? localHost : "NULL", 
                      localHostPortNum, error);
        goto EXIT;
    }

    // Bind to the socket
    bind(localHostPortNum, localHost);
    if (!isOk())
    {
        goto EXIT;
    }

    // Kick off connection
    doConnect(remoteHostPortNum, remoteHost, mSimulatedConnect);

EXIT:
    return;
}
Пример #3
0
TCPSocket::TCPSocket(const Address& address, TCPSocketObserver *o)
    throw(NetworkException)
    : SocketBase(address,true), observer(o)
{
    doConnect();
    setNoDelay();
}
Пример #4
0
void CSchedule::Start()
{

	if (!m_summer.Initialize())
	{
		return ;
	}

	for (int i=0; i< 1; i++)
	{
		CProcess * p = new CProcess();
		if (p->Start())
		{
			m_process.push_back(p);
		}
	}
	
	if (g_startType == 0)
	{
		if (m_accept.OpenAccept(g_remoteIP.c_str(), g_remotePort))
		{
			LOGI("open server port [" << g_remotePort << "] success");
		}
		CTcpSocketPtr s(new zsummer::network::CTcpSocket());
		s->Initialize(m_process[m_iCurProcess]->GetZSummer());
		m_accept.DoAccept(s, std::bind(&CSchedule::OnAccept, this, std::placeholders::_1, std::placeholders::_2, m_process[m_iCurProcess]));
	}
	else
	{
		doConnect(g_maxClient);
	}


	m_thread = std::thread(std::bind(&CSchedule::Run, this));
}
Пример #5
0
bool DekControl::unlock(string alias, Password *key) {
	printf("DekControl::unlock\n");

	shared_ptr<SerializedItem> sKey(key->serialize());

	sKey->dump("DekControl::unlock");

	int sock = doConnect();
	if(sock < 0) {
		printf("Cannot connect\n");
		return false;
	}

	string cmd = "0 ctl " + std::to_string(CommandCode::CommandUnlock) + " "
			+ alias + " " + sKey->toString();
	printf("cmd :: %s\n", cmd.c_str());
	write(sock, cmd.c_str(), cmd.size() + 1);

	shared_ptr<DaemonEvent> event(monitor(sock));
	close(sock);

	if(event->code == ResponseCode::CommandOkay) {
		return true;
	}

	printf("Failed to unlock [%d]\n", event->code);
	return false;
}
    void CloudReconnectWorker::doReconnect ( const AbsOptCloudClientWorker::BufferType& data )
    {
      gvr::communication::ucc::UccMessageCloudReconnect uccCloudReconnect;
      if (uccCloudReconnect.parse(data))
      {
        std::string jsonMessage;
        {
          uccCloudReconnect.getJson().serialize(jsonMessage);
          LOG_VNotice(core, "Received a reconnect command from the UCC [\n%s\n].\n", jsonMessage.c_str());
        }

        {
          std::string decryptedData;
          bool replaceOldEncryptedDataFile = false;
          bool decryptedDataOK = getDecryptedConnectionData(decryptedData);
          bool reconectStartOk = decryptedDataOK && (m_cloudStatus.getDeviceId().compare(uccCloudReconnect.getDeviceId()) == 0);
          sendReconnectResponse(uccCloudReconnect.getMessageId(), reconectStartOk);
          if(reconectStartOk)
          {
            LOG_VNotice(core, "Decrypted connection data Ok, doing a connect..\n", jsonMessage.c_str());
            doConnect(decryptedData);
          }
        }
      }
      else
      {
        LOG_VError(core, "UccMessageCloudReconnect Error [%s].\n", "Message parsing failed for reset command failed.");
      }
    }
Пример #7
0
bool SensorfwSensorBase::doConnectAfterCheck()
{
    if (!m_sensorInterface) return false;

    // buffer size
    int size = bufferSize();

    if (size == m_bufferSize) return true;

    if (m_bufferingSensors.contains(sensor()->identifier()))
        m_sensorInterface->setBufferSize(size);
    else
        size = 1;

    // if multiple->single or single->multiple or if uninitialized
    if ((m_bufferSize > 1 && size == 1) || (m_bufferSize == 1 && size > 1) || m_bufferSize == -1) {
        m_bufferSize = size;
        disconnect(this);
        if (!doConnect()) {
            qWarning() << "Unable to connect "<< sensorName();
            return false;
        }
        return true;
    }
    m_bufferSize = size;
    return true;
}
Пример #8
0
Client::Client(IoService& t_ioService, TcpResolverIterator t_endpointIterator, 
    std::string const& t_path)
    : m_ioService(t_ioService), m_socket(t_ioService), 
    m_endpointIterator(t_endpointIterator), m_path(t_path)
{
    doConnect();
    openFile(m_path);
}
Пример #9
0
PacketStorage::PacketStorage(QObject *parent)
    : QThread(parent),endThreadFlag(false)
{
    //做一些初始化工作,主要是连接信号和槽
    doConnect();

    //开始线程
    start();
}
Пример #10
0
FmRepair::FmRepair(QWidget *parent)
    :QDialog(parent)
{
    setupUi(this);
// 	listItems.clear();
    fillLists();
    doConnect();

}
Пример #11
0
Client::Client(boost::asio::io_service& ioService, tcp::resolver::iterator endpointIterator, ClientSettings settings)
	: ioService_(ioService), socket_(ioService)
{
	// Initialize
	settings_ = settings;

	// Connect our client
	doConnect(endpointIterator);
}
Пример #12
0
//-----------------------------------------------------------------------------
// 描述: 建立数据库连接并进行相关设置 (若失败则抛出异常)
//-----------------------------------------------------------------------------
void DbConnection::connect()
{
    if (!isConnected_)
    {
        doConnect();
        execCmdOnConnected();
        isConnected_ = true;
    }
}
Пример #13
0
void Connection::startConnect(const string& host, int port) {
  // Create a non-blocking socket.
  client_fd_ = socket(AF_INET, SOCK_STREAM, 0);
  if (client_fd_ < 0) {
    error_string_.append("Socket failed: ");
    error_string_.append(strerror(errno));
    in_error_ = true;
    return;
  }
  int flags = fcntl(client_fd_, F_GETFL, 0);
  fcntl(client_fd_, F_SETFL, flags | O_NONBLOCK);

  // Prepare to and start connection to 'host:port'.
  struct sockaddr_in serv_addr;
  bzero(&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(port);
  inet_pton(AF_INET, host.c_str(), &serv_addr.sin_addr);
  int res = connect(client_fd_, (sockaddr*) &serv_addr, sizeof(serv_addr));

  // Regardless of the success on connecting, we expect the user's
  // 'connDone()' up-call to be issued. Therefore doConnect() is called
  // -- directly, if success or failure in connecting is detected
  // immediately, or indirectly, otherwise. The acquire() here is
  // matched by a release() in doConnect().
  acquire();
  if (res >= 0) {
    doConnect();

  } else if ((errno != EINPROGRESS) && (errno != EINTR)) {
    ::close(client_fd_);
    client_fd_ = -1;
    error_string_.append("Connect failed: ");
    error_string_.append(strerror(errno));
    in_error_ = true;
    doConnect();

  } else {
    Callback<void>* write_cb = makeCallableMany(&Connection::doConnect, this);
    IOManager* io_manager = io_service_->io_manager();
    io_desc_ = io_manager->newDescriptor(client_fd_, NULL, write_cb);
    io_desc_->writeWhenReady();
  }
}
Пример #14
0
void
TCPSocket::onResolved()
{
    SocketBase::onResolved();
    create();
    setNonBlocking();
    setConfigured();
    doConnect();
    setNoDelay();
}
Пример #15
0
EncKey *DekClient::encrypt(string alias, SymKey *key) {
	printf("DekClient::encrypt\n");

	int sock = doConnect();
	if(sock < 0) {
		printf("Cannot connect\n");
		return false;
	}

	shared_ptr<SerializedItem> sKey(key->serialize());
	sKey->dump("DekClient::encrypt");

	string cmd = "0 enc " + std::to_string(CommandCode::CommandEncrypt) + " "
			+ alias + " " + sKey->toString();
	printf("cmd :: %s\n", cmd.c_str());
	write(sock, cmd.c_str(), cmd.size() + 1);

	shared_ptr<DaemonEvent> event(monitor(sock));
	close(sock);

	if(event == NULL) {
		printf("Failed to encrypt : %d\n", __LINE__);
		return NULL;
	}

	event->dump("encrypt return event");

	if(event->code == ResponseCode::CommandOkay) {
		int alg = std::stoi(event->message[0]);
		shared_ptr<SerializedItem> sItem;
		switch(alg) {
		case CryptAlg::AES:
			sItem = shared_ptr<SerializedItem> (
					new SerializedItem(alg, event->message[1].c_str(),
							event->message[2].c_str(), "?"));
			break;
		case CryptAlg::ECDH:
			sItem = shared_ptr<SerializedItem> (
					new SerializedItem(alg, event->message[1].c_str(),
							event->message[2].c_str(), event->message[3].c_str()));
			break;
		default:
			printf("Failed to encrypt. unknown alg %d\n", alg);
			break;
		}

		return (EncKey *) sItem->deserialize();
	} else {
		printf("Failed to encrypt [%d]\n",
				(event == NULL) ? ResponseCode::CommandFailed : event->code);
		return NULL;
	}

	return NULL;
}
Пример #16
0
void OpenSSLContext::handleDataFromNetwork(const SafeByteArray& data) {
	BIO_write(readBIO_, vecptr(data), data.size());
	switch (state_) {
		case Connecting:
			doConnect();
			break;
		case Connected:
			sendPendingDataToApplication();
			break;
		case Start: assert(false); break;
		case Error: /*assert(false);*/ break;
	}
}
Пример #17
0
/*
 * dblink_connect(server text) : boolean
 */
Datum
dblink_connect(PG_FUNCTION_ARGS)
{
	text   *name = PG_GETARG_TEXT_PP(0);
	Conn   *conn;
	bool	isNew;

	conn = doConnect(name, name, &isNew);
	conn->use_xa = PG_GETARG_BOOL(1);
	conn->keep = true;

	PG_RETURN_BOOL(isNew);
}
Пример #18
0
void Initiator::connect()
{
  Locker l(m_mutex);

  SessionIDs disconnected = m_disconnected;
  SessionIDs::iterator i = disconnected.begin();
  for ( ; i != disconnected.end(); ++i )
  {
    Session* pSession = Session::lookupSession( *i );
    if ( pSession->isEnabled() && pSession->isSessionTime(UtcTimeStamp()) )
      doConnect( *i, m_settings.get( *i ));
  }
}
Пример #19
0
void TcpMediaChannel::Connect(const MediaURL& url) {
    my_url_ = url;
    is_ready_ = false;
    Close();

    createSocket();
    int ret = doConnect();

    if ( ret < 0) {
        Close();    
        SignalChannelOpened(this, false); 
    }
}
Пример #20
0
T MysqlConnection_new(URL_T url, char **error) {
	T C;
        MYSQL *db;
	assert(url);
        assert(error);
        if (! (db = doConnect(url, error)))
                return NULL;
	NEW(C);
        C->db = db;
        C->url = url;
        C->sb = StringBuffer_create(STRLEN);
        C->timeout = SQL_DEFAULT_TIMEOUT;
	return C;
}
Пример #21
0
T OracleConnection_new(URL_T url, char **error) {
        T C;
        assert(url);
        assert(error);
        NEW(C);
        C->url = url;
        C->sb = StringBuffer_create(STRLEN);
        C->timeout = SQL_DEFAULT_TIMEOUT;
        if (! doConnect(C, url, error)) {
                OracleConnection_free(&C);
                return NULL;
        }
        C->txnhp = NULL;
        return C;
}
Пример #22
0
void Device::on_btn_getStatus_clicked()
{
    qDebug()<<"btn_getStatus_clicked";
    bool ret=false;

    //this->dev_ip= "127.0.0.1";
    qDebug()<<this->dev_ip;
    ret = doConnect(this->dev_ip);  ///< call doConnect and passing device's IP
    if(ret==false)  ///< check for device is present in network or not
    {
        QErrorMessage *err_msg= new QErrorMessage();
        err_msg->setWindowTitle("ERROR!");
        err_msg->showMessage("SORRY! Device not found ");
        return;
    }
}
Пример #23
0
MainViewWidget::MainViewWidget ( QWidget *parent )
	: QWidget ( parent )
{
	setupUi ( this );
	filterBar->setFilterListLayout(filterListLayout);
	filterBar->setCurFilterWidget(curFilterWidget);
	curFilterWidget->setVisible(false);
	quickSearchWidget->setVisible(false);

	quickSearchWait = 4000;
	quickSearchTimer = 0;
	m_forceReloadSelection = false;
	FMFontDb::DB()->clearFilteredFonts();

	listView->setNumCol(4);
	listView->setModelColumn(1);
	listView->setViewMode(QListView::IconMode);
	listView->setIconSize(QSize(qRound(listView->width() ), 1.3 * typotek::getInstance()->getPreviewSize() * typotek::getInstance()->getDpiY() / 72.0));
	listView->setUniformItemSizes(true);
	listView->setMovement(QListView::Static);

	previewModel = new FMPreviewModel( this, listView );
	previewModel->setSpecString("<family>");
	previewModel->setFamilyMode(true);
	listView->setModel(previewModel);



	iconPS1 =  QIcon(":/icon-PS1");
	iconTTF =  QIcon(":/icon-TTF");
	iconOTF =  QIcon(":/icon-OTF");

	
	theVeryFont = 0;
	typo = typotek::getInstance();
//	m_lists = ListDockWidget::getInstance();
	// 	currentFonts = typo->getAllFonts();
	FMFontDb::DB()->filterAllFonts();
	fontsetHasChanged = true;

	QSettings settings;
	activateByFamilyOnly = settings.value("ActivateOnlyFamily", false).toBool();

	currentOrdering = "family" ;
	doConnect();
	listView->setFocus(Qt::OtherFocusReason);
}
Пример #24
0
T SqlServerConnection_new(URL_T url, char **error) {
	T C;
	SqlServer_T db;
	assert(url);
	assert(error);
	if (! (db = doConnect(url, error)))
		return NULL;
	NEW(C);
	C->db = db;
	C->url = url;
	C->timeout = SQL_DEFAULT_TIMEOUT;
	C->sb = StringBuffer_create(STRLEN);
	C->err = StringBuffer_create(STRLEN);
	//  if (! setProperties(C, error))
	//         SqlServerConnection_free(&C);
	return C;
}
Пример #25
0
 void TcpRpcChannel::serverConnected(const boost::system::error_code& ec, tcp::resolver::iterator iter) {
     if (ec) {
         if (iter == tcp::resolver::iterator()) {
             GOOGLE_LOG(ERROR) << "fail to connect to server " << serverAddr_ << ":" << serverPort_;
             connectTried_ = true;
             startConnect();
         } else {
             doConnect(++iter);
         }
     } else {
         //the connection to server is established
         GOOGLE_LOG(INFO) << "connect to server " << serverAddr_ << ":" << serverPort_ << " successfully";
         boost::system::error_code error;
         sock_.set_option(tcp::socket::reuse_address(true), error);
         startRead();
         connectTried_ = true;
     }
 }
Пример #26
0
bool KviHttpRequest::start()
{
	// ensure that the file is closed
	resetInternalStatus();
	resetStatus();

	if(m_eProcessingType == StoreToFile)
	{
		if(m_szFileName.isEmpty())
		{
			m_szLastError = __tr2qs("No filename specified for the \"StoreToFile\" processing type");
			return false;
		}

		if((m_eExistingFileAction == Resume) && (m_uContentOffset == 0))
		{
			// determine the content offset automatically
			if(KviFile::exists(m_szFileName))
			{
				// we check it
				QFileInfo fi(m_szFileName);
				m_uContentOffset = fi.size();
			}
		}
	}

	if(m_connectionUrl.host().isEmpty())
	{
		resetInternalStatus();
		m_szLastError = __tr2qs("Invalid URL: missing hostname");
		return false;
	}

	m_p->bIsSSL = KviQString::equalCI(m_connectionUrl.protocol(),"https");

	if(!KviQString::equalCI(m_connectionUrl.protocol(),"http") && !m_p->bIsSSL)
	{
		resetInternalStatus();
		m_szLastError=__tr2qs("Unsupported protocol %1").arg(m_connectionUrl.protocol());
		return false;
	}

	return doConnect();
}
Пример #27
0
SymKey *DekClient::decrypt(string alias, EncKey *key) {
	printf("DekClient::decrypt\n");

	int sock = doConnect();
	if(sock < 0) {
		printf("Cannot connect\n");
		return false;
	}

	shared_ptr<SerializedItem> sKey(key->serialize());
	sKey->dump("DekClient::decrypt");

	string cmd = "0 enc " + std::to_string(CommandCode::CommandDecrypt) + " "
			+ alias + " " + sKey->toString();
	printf("cmd :: %s\n", cmd.c_str());
	write(sock, cmd.c_str(), cmd.size() + 1);

	shared_ptr<DaemonEvent> event(monitor(sock));
	close(sock);

	if(event == NULL) {
		printf("Failed to encrypt : %d\n", __LINE__);
		return NULL;
	}

	if(event->code == ResponseCode::CommandOkay) {
		int alg = std::stoi(event->message[0]);
		if(alg != CryptAlg::PLAIN) {
			printf("Failed to decrypt : result is not plain text\n");
			return NULL;
		}
		shared_ptr<SerializedItem> sItem(
					new SerializedItem(CryptAlg::PLAIN, event->message[1].c_str(),
							"?", "?"));
		return (SymKey *) sItem->deserialize();
	} else {
		printf("Failed to decrypt [%d]\n",
				(event == NULL) ? ResponseCode::CommandFailed : event->code);
		return NULL;
	}

	return NULL;
}
Пример #28
0
TestClient::TestClient()
    : KMainWindow( 0 ),
      m_status( AppDisconnected ), m_view( new QWidget( this ) )
{
    ui.setupUi( m_view );

    setCentralWidget(m_view);

    networkStatusChanged( Solid::Networking::status() );
    appDisconnected();

    kDebug() << "About to connect";
    connect( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), SLOT(networkStatusChanged(Solid::Networking::Status)) );
    kDebug() << "Connected.";
    connect( Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(doConnect()) );
    connect( Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(doDisconnect()) );

    connect( ui.connectButton, SIGNAL(clicked()), SLOT(connectButtonClicked()) );
}
Пример #29
0
// The connection of found from connection list of same address is returned.
connection* connections::connect(const std::string& hst, const char* port,
        handshake f, void* data, bool newConnection, bool clearNRCache)
{
    bool namedPipe = false;
    connection* c;
    std::string host = hst;
    unsigned int opt = clearNRCache ? HST_OPTION_CLEAR_CACHE : 0;
    char buf[MAX_PATH];
    if (m_haNameResolver)
    {
        m_haNameResolver(hst.c_str(), port, buf, opt);
        char* p = strchr(buf, ':');
        if (p)
        {
            *p = 0x00;
            port = p + 1;
        }
        host = buf;
    }
    mutex::scoped_lock lck(m_mutex);
    asio::ip::tcp::endpoint ep = endpoint(host, port, m_e);
    if (m_e)
        return NULL;
#ifdef USE_PIPE_CLIENT
    namedPipe =  (m_usePipedLocal && isUseNamedPipe(ep));
    if (namedPipe)
        c = newConnection ? NULL : getConnectionPipe(ep.port());
    else
#endif
        c = newConnection ? NULL : getConnection(ep);
    if (newConnection || !c)
    {
        c = createConnection(ep, namedPipe);
        c->setUserOptions(opt);
        c = doConnect(c);
        if (!c || !doHandShake(c, f, data))
            return NULL;
        m_conns.push_back(c);
    }
    c->addref();
    return c;
}
Пример #30
0
Inverter::Inverter(bool output)
    : m_stdout(output), m_cycle(MSG_DETAIL)
{
    // set up our UDP socket
    // this is used to find all inverters on the LAN
    m_udpsocket = new QUdpSocket(this);

    // setup our tcp server
    // this is used to send control messages to any inverters that respond to UDP messages
    m_server    = new QTcpServer(this);

    // start the TCP server and listen on the standard samil port
    connect(m_server, SIGNAL(newConnection()),this, SLOT(newClient()));
    m_server->listen(QHostAddress::Any, TCP_PORT);

    // start a new timer that will send out UDP discovery messages on timeout
    connect(&m_connectTimer, SIGNAL(timeout()), this, SLOT(doConnect()));
    m_connectTimer.start(CONNECTION_TIME);

}