Example #1
0
Bool rfbIsCongested(rfbClientPtr cl)
{
    int offset;  time_t sockIdleTime;

    if (!cl->enableFence)
        return FALSE;

    sockIdleTime = msSince(&cl->lastWrite);

    /* Idle for too long? (and no data on the wire)

       FIXME: This should really just be one baseRTT, but we're getting
              problems with triggering the idle timeout on each update.
              Maybe we need to use a moving average for the wire latency
              instead of baseRTT. */
    if ((cl->sentOffset == cl->ackedOffset) &&
        (sockIdleTime > 2 * cl->baseRTT)) {

#ifdef CONGESTION_DEBUG
        if (cl->congWindow > INITIAL_WINDOW)
            rfbLog("Reverting to initial window (%d KB) after %d ms\n",
                   INITIAL_WINDOW / 1024, sockIdleTime);
#endif

        /* Close congestion window and allow a transfer
           FIXME: Reset baseRTT like Linux Vegas? */
        cl->congWindow = min(INITIAL_WINDOW, cl->congWindow);
        return FALSE;
    }

    offset = cl->sockOffset;

    /* FIXME: Should we compensate for non-update data?
              (i.e. use sentOffset instead of offset) */
    if ((offset - cl->ackedOffset) < cl->congWindow)
        return FALSE;

    /* If we just have one outstanding "ping", then that means the client has
       started receiving our update.  In order to provide backward
       compatibility with viewers that don't support the flow control
       extensions, we allow another update here.  This could further clog up
       the tubes, but if we reach this point, congestion control isn't really
       working properly anyhow, as the wire would otherwise be idle for at
       least RTT/2. */
    if (cl->pingCounter == 1)
        return FALSE;

    return TRUE;
}
Example #2
0
void rgbPoll() {
  if (_error) {
    LED_ON(PIN_R);
    return;
  }

  _pollCounter += 1;

  if (msSince(_lastms) > MS_PER_UNIT_DURATION) {
    _lastms = _elapsedTime.ms;
    _duration -= 1;

    _r = adjIntensity(_r, _dr);
    _g = adjIntensity(_g, _dg);
    _b = adjIntensity(_b, _db);

  }

  pwm(_pollCounter, _r, PIN_R);
  pwm(_pollCounter, _g, PIN_G);
  pwm(_pollCounter, _b, PIN_B);

  if (_duration == 0) {
    // first set ourselves to the value the control block specified, since we
    // probably didn't hit it due to founding errors.
    ControlBlock *cb = ctrBlockCurrent();
    copyColors(cb);

    cb = ctrBlockNext();
    _duration = cb->duration;

    if (_duration) {
      _dr = calcColorDelta(_r, cb->r, _duration);
      _dg = calcColorDelta(_g, cb->g, _duration);
      _db = calcColorDelta(_b, cb->b, _duration);

      if (_dr == 0) _r = (cb->r+_r)/2;
      if (_dg == 0) _g = (cb->g+_g)/2;
      if (_db == 0) _b = (cb->b+_b)/2;

    } else copyColors(cb);
  }
}
Example #3
0
static void HandleRTTPong(rfbClientPtr cl, RTTInfo *rttInfo)
{
    unsigned rtt, delay;

    cl->pingCounter--;

    rtt = msSince(&rttInfo->tv);
    if (rtt < 1)
        rtt = 1;

    cl->ackedOffset = rttInfo->offset;

    /* Try to estimate wire latency by tracking lowest latency seen */
    if (rtt < cl->baseRTT)
        cl->baseRTT = rtt;

    if (rttInfo->inFlight > cl->congWindow) {
        cl->seenCongestion = TRUE;

        /* Estimate added delay because of overtaxed buffers */
        delay = (rttInfo->inFlight - cl->congWindow) *
                 cl->baseRTT / cl->congWindow;

        if (delay < rtt)
            rtt -= delay;
        else
            rtt = 1;

        /* If we underestimate the congestion window, then we'll get a latency
           that's less than the wire latency, which will confuse other portions
           of the code. */
        if (rtt < cl->baseRTT)
            rtt = cl->baseRTT;
    }

    /* We only keep track of the minimum latency seen (for a given interval)
       because we want to avoid issuing buffers continously, but we don't mind
       (and even approve of) bursts. */
    if (rtt < cl->minRTT)
        cl->minRTT = rtt;
}
Example #4
0
void gameloop() { 
    srand( time(NULL));
    
    root = (struct node *) malloc(sizeof(struct node));
    body = (struct node *) malloc(sizeof(struct node));
    tail = (struct node *) malloc(sizeof(struct node));
    head = (struct node *) malloc(sizeof(struct node));
    temp = (struct node *) malloc(sizeof(struct node));
    apple = (struct node *) malloc(sizeof(struct node));


    int h = 5;
    int x = 100;
    int y = 120;
    root->x = 160;
    root->y = 120;
    body->x = 154;
    body->y = 120;
    tail->x = 0;
    tail->y = 0;
    head->x = 0;
    head->y = 0;
    // apple->x = 130;
    // apple ->y = 120;


    tail->next = root;
    head->next = body;
    root->next = body;

    bool go = true;
    int moving = 1;
    drawRect(0,0,320, 240, &white);
    drawRect(4,6, 306, 228, &black);
    drawRect(root->x, root->y, h, h, &green);
    drawRect(body->x, body->y, h, h, &green);
    drawApple(tail);


    struct timespec lastTime;
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &lastTime);



    //while (nanosleep(&sleeptime, &sleeptime) && errno == EINTR);
    getGpio();
        while(go){
            while (msSince(lastTime)<50);
                clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &lastTime);
            head->next->next =  (struct node *) malloc(sizeof(struct node));
            if (direction == 5){
                break;
            }
            if(direction != moving+2 && direction != moving-2 && direction != moving){
                if (direction != 0){
                    moving = direction;
                }
            }

            if (moving == 1){
                head->next->next->x = head->next->x-6;
                head->next->next->y = head->next->y;
            }
            else if(moving == 2){
                head->next->next->x = head->next->x;
                head->next->next->y = head->next->y-6;
            }
            else if(moving == 3){
                head->next->next->x = head->next->x+6;
                head->next->next->y = head->next->y;
            }
            else if(moving == 4){
                head->next->next->x = head->next->x;
                head->next->next->y = head->next->y+6;
            }
            if (checkScreen(head->next->next->x, head->next->next->y) == green)
            {
                printf("You f****n wanku55\n");
                break;
            }
            head->next = head->next->next;

            drawRect(head->next->x, head->next->y, h, h, &green);
            if(head->next->x >=308 || head->next->y >=235 || head->next->x <= 2 || head->next->y <= 5){
                printf("you f*****g wankuh\n");
                break;
            }
            if(head->next->x != apple->x || head->next->y != apple->y){
                drawRect(tail->next->x, tail->next->y, h, h, &black);
                temp = tail->next->next;
                free(tail->next);
                tail->next = temp;
            }
            else{
               drawApple(tail);
            }
        }

}