void broadcast(struct message *m, fd_set *writefds) { struct handler *h = handlers; while(h) { if(h->h_type == PERSISTENT) { char *buff; switch(h->i_type) { case JSON: buff = message_to_json(m); if(! (ensure_write(h->fdout, buff, strlen(buff)) && ensure_write(h->fdout, "\n", 1))) { fprintf(stderr, "Failed to write to handler %s\n", h->command); } break; case RAW: buff = message_to_IRC(m); break; } } else if(h->h_type == TRANSIENT) { kill_child(h); launch_child(h); char *buff; switch(h->i_type) { case JSON: buff = message_to_json(m); if(! (ensure_write(h->fdout, buff, strlen(buff)) && ensure_write(h->fdout, "\n", 1))) { fprintf(stderr, "Failed to write to handler %s\n", h->command); } close(h->fdout); break; case RAW: buff = message_to_IRC(m); if( ! ensure_write(h->fdout, buff, strlen(buff))) { fprintf(stderr, "Failed to write to handler %s\n", h->command); } close(h->fdout); break; } } h = h->next; } }
static int extract_data(FILE *inp, FILE *outp, size_t s) { size_t got=0; char buf[4096]=""; while((got=fread(buf, 1, min(sizeof(buf), s), inp))>0) { if(ensure_write(buf, got, outp)) return -1; s-=got; if(s<=0) break; } if(s!=0) { fprintf(stderr, "Error - expected %lu more bytes\n", s); return -1; } return 0; }
int set_vss(BFILE *bfd, const char *vssdata, size_t vlen, struct conf **confs) { // Just need to write the VSS stuff to the file. if(!vlen || !vssdata) return 0; return ensure_write(bfd, vssdata, vlen); }