Ignore:
Timestamp:
May 13, 2009, 10:56:59 AM (11 years ago)
Author:
Pascal Terjan
Message:
  • Remove a memcpy
File:
1 edited

Legend:

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

    r3441 r3444  
    9999    size_t bytes;
    100100    void *buf;
    101     char *buf2;
    102101    buf = caca_export_memory (screen_list->cv, "caca", &bytes);
    103     buf2 = malloc(bytes+8);
    104     memcpy(buf2, "REFRESH ", 8);
    105     memcpy(buf2+8, buf, bytes);
    106102    if(!screen_list->socket[SOCK_CLIENT])
    107103        connect_socket(screen_list, SOCK_CLIENT);
    108104    if(screen_list->socket[SOCK_CLIENT])
    109105    {
    110         size_t bufsize, towrite = bytes+8;
    111         ssize_t written;
     106        size_t bufsize, towrite = bytes;
     107        ssize_t written = 0, ret;
    112108        socklen_t optlen = sizeof(bufsize);
    113         debug("Requesting refresh for %d", bytes+8);
     109        debug("Requesting refresh for %d", bytes);
     110       
    114111        getsockopt(screen_list->socket[SOCK_CLIENT], SOL_SOCKET, SO_SNDBUF,
    115112                   &bufsize, &optlen);
    116113        bufsize /= 2;
    117114        debug("bufsize=%d", bufsize);
    118         written = write(screen_list->socket[SOCK_CLIENT],
    119                         buf2,
    120                         towrite > bufsize ? bufsize : towrite);
    121         if(written <= 0 && errno != EAGAIN)
    122         {
    123             debug("Can't refresh (%s), with %d bytes (out of %d)", strerror(errno), towrite > bufsize ? bufsize : towrite, towrite);
     115        ret = write(screen_list->socket[SOCK_CLIENT],
     116                    "REFRESH ",
     117                    8);
     118        if(ret <= 8 && errno != EAGAIN)
     119        {
     120            free(buf);
    124121            return -1;
    125122        }
    126         debug("Wrote %d bytes", written);
    127         towrite -= written;
    128         while(written > 0 && towrite > 0)
     123        while(towrite > 0)
    129124        {
    130125            ssize_t n;
    131126            debug("Wrote %d, %d remaining", written, towrite);
    132             /* Block to read the end of the message */
     127            /* Block to write the end of the message */
    133128            fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, 0);
    134129            n = write(screen_list->socket[SOCK_CLIENT],
    135                       buf2 + written,
     130                      (char *)buf + written,
    136131                      towrite > bufsize ? bufsize : towrite);
    137132            if(n < 0)
    138133            {
    139                 debug("Can't refresh (%s), with %d bytes", strerror(errno), bytes+8);
     134                debug("Can't refresh (%s), with %d bytes (out of %d)", strerror(errno), towrite > bufsize ? bufsize : towrite, towrite);
    140135                return -1;
    141136            }
     
    146141    }
    147142    free(buf);
    148     free(buf2);
    149143    return 0;
    150144}
Note: See TracChangeset for help on using the changeset viewer.