Пример #1
0
void ProxyConfig::fillClients()
{
    m_current = (unsigned)(-1);
    m_data.clear();
    cmbClient->clear();
    cmbClient->insertItem(i18n("Default"));
    ProxyData d(m_plugin->data);
    clear_list(&d.Clients);
    m_data.push_back(d);
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        if (client->protocol()->description()->flags & PROTOCOL_NOPROXY)
            continue;
        QString name = client->name().c_str();
        int pos = name.find(".");
        if (pos > 0)
            name = name.replace(pos, 1, " ");
        cmbClient->insertItem(Pict(client->protocol()->description()->icon), name);
        ProxyData d;
        m_plugin->clientData(static_cast<TCPClient*>(client), d);
        m_data.push_back(d);
    }
    bool bState;
    if (!get_connection_state(bState)){
        cmbClient->insertItem(i18n("HTTP requests"));;
        ProxyData d;
        m_plugin->clientData((TCPClient*)(-1), d);
        m_data.push_back(d);
    }
    clientChanged(0);
}
Пример #2
0
void SIMSockets::resultsReady()
{
    list<SIMResolver*>::iterator it;
    for (it = resolvers.begin(); it != resolvers.end();){
        SIMResolver *r = *it;
        if (!r->bDone){
            ++it;
            continue;
        }
        bool isActive;
        if (r->bTimeout){
            isActive = false;
        }else{
            isActive = true;
        }
        if (r->addr() == INADDR_NONE)
            isActive = false;
#ifdef WIN32
        bool bState;
        if (get_connection_state(bState))
            isActive = bState;
#endif
        setActive(isActive);
        emit resolveReady(r->addr(), r->host().c_str());
        resolvers.remove(r);
        delete r;
        it = resolvers.begin();
    }
}
Пример #3
0
TEST(hub_connection_tests, connection_status_start_stop_start_reconnect)
{
    auto hub_conn = std::make_shared<signalr::hub_connection>(url);
    auto weak_hub_conn = std::weak_ptr<signalr::hub_connection>(hub_conn);
    auto reconnecting_event = std::make_shared<signalr::event>();
    auto reconnected_event = std::make_shared<signalr::event>();

    hub_conn->set_reconnecting([weak_hub_conn, reconnecting_event]()
    {
        auto conn = weak_hub_conn.lock();
        if (conn)
        {
            ASSERT_EQ(conn->get_connection_state(), signalr::connection_state::reconnecting);
        }
        reconnecting_event->set();
    });

    hub_conn->set_reconnected([weak_hub_conn, reconnected_event]()
    {
        auto conn = weak_hub_conn.lock();
        if (conn)
        {
            ASSERT_EQ(conn->get_connection_state(), signalr::connection_state::connected);
        }
        reconnected_event->set();
    });

    hub_conn->start().get();
    ASSERT_EQ(hub_conn->get_connection_state(), signalr::connection_state::connected);

    hub_conn->stop().get();
    ASSERT_EQ(hub_conn->get_connection_state(), signalr::connection_state::disconnected);

    hub_conn->start().get();
    ASSERT_EQ(hub_conn->get_connection_state(), signalr::connection_state::connected);

    try
    {
        hub_conn->send(U("forceReconnect")).get();
    }
    catch (...)
    {
    }

    ASSERT_FALSE(reconnecting_event->wait(2000));
    ASSERT_FALSE(reconnected_event->wait(2000));
}
Пример #4
0
void SIMSockets::checkState()
{
#ifdef WIN32
    bool state;
    if (get_connection_state(state))
        setActive(state);
#endif
}
Пример #5
0
void SIMClientSocket::slotConnectionClosed()
{
    log(L_WARN, "Connection closed");
    timerStop();
    if (notify)
        notify->error_state(I18N_NOOP("Connection closed"));
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState) && !bState)
        getSocketFactory()->setActive(false);
#endif
}
Пример #6
0
unsigned SIM::fetch(const char *url, Buffer *postData, const char *headers, bool bRedirect)
{
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState))
        getSocketFactory()->setActive(bState);
#endif
    FetchClient *client = new FetchClient(url, postData, headers, bRedirect);
    if (client->id())
        return client->id();
    delete client;
    return 0;
}
Пример #7
0
SIMResolver::SIMResolver(QObject *parent, const char *host)
        : QObject(parent)
{
    bDone = false;
    bTimeout = false;
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState) && !bState){
        QTimer::singleShot(0, this, SLOT(resolveTimeout()));
        return;
    }
#endif
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(resolveTimeout()));
    timer->start(20000);
    dns = new QDns(host, QDns::A);
    connect(dns, SIGNAL(resultsReady()), this, SLOT(resolveReady()));
}
Пример #8
0
void SIMClientSocket::connect(const char *_host, unsigned short _port)
{
    port = _port;
    host = _host;
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState) && !bState){
        QTimer::singleShot(0, this, SLOT(slotConnectionClosed()));
        return;
    }
#endif
    log(L_DEBUG, "Connect to %s:%u", host.c_str(), port);
    if (inet_addr(host.c_str()) == INADDR_NONE){
        if (!host.empty() && (host[host.length() - 1] != '.'))
            host += ".";
        log(L_DEBUG, "Start resolve %s", host.c_str());
        SIMSockets *s = static_cast<SIMSockets*>(getSocketFactory());
        QObject::connect(s, SIGNAL(resolveReady(unsigned long, const char*)), this, SLOT(resolveReady(unsigned long, const char*)));
        s->resolve(host.c_str());
        return;
    }
    resolveReady(inet_addr(host.c_str()), host.c_str());
}