load.c (1089B)
1 #include <u.h> 2 #include <libc.h> 3 #include <thread.h> 4 5 #include "load.h" 6 7 void 8 threadload(void *v) 9 { 10 char *status; 11 int gfd; 12 Text text; 13 ulong n; 14 char buf[1024]; 15 16 Loadctl *lctl; 17 lctl = v; 18 19 status = smprint("dialing %s", lctl->addr); 20 send(lctl->sc, &status); 21 gfd = dial(lctl->addr, 0, 0, 0); 22 if (gfd == -1) { 23 status = smprint("failed to dial %s", lctl->addr); 24 send(lctl->sc, &status); 25 send(lctl->c, nil); 26 27 realloc(lctl->path, 0); 28 realloc(lctl->addr, 0); 29 realloc(lctl->query, 0); 30 return; 31 } 32 write(gfd, lctl->path, strlen(lctl->path)); 33 write(gfd, "\n", 1); 34 // if there're query, send query 35 text.data = nil; 36 text.size = 0; 37 while ((n = read(gfd, buf, 1024)) > 0){ 38 text.data = realloc(text.data, text.size + n); 39 memcpy(text.data + text.size, buf, n); 40 text.size += n; 41 status = smprint("loading - %ld bytes", text.size); 42 send(lctl->sc, &status); 43 // border animation 44 } 45 status = smprint("done - %s %s", lctl->addr, lctl->path); 46 send(lctl->sc, &status); 47 send(lctl->c, &text); 48 49 realloc(lctl->path, 0); 50 realloc(lctl->addr, 0); 51 realloc(lctl->query, 0); 52 }