Changeset 3457


Ignore:
Timestamp:
May 14, 2009, 6:16:41 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • Adapt refresh rate dynamically and inform the server about it
Location:
neercs/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/attach.c

    r3456 r3457  
    177177int request_attach(struct screen_list* screen_list)
    178178{
    179     char buf[32];
     179    char buf[41];
    180180    int bytes;
    181181
    182     bytes = snprintf(buf, sizeof(buf)-1, "ATTACH %10d%c%10d",
     182    bytes = snprintf(buf, sizeof(buf)-1, "ATTACH %10d %10d %10d",
    183183                     caca_get_canvas_width(screen_list->cv),
    184                      ' ',
    185                      caca_get_canvas_height(screen_list->cv));
     184                     caca_get_canvas_height(screen_list->cv),
     185                     screen_list->delay);
    186186    buf[bytes] = '\0';
    187187    debug("Requesting attach: %s", buf);
     
    445445}
    446446
     447int send_delay(struct screen_list* screen_list)
     448{
     449    char buf[18];
     450    int bytes;
     451    bytes = snprintf(buf, sizeof(buf)-1, "DELAY %10d", screen_list->delay);
     452    buf[bytes] = '\0';
     453    return write(screen_list->socket[SOCK_SERVER], buf, strlen(buf)) <= 0;
     454}
  • neercs/trunk/src/main.c

    r3456 r3457  
    180180                char * buf2;
    181181                size_t l = 0;
     182                int dt;
    182183                /* 0 means we have valid data but incomplete, so read the rest */
    183184                while(l == 0)
     
    206207                fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, O_NONBLOCK);
    207208                caca_refresh_display(screen_list->dp);
    208                 debug("refreshtime=%d", caca_get_display_time(screen_list->dp));
     209                dt = caca_get_display_time(screen_list->dp);
     210                debug("refreshtime=%dms (limit %d, requested %d)", dt/1000, screen_list->delay, screen_list->requested_delay);
     211                /* Adjust refresh delay so that the server do not compute useless things */
     212                if(dt > 2*1000*screen_list->delay)
     213                {
     214                    screen_list->delay*=2;
     215                    send_delay(screen_list);
     216                }
     217                else if(dt < screen_list->delay*1000/2 &&
     218                        screen_list->delay >= 2*screen_list->requested_delay)
     219                {
     220                    screen_list->delay/=2;
     221                    send_delay(screen_list);
     222                }
    209223            }
    210224            else if(!strncmp("CURSOR ", buf, 7))
  • neercs/trunk/src/neercs.h

    r3456 r3457  
    245245int start_server(struct screen_list *screen_list);
    246246int send_event(caca_event_t ev, struct screen_list* screen_list);
     247int send_delay(struct screen_list* screen_list);
    247248
    248249/* Screens management */
  • neercs/trunk/src/server.c

    r3456 r3457  
    222222        int quit = 0;
    223223        ssize_t n;
    224         char buf[4097];
     224        char buf[128];
    225225
    226226        /* Read program output */
     
    240240                caca_free_canvas(screen_list->cv);
    241241                screen_list->cv = caca_create_canvas(atoi(buf+7), atoi(buf+18));
     242                screen_list->delay = atoi(buf+29);
    242243                screen_list->width  = caca_get_canvas_width(screen_list->cv);
    243244                screen_list->height = caca_get_canvas_height(screen_list->cv) - ((screen_list->mini*6) + (screen_list->status));
     
    249250            {
    250251                quit = 1;
     252            }
     253            else if(!strncmp("DELAY ", buf, 6))
     254            {
     255                screen_list->delay = atoi(buf+6);
    251256            }
    252257            else if(!strncmp("RESIZE ", buf, 7))
Note: See TracChangeset for help on using the changeset viewer.