コード例 #1
0
ファイル: dbclient.cpp プロジェクト: RyokoAkizuki/freshcity
    void DBClientConnection::_checkConnection() {
        if ( !_failed )
            return;
        if ( lastReconnectTry && time(0)-lastReconnectTry < 2 ) {
            // we wait a little before reconnect attempt to avoid constant hammering.
            // but we throw we don't want to try to use a connection in a bad state
            throw SocketException( SocketException::FAILED_STATE , toString() );
        }
        if ( !autoReconnect )
            throw SocketException( SocketException::FAILED_STATE , toString() );

        lastReconnectTry = time(0);
        log(_logLevel) << "trying reconnect to " << _serverString << endl;
        string errmsg;
        _failed = false;
        if ( ! _connect(errmsg) ) {
            _failed = true;
            log(_logLevel) << "reconnect " << _serverString << " failed " << errmsg << endl;
            throw SocketException( SocketException::CONNECT_ERROR , toString() );
        }

        log(_logLevel) << "reconnect " << _serverString << " ok" << endl;
        for( map< string, pair<string,string> >::iterator i = authCache.begin(); i != authCache.end(); i++ ) {
            const char *dbname = i->first.c_str();
            const char *username = i->second.first.c_str();
            const char *password = i->second.second.c_str();
            if( !DBClientBase::auth(dbname, username, password, errmsg, false) )
                log(_logLevel) << "reconnect: auth failed db:" << dbname << " user:" << username << ' ' << errmsg << '\n';
        }
    }
