void NewNet::TcpClientSocket::connect(const std::string & host, unsigned int port) { assert((descriptor() == -1) || (socketState() == SocketUninitialized)); setSocketState(SocketConnecting); NNLOG("newnet.net.debug", "Resolving host '%s'.", host.c_str()); struct hostent *h = gethostbyname(host.c_str()); if(! h) { NNLOG("newnet.net.warn", "Cannot resolve host '%s'.", host.c_str()); setSocketError(ErrorCannotResolve); cannotConnectEvent(this); return; } struct sockaddr_in address; memset(&address, 0, sizeof(address)); address.sin_family = AF_INET; memcpy(&(address.sin_addr.s_addr), *(h->h_addr_list), sizeof(address.sin_addr.s_addr)); address.sin_port = htons(port); NNLOG("newnet.net.debug", "Connecting to host '%s:%u'.", host.c_str(), port); int s = socket(PF_INET, SOCK_STREAM, 0); if (!setnonblocking(s)) NNLOG("newnet.net.warn", "Couldn't set socket %i to non blocking (errno: %i)", s, errno); setDescriptor(s); if(s < 0) { NNLOG("newnet.net.warn", "Cannot connect to host '%s:%u', error: %i.", host.c_str(), port, WSAGetLastError()); setSocketError(ErrorCannotConnect); cannotConnectEvent(this); return; } // Add a connection timeout if (reactor()) { m_ConnectionTimeout = reactor()->addTimeout(120000, this, &TcpClientSocket::onConnectionTimeout); } connectedEvent.connect(this, &TcpClientSocket::onConnected); if(::connect(s, (struct sockaddr *)&address, sizeof(struct sockaddr_in)) == 0) { // When using non blocking socket (most of the time), we don't get here. NNLOG("newnet.net.debug", "Connected to host '%s:%u'.", host.c_str(), port); setSocketState(SocketConnected); connectedEvent(this); } else if(WSAGetLastError() != WSAEWOULDBLOCK) { // When using non blocking socket (most of the time), we don't get here. NNLOG("newnet.net.warn", "Cannot connect to host '%s:%u', error: %i.", host.c_str(), port, WSAGetLastError()); setSocketError(ErrorCannotConnect); cannotConnectEvent(this); } }
void ConnectHandler::connectedEventHandlerThreadSafe(std::string imAccountId, EnumPresenceState::PresenceState initialPresenceState ) { if (_userProfile && !_freeze) { IMAccount * imAccount = _userProfile->getIMAccountManager().getIMAccount(imAccountId); if (imAccount) { imAccount->setConnected(true); imAccount->setPresenceState( initialPresenceState ); //VOXOX - JRT - 2009.09.10 //VOXOX - JRT - 2009.09.14 - We now set the initialPresence before we try to connect. ////TODO: VOXOX CHANGE by Rolando - 2009.05.22 - FIX this: check if each network associated supports invisible presence //if(_userProfile->mustLoginInvisible() && imAccount->getProtocol() != EnumIMProtocol::IMProtocolWengo && imAccount->getProtocol() != EnumIMProtocol::IMProtocolSIP) //{ // //VOXOX CHANGE by Rolando - 2009.05.22 - because user can login as invisible presence we have to change here the presence to be able to do change it // //TODO: Find a way to be able to change the presence to invisible before set connected the imaccount to "true" // //this is provocating that others users can realize that user logged in and later "logged off" // imAccount->setPresenceState(EnumPresenceState::PresenceStateInvisible); // _userProfile->setPresenceState(EnumPresenceState::PresenceStateInvisible, imAccountId);//VOXOX CHANGE by Rolando - 2009.05.15 //} EnumPresenceState::PresenceState presenceState = imAccount->getPresenceState();//VOXOX CHANGE by Rolando - 2009.07.15 EnumIMProtocol::IMProtocol imProtocol = imAccount->getProtocol();//VOXOX CHANGE by Rolando - 2009.07.15 _userProfile->updateIMAccount(*imAccount); _userProfile->requestSyncData(*imAccount); //VOXOX - JRT - 2009.08.03 OWSAFE_DELETE(imAccount); connectedEvent(*this, imAccountId);//VOXOX CHANGE by Rolando - 2009.05.15 //VOXOX CHANGE by Rolando - 2009.07.15 if( QtEnumIMProtocolMap::supportsPresence( imProtocol ) ) //VOXOX - JRT - 2009.08.28 - moved logic to QtEnumIMProtocol { _userProfile->setPresenceState(presenceState, imAccountId, false, String::null );//VOXOX CHANGE by Rolando - 2009.07.15 //VOXOX - JRT - 2009.09.14 } } } }
void PhApiIMConnect::connectedEventHandler(PhApiWrapper & sender) { _imAccount.setPresenceState( _imAccount.getInitialPresenceState() );//VOXOX - JRT - 2009.09.14 - Should always be 'online'? connectedEvent(*this); }