示例#1
0
    void WSThread_tls::send(websocketpp::connection_hdl hdl, std::string msg) {
        StringProc::removeSymbolsForString(msg);
        try {
            size_t buffered_amount = get_buffered_amount(hdl);

            unsigned int maxBuffSize = _tc->getMaxBuffSize();

            if (maxBuffSize < maximumBufferSizeMin || maxBuffSize > maximumBufferSizeMax)
                maxBuffSize = maximumBufferSizeDef * 1024;
            else
                maxBuffSize = maxBuffSize * 1024;

            if (buffered_amount<maxBuffSize)
                m_server.send(hdl, msg, websocketpp::frame::opcode::text);
            else
                close_from_server(hdl);

        }
        catch (websocketpp::exception const & e) {
            ERROR_STREAM_F << "exception from send: " << e.what() << endl;
            close_from_server(hdl);
        }
        catch (std::exception& e) {
            ERROR_STREAM_F << "exception from send: " << e.what() << endl;
            close_from_server(hdl);
        }
        catch (...) {
            ERROR_STREAM_F << "unknown error from send " << endl;
            close_from_server(hdl);
        }
    }
示例#2
0
    void WSThread_tls::send_all(std::string msg) {
        StringProc::removeSymbolsForString(msg);
        int ii = 0;
        size_t total = 0;

        unsigned int maxBuffSize = _tc->getMaxBuffSize();
        if (maxBuffSize < maximumBufferSizeMin || maxBuffSize > maximumBufferSizeMax)
            maxBuffSize = maximumBufferSizeDef * 1024;
        else
            maxBuffSize = maxBuffSize * 1024;

        vector<websocketpp::connection_hdl> for_close;

        websocketpp::lib::unique_lock<websocketpp::lib::mutex> con_lock(m_connection_lock);

        for (const auto& conn : m_connections) {
            try {
                websocketpp::lib::error_code erc;
                size_t buffered_amount = get_buffered_amount((conn.first));

                total += buffered_amount;
                DEBUG_STREAM_F << "con: " << ii << " bufersize: " << buffered_amount << " bytes | " << std::fixed << std::setprecision(3) << (buffered_amount / (1024. * 1024.)) << " Mb" << endl;

                if (buffered_amount<maxBuffSize)
                    m_server.send((conn.first), msg, websocketpp::frame::opcode::text);
                else {
                    ii++;
                    for_close.push_back(conn.first);
                    continue;
                }
                ii++;
            }
            catch (websocketpp::exception const & e) {
                ERROR_STREAM_F << "exception from send_all: " << e.what() << endl;
                ii++;
                for_close.push_back(conn.first);
            }
            catch (std::exception& e)
            {
                ERROR_STREAM_F << "exception from send_all: " << e.what() << endl;
                ii++;
                for_close.push_back(conn.first);
            }
            catch (...) {
                ERROR_STREAM_F << "unknown error from send_all " << endl;
                ii++;
                for_close.push_back(conn.first);
            }
        }

        for (auto& cls : for_close) {
            close_from_server(cls);
        }

        DEBUG_STREAM_F << std::fixed << "total bufersize: " << total << " | " << std::setprecision(3) << (total / (1024.*1024.)) << "  Mb: " << endl;
    }
示例#3
0
static void owr_data_channel_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
    OwrDataChannel *data_channel;
    OwrDataChannelPrivate *priv;

    g_return_if_fail(object);
    g_return_if_fail(value);
    g_return_if_fail(pspec);

    data_channel = OWR_DATA_CHANNEL(object);
    priv = data_channel->priv;

    switch (property_id) {
    case PROP_ORDERED:
        g_value_set_boolean(value, priv->ordered);
        break;
    case PROP_MAX_PACKET_LIFE_TIME:
        g_value_set_int(value, priv->max_packet_life_time);
        break;
    case PROP_MAX_RETRANSMITS:
        g_value_set_int(value, priv->max_retransmits);
        break;
    case PROP_PROTOCOL:
        g_value_set_string(value, priv->protocol);
        break;
    case PROP_NEGOTIATED:
        g_value_set_boolean(value, priv->negotiated);
        break;
    case PROP_ID:
        g_value_set_uint(value, priv->id);
        break;
    case PROP_LABEL:
        g_value_set_string(value, priv->label);
        break;
    case PROP_READY_STATE:
        g_value_set_enum(value, priv->ready_state);
        break;
    case PROP_BUFFERED_AMOUNT:
        g_value_set_uint(value, get_buffered_amount(data_channel));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
        break;
    }
}
示例#4
0
 /// DEPRECATED: use get_buffered_amount instead
 size_t buffered_amount() const {
     return get_buffered_amount();
 }