コード例 #2
0
int
connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
    libc_func(connect, int, int, const struct sockaddr *, socklen_t);
    int res;

    /* playback */
    if (addr->sa_family == AF_UNIX) {
	const char *sock_path = ((struct sockaddr_un *) addr)->sun_path;
	TRAP_PATH_LOCK;
	const char *p = trap_path(sock_path);
	struct sockaddr_un trapped_addr;

	if (p != sock_path) {
	    DBG(DBG_NETLINK, "testbed wrapped connect: redirecting Unix socket %s to %s\n", sock_path, p);
	    trapped_addr.sun_family = AF_UNIX;
	    strncpy(trapped_addr.sun_path, p, sizeof(trapped_addr.sun_path));
	    addr = (struct sockaddr*) &trapped_addr;
	}
	TRAP_PATH_UNLOCK;
    }

    res = _connect(sockfd, addr, addrlen);
    script_record_connect(sockfd, addr, addrlen, res);

    return res;
}
コード例 #3
0
ファイル: mainWindow.cpp プロジェクト: rballester/Livre
void MainWindow::_createActions()
{
// connect to an application
    _linkAct = new QAction( QIcon(":/link.png"), tr("&Connect..."), this );  Q_ASSERT( _linkAct );
    _linkAct->setShortcut(tr("Ctrl+C"));
    connect( _linkAct, SIGNAL( triggered( )), this, SLOT( _connect( )));

// open a file
    _openAct = new QAction( QIcon(":/open.png"), tr("&Open..."), this );  Q_ASSERT( _openAct );
    _openAct->setShortcut(tr("Ctrl+O"));
    connect( _openAct, SIGNAL( triggered( )), this, SLOT( _open( )));

// transfer function editor
    _tfAct = new QAction( QIcon(":/tune.png"), tr("Edit &TF"), this );  Q_ASSERT( _tfAct );
    _tfAct->setShortcut(tr("Ctrl+T"));
    _tfAct->setEnabled( true );
    connect( _tfAct, SIGNAL( triggered( )), this, SLOT( _adjustTF()));

// quit app
    _quitAct = new QAction( tr("&Quit"), this );   Q_ASSERT( _quitAct );
    _quitAct->setShortcuts( QKeySequence::Quit );
    _quitAct->setStatusTip( tr("Quit the application") );
    connect(_quitAct, SIGNAL(triggered()), this, SLOT( close()));

// about
    _aboutAct = new QAction( tr("&About"), this );   Q_ASSERT( _aboutAct );
    _aboutAct->setStatusTip( tr("Show the application's About box") );
    connect(_aboutAct, SIGNAL(triggered()), this, SLOT( _about()));


// recent directories actions
    RecentFiles::_createActions();
}
コード例 #4
0
ファイル: client.cpp プロジェクト: oliver-e/Equalizer
bool Client::connectServer( ServerPtr server )
{
    if( Super::connectServer( server.get( )))
    {
        server->setClient( this );
        return true;
    }

    if( !server->getConnectionDescriptions().empty() ||
        !Global::getServer().empty() || getenv( "EQ_SERVER" ))
    {
        return false;
    }

    // Use app-local server if no explicit server was set
    co::ConnectionPtr connection = _startLocalServer();
    if( !connection )
        return false;

    if( !_connect( server.get(), connection ))
        // giving up
        return false;

    server->setClient( this );
    server->_localServer = true;
    return true;
}
コード例 #5
0
AdmXmppWidget::AdmXmppWidget(QWidget *parent) :
  QFrame(parent),
  ui(new Ui::AdmXmppWidget)
{
  ui->setupUi(this);
  _client = NULL;
  _conn = NULL;
  _socketNotify = NULL;

  _mapBuddies = new QMap<JID,AdmXmppBuddyWidget*>();
  _mapBuddyItems = new QMap<JID,AdmXmppBuddyItem*>();
  _mapChats = new QMap<QString,AdmXmppChatWidget*>();
  _mapSessions = new QMap<QString,MessageSession*>();
  
  connect(ui->_status,  SIGNAL(currentIndexChanged(int)),
          this,         SLOT(sStatusIndexChanged(int))
  );

  connect(ui->_buddyList, SIGNAL(activated(QModelIndex)),
          this,           SLOT(sBuddyActivated(QModelIndex)));

  connect(ui->_conversations, SIGNAL(currentChanged(int)),
          this,               SLOT(sConversationsCurrentChanged(int)));

  connect(ui->_conversations, SIGNAL(tabCloseRequested(int)),
          this,               SLOT(sConversationsTabClosed(int)));
          
  // Customize colors
  ui->_buddyList->setStyleSheet("QListWidget::item:selected {background: palette(button);}");
  ui->_buddyList->setSortingEnabled(true);

  // Connect to XMPP
  _connect();
}
コード例 #6
0
void CIMExportClient::connect(
    const String& host,
    const Uint32 portNumber)
{
    PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::connect()");

    // If already connected, bail out!
    if (_connected)
    {
        PEG_METHOD_EXIT();
        throw AlreadyConnectedException();
    }

    //
    // If the host is empty, set hostName to "localhost"
    //
    String hostName = host;
    if (host == String::EMPTY)
    {
        hostName = "localhost";
    }

    //
    // Set authentication information
    //
    _authenticator.clear();

    _connectSSLContext.reset(0);
    _connectHost = hostName;
    _connectPortNumber = portNumber;

    _connect();
    PEG_METHOD_EXIT();
}
コード例 #7
0
ファイル: iFuse.Lib.Conn.cpp プロジェクト: iychoi/irods
static int _newConn(iFuseConn_t **iFuseConn) {
    int status = 0;
    iFuseConn_t *tmpIFuseConn = NULL;

    assert(iFuseConn != NULL);

    tmpIFuseConn = (iFuseConn_t *) calloc(1, sizeof ( iFuseConn_t));
    if (tmpIFuseConn == NULL) {
        *iFuseConn = NULL;
        return SYS_MALLOC_ERR;
    }

    tmpIFuseConn->connId = _genNextConnID();

    iFuseRodsClientLog(LOG_DEBUG, "_newConn: creating a new connection - %lu", tmpIFuseConn->connId);

    pthread_mutexattr_init(&tmpIFuseConn->lockAttr);
    pthread_mutexattr_settype(&tmpIFuseConn->lockAttr, PTHREAD_MUTEX_RECURSIVE);
    pthread_mutex_init(&tmpIFuseConn->lock, &tmpIFuseConn->lockAttr);

    // connect
    status = _connect(tmpIFuseConn);
    *iFuseConn = tmpIFuseConn;
    return status;
}
コード例 #8
0
EXPORT_SYM const char *
hdfs_namenode_connect(struct hdfs_namenode *n, const char *host, const char *port)
{
	const char *error = NULL;

	_lock(&n->nn_lock);
	ASSERT(n->nn_sock == -1);

	if (n->nn_kerb == HDFS_TRY_KERB || n->nn_kerb == HDFS_REQUIRE_KERB) {
		int r = sasl_client_new("hdfs", host, NULL/*localip*/,
		    NULL/*remoteip*/, NULL/*CBs*/, 0/*sec flags*/, &n->nn_sasl_ctx);
		if (r != SASL_OK) {
			error = sasl_errstring(r, NULL, NULL);
			goto out;
		}
	}

	error = _connect(&n->nn_sock, host, port);
	if (error)
		goto out;

out:
	_unlock(&n->nn_lock);
	return error;
}
コード例 #9
0
ファイル: WsHook.cpp プロジェクト: Appdynamics/webpagetest
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
int CWsHook::connect(IN SOCKET s, const struct sockaddr FAR * name, IN int namelen)
{
	int ret = SOCKET_ERROR;
  bool allowed = true;

	// we only care about IP sockets at this point
	if( dlg && namelen >= sizeof(struct sockaddr_in) && name->sa_family == AF_INET)
	{
		struct sockaddr_in * ipName = (struct sockaddr_in *)name;
    // Block access to link-local addresses (169.254.x.x)
    if ((ipName->sin_addr.S_un.S_addr & 0x0000FFFF) == 0x0000FEA9)
      allowed = false;
    else
		  dlg->SocketConnect(s, ipName);
	}

  if (allowed) {
	  if( _connect )
		  ret = _connect(s, name, namelen);
    if (!ret) {
      dlg->SocketConnected(s);
    }

    if (tlsIndex != TLS_OUT_OF_INDEXES)
      TlsSetValue(tlsIndex, 0);
  }

	return ret;
}
コード例 #10
0
ファイル: FTPServer.c プロジェクト: agb861/ddd
/*********************************************************************
*
*       _Connect
*
*  Function description
*    This function is called from the FTP server module if the client
*    uses active FTP to establish the data connection.
*/
static FTPS_SOCKET _Connect(FTPS_SOCKET CtrlSocket, U16 Port) {
  int                DataSock;
  struct sockaddr_in Data;
  struct sockaddr_in PeerAddr;
  int                ConnectStatus;
  int                AddrSize;

  DataSock = _socket(AF_INET, SOCK_STREAM, 0);  // Create a new socket for data connection to the client
  if (DataSock != SOCKET_ERROR) {               // Socket created?
    Data.sin_family      = AF_INET;
    Data.sin_port        = _htons(20);
    Data.sin_addr.s_addr = INADDR_ANY;
    _bind(DataSock, (struct sockaddr *)&Data, sizeof(Data));
    //
    //  Get IP address of connected client and connect to listening port
    //
    AddrSize = sizeof(struct sockaddr_in);
    _getpeername((long)CtrlSocket, (struct sockaddr *)&PeerAddr, &AddrSize);
    PeerAddr.sin_port = _htons(Port);
    ConnectStatus  = _connect(DataSock, (struct sockaddr *)&PeerAddr, sizeof(struct sockaddr_in));
    if (ConnectStatus == 0) {
      return (void*)DataSock;
    }
  }
  return NULL;
}
コード例 #11
0
    void SyncSourceFeedback::run() {
        Client::initThread("SyncSourceFeedbackThread");
        OperationContextImpl txn;

        bool positionChanged = false;
        bool handshakeNeeded = false;
        ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator();
        while (!inShutdown()) { // TODO(spencer): Remove once legacy repl coordinator is gone.
            {
                boost::unique_lock<boost::mutex> lock(_mtx);
                while (!_positionChanged && !_handshakeNeeded && !_shutdownSignaled) {
                    _cond.wait(lock);
                }

                if (_shutdownSignaled) {
                    break;
                }

                positionChanged = _positionChanged;
                handshakeNeeded = _handshakeNeeded;
                _positionChanged = false;
                _handshakeNeeded = false;
            }

            MemberState state = replCoord->getCurrentMemberState();
            if (state.primary() || state.fatal() || state.startup()) {
                continue;
            }
            const Member* target = BackgroundSync::get()->getSyncTarget();
            if (_syncTarget != target) {
                _resetConnection();
                _syncTarget = target;
            }
            if (!hasConnection()) {
                // fix connection if need be
                if (!target) {
                    sleepmillis(500);
                    continue;
                }
                if (!_connect(&txn, target->fullName())) {
                    sleepmillis(500);
                    continue;
                }
            }
            if (handshakeNeeded) {
                if (!replHandshake(&txn)) {
                    boost::unique_lock<boost::mutex> lock(_mtx);
                    _handshakeNeeded = true;
                    continue;
                }
            }
            if (positionChanged) {
                if (!updateUpstream(&txn)) {
                    boost::unique_lock<boost::mutex> lock(_mtx);
                    _positionChanged = true;
                }
            }
        }
        cc().shutdown();
    }
