/*************************************************************************** * Function: int recv_text(conn_data *conn) * * Description: * Read data from the file descriptor associated with a connection and * add it to the connection's input buffer. If the read returns -1 and either * 1) errno isn't set to EWOULDBLOCK (BSD), or 2) the OS is Sys V, an error has * occured and ERROR is returned. If errno _is_ EWOULDBLOCK (under BSD), or the * return value was 0 (under Sys V), no data remains to be read from the * socket. Under normal conditions return the number of bytes received. **************************************************************************/ static int recv_text(conn_data *conn) { int count, total = 0, result, length; /* * Keep reading data from the socket until there's nothing left to read. */ do { length = strlen(conn->input_buf); if ((count = read(conn->fd, conn->input_buf + length, MAX_INPUT_LEN - length)) < 0) { #ifdef BSD if (errno == EWOULDBLOCK) return(total); #endif return(ERROR); } /* * If anything was read in, call filter_input to move it to the input list. */ if (count != 0) { total += count; conn->input_buf[length + count] = '\0'; result = filter_input(conn); if (result == ERROR) return(ERROR); } } while (length + count == MAX_INPUT_LEN); return(total); }
void filter_changesets (database_t * db, changeset_t ** serial, changeset_t ** serial_end, const char * filter_command) { // Set up a pipeline for running the subprocess and sending the data to it. struct filter_context context = { db, serial, serial_end }; pipeline * pl = pipeline_new(); pipeline_command ( pl, pipecmd_new_function ("filter source", filter_output, NULL, &context)); pipeline_command_argstr (pl, filter_command); pipeline_want_out (pl, -1); fflush (NULL); // We're forking... pipeline_start (pl); filter_input (db, pipeline_get_outfile (pl)); int res = pipeline_wait (pl); if (res != 0) fatal ("filter subprocess gave error: %i\n", res); pipeline_free (pl); }