Ignore:
Timestamp:
May 5, 2009, 6:42:08 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • Handle large screens
File:
1 edited

Legend:

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

    r3396 r3431  
    2424#include <signal.h>
    2525#include <sys/ioctl.h>
     26#include <sys/socket.h>
    2627#include <sys/types.h>
    2728#include <sys/wait.h>
     
    4041    if(!screen_list->socket[SOCK_CLIENT])
    4142        connect_socket(screen_list, SOCK_CLIENT);
    42     debug("Sending message (%s) to client on socket %d", msg, screen_list->socket[SOCK_CLIENT]);
     43    debug("Sending message (%.8s,%d) to client on socket %d", msg, strlen(msg), screen_list->socket[SOCK_CLIENT]);
    4344    if(!screen_list->socket[SOCK_CLIENT])
    4445        ret = -1;
     
    106107        connect_socket(screen_list, SOCK_CLIENT);
    107108    if(screen_list->socket[SOCK_CLIENT])
    108         if(write(screen_list->socket[SOCK_CLIENT], buf2, bytes+8) <= 0 && errno != EAGAIN)
    109         {
    110             debug("Can't refresh (%s), with %d bytes\n", strerror(errno), bytes+8);
     109    {
     110        size_t bufsize, towrite = bytes+8;
     111        ssize_t written;
     112        socklen_t optlen = sizeof(bufsize);
     113        debug("Requesting refresh for %d", bytes+8);
     114        getsockopt(screen_list->socket[SOCK_CLIENT], SOL_SOCKET, SO_SNDBUF,
     115                   &bufsize, &optlen);
     116        written = write(screen_list->socket[SOCK_CLIENT],
     117                        buf2,
     118                        towrite > bufsize ? bufsize : towrite);
     119        if(written <= 0 && errno != EAGAIN)
     120        {
     121            debug("Can't refresh (%s), with %d bytes", strerror(errno), towrite);
    111122            return -1;
    112123        }
     124        debug("Wrote %d bytes", written);
     125        towrite -= written;
     126        while(written > 0 && towrite > 0)
     127        {
     128            ssize_t n;
     129            debug("Wrote %d, %d remaining", written, towrite);
     130            /* Block to read the end of the message */
     131            fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, 0);
     132            n = write(screen_list->socket[SOCK_CLIENT],
     133                      buf2 + written,
     134                      towrite > bufsize ? bufsize : towrite);
     135            if(n < 0)
     136            {
     137                debug("Can't refresh (%s), with %d bytes", strerror(errno), bytes+8);
     138                return -1;
     139            }
     140            written += n;
     141            towrite -= n;
     142        }
     143        fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, O_NONBLOCK);
     144    }
    113145    free(buf);
    114146    free(buf2);
Note: See TracChangeset for help on using the changeset viewer.