Browse Source

* cacaserver works again (but needs a complete rewrite because it's really

become ugly). You can now emulate the previous network driver behaviour
    by doing: "CACA_DRIVER=raw cacaplas | cacaserver".
tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
0e15619e46
1 changed files with 34 additions and 3 deletions
  1. +34
    -3
      src/cacaserver.c

+ 34
- 3
src/cacaserver.c View File

@@ -97,9 +97,12 @@ struct server
socklen_t sin_size; socklen_t sin_size;


/* Input buffer */ /* Input buffer */
uint8_t *input;
unsigned int read;


char prefix[sizeof(INIT_PREFIX)]; char prefix[sizeof(INIT_PREFIX)];


cucul_t *qq;
struct cucul_export *ex; struct cucul_export *ex;


int client_count; int client_count;
@@ -114,13 +117,15 @@ ssize_t nonblock_write(int fd, void *buf, size_t len);


int main(void) int main(void)
{ {
cucul_t *qq;
int i, yes = 1, flags; int i, yes = 1, flags;
struct server *server; struct server *server;
char *tmp; char *tmp;


server = malloc(sizeof(struct server)); server = malloc(sizeof(struct server));


server->input = malloc(12);
server->read = 0;

server->client_count = 0; server->client_count = 0;
server->clients = NULL; server->clients = NULL;
server->port = 0xCACA; /* 51914 */ server->port = 0xCACA; /* 51914 */
@@ -168,6 +173,7 @@ int main(void)
return -1; return -1;
} }


server->qq = NULL;
server->ex = NULL; server->ex = NULL;


/* Ignore SIGPIPE */ /* Ignore SIGPIPE */
@@ -179,12 +185,37 @@ int main(void)
/* Main loop */ /* Main loop */
for(;;) for(;;)
{ {
uint8_t *buf = server->input;
uint32_t width, height;
unsigned int size;

/* Manage new connections as this function will be called sometimes /* Manage new connections as this function will be called sometimes
* more often than display */ * more often than display */
manage_connections(server); manage_connections(server);


/* Read data from stdin */ /* Read data from stdin */
/* FIXME: read data, then continue if there was a new image */
read(0, buf, 12);

while(buf[0] != 'C' && buf[1] != 'A' && buf[2] != 'C' && buf[3] != 'A')
{
memmove(buf, buf + 1, 11);
read(0, buf + 11, 1);
}

width = ((uint32_t)buf[4] << 24) | ((uint32_t)buf[5] << 16)
| ((uint32_t)buf[6] << 8) | (uint32_t)buf[7];
height = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
| ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];

size = 12 + width * height * 5 + 4;
server->input = realloc(server->input, size);
read(0, buf + 12, size - 12);

/* Free the previous canvas, if any */
if(server->qq)
cucul_free(server->qq);

server->qq = cucul_load(buf, size);


/* Free the previous export buffer, if any */ /* Free the previous export buffer, if any */
if(server->ex) if(server->ex)
@@ -195,7 +226,7 @@ int main(void)


/* Get ANSI representation of the image and skip the end-of buffer /* Get ANSI representation of the image and skip the end-of buffer
* linefeed ("\r\n\0", 3 bytes) */ * linefeed ("\r\n\0", 3 bytes) */
server->ex = cucul_create_export(qq, "ansi");
server->ex = cucul_create_export(server->qq, "ansi");
server->ex->size -= 3; server->ex->size -= 3;


for(i = 0; i < server->client_count; i++) for(i = 0; i < server->client_count; i++)


Loading…
Cancel
Save