static void buffered_socket_read_cb(EV_P_ struct ev_io *w, int revents) { struct BufferedSocket *buffsock = (struct BufferedSocket *)(w->data); int res; res = buffer_read_fd(buffsock->read_buf, w->fd); _DEBUG("%s: %d bytes read\n", __FUNCTION__, res); if (res == -1) { if (errno == EAGAIN || errno == EINTR) { return; } goto error; } else if (res == 0) { goto error; } // client's responsibility to drain the buffer if (buffsock->read_callback) { (*buffsock->read_callback)(buffsock, buffsock->read_buf, buffsock->cbarg); } if (buffsock->read_bytes_n && (BUFFER_HAS_DATA(buffsock->read_buf) >= buffsock->read_bytes_n)) { ev_timer_start(buffsock->loop, &buffsock->read_bytes_timer_ev); } return; error: if (buffsock->error_callback) { (*buffsock->error_callback)(buffsock, buffsock->cbarg); } buffered_socket_close(buffsock); }
int main(int argc, char* argv[]) { xmlreader r; int ret; int c; int index = 0; struct longopt opts[] = { {"help", 0, NULL, 'h'}, {"single-quote", 0, "e_char, '\''}, {"double-quote", 0, "e_char, '"'}, {"one-line", 0, NULL, 'o'}, {"compact", 0, NULL, 'c'}, {"indent", 0, NULL, 'l'}, {0}, }; errmsg_iam(argv[0]); for(;;) { c = getopt_long(argc, argv, "hsdol:c", opts, &index); if(c == -1) break; if(c == 0) continue; switch(c) { case 'h': usage(argv[0]); return 0; case 's': quote_char = '\''; break; case 'd': quote_char = '"'; break; case 'o': one_line = 1; break; case 'c': compact = 1; break; case 'l': scan_int(optarg, &indent); break; default: usage(argv[0]); return 1; } } if(argc > 1) ret = buffer_mmapprivate(&infile, argv[1]); else ret = buffer_read_fd(&infile, 0); if(ret) { errmsg_infosys("input"); return errno == ENOENT ? 127 : 1; } xml_reader_init(&r, &infile); xml_read_callback(&r, xml_read_function); buffer_putnlflush(buffer_1); buffer_close(&b); return 0; }