void RTCDataChannel::didDecreaseBufferedAmount(unsigned previousAmount)
{
    if (previousAmount > m_bufferedAmountLowThreshold
        && bufferedAmount() <= m_bufferedAmountLowThreshold) {
        scheduleDispatchEvent(Event::create(EventTypeNames::bufferedamountlow));
    }
}
Exemple #2
0
// ActiveScriptWrappable
bool RTCDataChannel::hasPendingActivity() const
{
    if (m_stopped)
        return false;

    // A RTCDataChannel object must not be garbage collected if its
    // * readyState is connecting and at least one event listener is registered
    //   for open events, message events, error events, or close events.
    // * readyState is open and at least one event listener is registered for
    //   message events, error events, or close events.
    // * readyState is closing and at least one event listener is registered for
    //   error events, or close events.
    // * underlying data transport is established and data is queued to be
    //   transmitted.
    bool hasValidListeners = false;
    switch (m_readyState) {
    case ReadyStateConnecting:
        hasValidListeners |= hasEventListeners(EventTypeNames::open);
        // fallthrough intended
    case ReadyStateOpen:
        hasValidListeners |= hasEventListeners(EventTypeNames::message);
        // fallthrough intended
    case ReadyStateClosing:
        hasValidListeners |= hasEventListeners(EventTypeNames::error) || hasEventListeners(EventTypeNames::close);
        break;
    default:
        break;
    }

    if (hasValidListeners)
        return true;

    return m_readyState != ReadyStateClosed && bufferedAmount() > 0;
}
void SocketStreamHandle::writeReady()
{
    // We no longer have buffered data, so stop waiting for the socket to be writable.
    if (!bufferedAmount()) {
        stopWaitingForSocketWritability();
        return;
    }

    sendPendingData();
}
void
SocketStreamHandleServer::progressTimerFired()
{
    switch (m_progressState) {
    case EError:
        if (m_client)
            m_client->didFailSocketStream(reinterpret_cast<SocketStreamHandle*>(this), SocketStreamError(-1));
        break;

    case EConnectingDest:
        break;
#if 0
    case EConnectingProxy:
    {
        char buf[1024] = {0};
        fd_set rd;
        FD_ZERO(&rd);
        FD_SET(m_socket, &rd);
        struct timeval tv = {0};
        if (wkcNetSelectPeer(m_socket+1, &rd, NULL, NULL, &tv)==0) {
            m_progressTimer.startOneShot(0.1);
            break;
        }
        int len = wkcNetRecvPeer(m_socket, buf, sizeof(buf), 0);
        if (len<=0) {
            m_progressTimer.startOneShot(0.1);
            break;
        }
        String result(buf);
        if (result.find("Connection Established", 0, false)) {
            m_progressState = EConnected;
            m_progressTimer.startOneShot(0.1);
        } else {
            m_progressState = EError;
            m_progressTimer.startOneShot(0.1);
        }
        break;
    }
#endif
    case EConnected:
        m_state = Open;
        m_progressState = EReady;
        if (m_client)
            m_client->didOpenSocketStream(reinterpret_cast<SocketStreamHandle*>(this));
        m_progressTimer.startOneShot(0.1);
        break;

    case EReady:
    {
        char buf[1024] = {0};
        do {
            fd_set rd, wd;
            FD_ZERO(&rd);
            FD_ZERO(&wd);
            FD_SET(m_socket, &rd);
            FD_SET(m_socket, &wd);
            struct timeval tv = {0};
            int ret = wkcNetSelectPeer(m_socket+1, &rd, &wd, NULL, &tv);
            if (ret == 0 || (!FD_ISSET(m_socket, &rd) && !bufferedAmount()))
                break;
            if (FD_ISSET(m_socket, &rd)) {
                int len = wkcNetRecvPeer(m_socket, buf, sizeof(buf), 0);
                if (len<=0)
                    break;
                if (m_client)
                    m_client->didReceiveSocketStreamData(reinterpret_cast<SocketStreamHandle*>(this), buf, len);
            }
            if (bufferedAmount()) {
                if (FD_ISSET(m_socket, &wd)) {
                    if (!sendPendingData()) {
                        m_progressState = EError;
                        break;
                    }
                }
            }
        } while (1);
        m_progressTimer.startOneShot(0.1);
        break;
    }

    case ERequestClose:
        if (m_client)
            m_client->didCloseSocketStream(reinterpret_cast<SocketStreamHandle*>(this));
        m_state = Closed;
        break;

    default:
        break;
    }
}