コード例 #12
0
ファイル: namenode.c プロジェクト: cemeyer/hadoofus
EXPORT_SYM struct hdfs_error
hdfs_namenode_connect(struct hdfs_namenode *n, const char *host, const char *port)
{
	struct hdfs_error error = HDFS_SUCCESS;

	_lock(&n->nn_lock);
	ASSERT(n->nn_sock == -1);

	if (n->nn_kerb == HDFS_TRY_KERB || n->nn_kerb == HDFS_REQUIRE_KERB) {
		int r = sasl_client_new("hdfs", host, NULL/*localip*/,
		    NULL/*remoteip*/, NULL/*CBs*/, 0/*sec flags*/, &n->nn_sasl_ctx);
		if (r != SASL_OK) {
			error = error_from_sasl(r);
			goto out;
		}
	}

	error = _connect(&n->nn_sock, host, port);
	if (hdfs_is_error(error))
		goto out;

out:
	_unlock(&n->nn_lock);
	return error;
}
コード例 #13
0
ファイル: localNode.cpp プロジェクト: MichaelVlad/Equalizer
bool LocalNode::connect( NodePtr node )
{
    EQASSERTINFO( _state == STATE_LISTENING, _state );
    if( node->_state == STATE_CONNECTED || node->_state == STATE_LISTENING )
        return true;

    EQASSERT( node->_state == STATE_CLOSED );

    // try connecting using the given descriptions
    const ConnectionDescriptions& cds = node->getConnectionDescriptions();
    if( node->getConnectionDescriptions().empty( ))
        EQWARN << "Can't connect to a node with no listening connections"
               << std::endl;
    for( ConnectionDescriptions::const_iterator i = cds.begin();
        i != cds.end(); ++i )
    {
        ConnectionDescriptionPtr description = *i;
        if( description->type >= CONNECTIONTYPE_MULTICAST )
            continue; // Don't use multicast for primary connections

        ConnectionPtr connection = Connection::create( description );
        if( !connection || !connection->connect( ))
            continue;

        return _connect( node, connection );
    }
    return false;
}
コード例 #14
0
ファイル: localNode.cpp プロジェクト: MichaelVlad/Equalizer
//----------------------------------------------------------------------
// Connecting a node
//----------------------------------------------------------------------
NodePtr LocalNode::connect( const NodeID& nodeID )
{
    EQASSERT( nodeID != NodeID::ZERO );
    EQASSERT( _state == STATE_LISTENING );

    Nodes nodes;
    getNodes( nodes );

    for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
    {
        NodePtr peer = *i;
        if( peer->getNodeID() == nodeID && peer->isConnected( )) // early out
            return peer;
    }

    for( Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
    {
        NodePtr peer = *i;
        NodePtr node = _connect( nodeID, peer );
        if( node.isValid( ))
            return node;
    }
        
    EQWARN << "Node " << nodeID << " connection failed" << std::endl;
    return 0;
}
コード例 #15
0
ファイル: connections_dialog.cpp プロジェクト: 93i/godot
/*
Post-ConnectDialog callback for creating/editing connections.
Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
*/
void ConnectionsDock::_make_or_edit_connection() {

	TreeItem *it = tree->get_selected();
	ERR_FAIL_COND(!it);

	NodePath dst_path = connect_dialog->get_dst_path();
	Node *target = selectedNode->get_node(dst_path);
	ERR_FAIL_COND(!target);

	Connection cToMake;
	cToMake.source = connect_dialog->get_source();
	cToMake.target = target;
	cToMake.signal = connect_dialog->get_signal_name();
	cToMake.method = connect_dialog->get_dst_method_name();
	cToMake.binds = connect_dialog->get_binds();
	bool defer = connect_dialog->get_deferred();
	bool oshot = connect_dialog->get_oneshot();
	cToMake.flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0);

	bool add_script_function = connect_dialog->get_make_callback();
	PoolStringArray script_function_args;
	if (add_script_function) {
		// pick up args here before "it" is deleted by update_tree
		script_function_args = it->get_metadata(0).operator Dictionary()["args"];
		for (int i = 0; i < cToMake.binds.size(); i++) {
			script_function_args.append("extra_arg_" + itos(i));
		}
	}

	if (connect_dialog->is_editing()) {
		_disconnect(*it);
		_connect(cToMake);
	} else {
		_connect(cToMake);
	}

	// IMPORTANT NOTE: _disconnect and _connect cause an update_tree,
	// which will delete the object "it" is pointing to
	it = NULL;

	if (add_script_function) {
		editor->emit_signal("script_add_function_request", target, cToMake.method, script_function_args);
		hide();
	}

	update_tree();
}
コード例 #16
0
void WbemExecClient::_reconnect()
{
    PEGASUS_ASSERT(_connected);
    _httpConnector->disconnect(_httpConnection);
    _httpConnection = 0;
    _connected = false;
    _connect();
}
コード例 #17
0
ファイル: WiFlyClient.cpp プロジェクト: amaxilat/Wifly-MQTT
int WiFlyClient::connect(const char *host, uint16_t port){
    /*
     */
    _ip = NULL;
    _port = port;
    _domain = host;

    return _connect();
}
コード例 #18
0
ファイル: reliantunix.c プロジェクト: Axelio/cert_ve_mozilla
PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
                        PRIntervalTime timeout)
{
    PRInt32 rv;

    _MD_BLOCK_CLOCK_INTERRUPTS();
    rv = _connect(osfd,addr,addrlen);
    _MD_UNBLOCK_CLOCK_INTERRUPTS();
}
コード例 #19
0
ファイル: rmdir.c プロジェクト: vocho/openqnx
int rmdir(const char *path) {
	int							fd;

	if((fd = _connect(_NTO_SIDE_CHANNEL, path, S_IFDIR, O_NOCTTY, SH_DENYNO, _IO_CONNECT_UNLINK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == -1) {
		return -1;
	}
	ConnectDetach(fd);
	return 0;
}
コード例 #20
0
ファイル: MonsterProperties.cpp プロジェクト: lswzzz/QTEditor
MonsterProperties::MonsterProperties(char* title, QSize size)
	:ControlBaseDockWidget(title, size, true)
{
	m_ControlView_Type = Type_MonsterProperties;
	_setLayout();
	_connect();
	addSelectedCheckBox();
	addCheckBoxConnect();
}
コード例 #21
0
ファイル: connect.c プロジェクト: NanXiao/illumos-joyent
int
connect(int s, struct sockaddr *name, int namelen)
{
	int	a;

	if ((a = _connect(s, name, namelen)) == -1)
		maperror();
	return (a);
}
コード例 #22
0
bool ESPSerialWiFiManager::_connect_enc(String ssid){
    OF("Connect to "); O(ssid); OFL(":");

    String pass = _prompt("Password", '*');

    _get_advanced();

    return _connect(ssid, pass);
}
コード例 #23
0
ファイル: pathmgr_unlink.c プロジェクト: vocho/openqnx
int pathmgr_unlink(const char *path) { 
	int							fd;
	
	if((fd = _connect(PATHMGR_COID, path, S_IFLNK, O_NOCTTY, SH_DENYNO, _IO_CONNECT_UNLINK, 0, 0, _FTYPE_LINK, 0, 0, 0, 0, 0, 0)) == -1) {
		return -1;
	}
	ConnectDetach(fd);
	return 0;
}
コード例 #24
0
void NetworkInterfaceASIO::_startCommand(AsyncOp* op) {
    LOG(3) << "running command " << redact(op->request().cmdObj) << " against database "
           << op->request().dbname << " across network to " << op->request().target.toString();
    if (inShutdown()) {
        return;
    }

    // _connect() will continue the state machine.
    _connect(op);
}
コード例 #25
0
bool OSGGTKDrawingArea::createWidget(int width, int height) {
    _glconfig = gdk_gl_config_new_by_mode(static_cast<GdkGLConfigMode>(
        GDK_GL_MODE_RGBA |
        GDK_GL_MODE_DEPTH |
        GDK_GL_MODE_DOUBLE
    ));

    if(not _glconfig) {
        osg::notify(osg::FATAL) << "Fail!" << std::endl;

        return false;
    }

    gtk_widget_set_size_request(_widget, width, height);

    gtk_widget_set_gl_capability(
        _widget,
        _glconfig,
        0,
        true,
        GDK_GL_RGBA_TYPE
    );

    gtk_widget_add_events(
        _widget,
        GDK_BUTTON1_MOTION_MASK |
        GDK_BUTTON2_MOTION_MASK |
        GDK_BUTTON3_MOTION_MASK |
        GDK_POINTER_MOTION_MASK |
        GDK_BUTTON_PRESS_MASK |
        GDK_BUTTON_RELEASE_MASK |
        GDK_KEY_PRESS_MASK |
        GDK_KEY_RELEASE_MASK |
        GDK_VISIBILITY_NOTIFY_MASK
    );

    // We do this so that we don't have to suck up ALL the input to the
    // window, but instead just when the drawing area is focused.
    g_object_set(_widget, "can-focus", true, NULL);

    _connect("realize", G_CALLBACK(&OSGGTKDrawingArea::_srealize));
    _connect("unrealize", G_CALLBACK(&OSGGTKDrawingArea::_sunrealize));
    _connect("expose_event", G_CALLBACK(&OSGGTKDrawingArea::_sexpose_event));
    _connect("configure_event", G_CALLBACK(&OSGGTKDrawingArea::_sconfigure_event));
    _connect("motion_notify_event", G_CALLBACK(&OSGGTKDrawingArea::_smotion_notify_event));
    _connect("button_press_event", G_CALLBACK(&OSGGTKDrawingArea::_sbutton_press_event));
    _connect("button_release_event", G_CALLBACK(&OSGGTKDrawingArea::_sbutton_press_event));
    _connect("key_press_event", G_CALLBACK(&OSGGTKDrawingArea::_skey_press_event));

    _gw = setUpViewerAsEmbeddedInWindow(0, 0, width, height);

    return true;
}
コード例 #26
0
ファイル: ESP_RESTClient.cpp プロジェクト: nkolban/ESPLibs
void ESP_RestClient::m_resolveHostname() {
	LOG("About to resolve hostname of: %s\n", m_hostname.c_str());
	if (m_serverIP.addr != 0) {
		_connect();
		return;
	}
	int rc = espconn_gethostbyname(&m_conn, m_hostname.c_str(), &m_serverIP,
			dnsFoundCallback);
	if (rc == ESPCONN_OK) {
		LOG("We immediately have an IP address\n");
		_connect();
		return;
	}
	if (rc != ESPCONN_INPROGRESS) {
		_handleError();
		return;
	}
	return;
} // End of m_resolveHostname
コード例 #27
0
ファイル: WiFlyClient.cpp プロジェクト: amaxilat/Wifly-MQTT
int WiFlyClient::connect(IPAddress ip, uint16_t port){
    /*
     */
    
    _ip = rawIPAddress(ip);
    _port = port;
    _domain = NULL;

    return _connect();
}
コード例 #28
0
ファイル: pathmgr_symlink.c プロジェクト: vocho/openqnx
int pathmgr_symlink(const char *path, const char *symlinkp) { 
	int							fd;
	
	if((fd = _connect(PATHMGR_COID, symlinkp, S_IFLNK | S_IPERMS, O_CREAT | O_EXCL | O_NOCTTY, SH_DENYNO, _IO_CONNECT_LINK, 0, 0, _FTYPE_LINK,
			_IO_CONNECT_EXTRA_PROC_SYMLINK, strlen(path) + 1, path, 0, 0, 0)) == -1) {
		return -1;
	}
	ConnectDetach(fd);
	return 0;
}
コード例 #29
0
ファイル: Network.cpp プロジェクト: nsierra-/Zappy-Client
Network::Network(Client *client, unsigned int port, std::string hostName) :
	_client(client),
	_hostName(hostName),
	_port(port),
	_connected(false)
{
	_connect();
	if (_connected)
		std::cout << getpid() << " dit " << "Connected to server." << std::endl;
}
コード例 #30
0
void NotifyrClient::listen() {
	if (_client.available()) {
		char c = _client.read();
		
		if (c != _lastChar || c != ' ') { //ignore double spaces
			// Serial.print(c);
			
			if (_receiving && _lastChar == '\n' && c == '\n') { //detect double newline
				//remove newline and quote
				_buffer = _buffer.substring(0, _buffer.length() - 2);
				
				NotifyrClient::_log("Data: " + _buffer);
				
				//do thing
				if (_eventDelegate != NULL) {
					_eventDelegate(_buffer);
				}
				
				//reset
				_buffer = "";
				_receiving = false;
			}
			
			_buffer += c;
			
			if (_buffer.endsWith("data: \"")) {
				NotifyrClient::_log("Receiving Event...");
				_buffer = "";
				_receiving = true;
				_lastHeartbeat = millis();
			} else if (_buffer.endsWith("data: null")) { //check for heartbeat
				NotifyrClient::_log("Heartbeat...");
				_buffer = "";
				_lastHeartbeat = millis();
			}
		}
		_lastChar = c;
	}
	
	//if it has been longer than the threshhold since our last heartbeat, reconnect
	if (_lastHeartbeat && (millis() - _lastHeartbeat) > HEARTBEAT_THRESHHOLD) {
		NotifyrClient::_log("Missed heartbeat!");
		NotifyrClient::_log("Disconnecting...");
		disconnect();
		NotifyrClient::_log("Connecting...");
		if (_connect()) {
			NotifyrClient::_log("Reconnected!");
			_buffer = "";
			_lastHeartbeat = millis();
		} else {
			NotifyrClient::_log("Connection failed! Sleeping 3 seconds...");
			delay(3000);
		}
	}
}