void streaming_sort() { int capacity = 256; int nitems = 0,i=0; int buffer[capacity]; stream_init(); // GET READY FILE*file = open_infile(infile_name); while(!feof(file) && !ferror(file)) { int success = fscanf(file,"%d",buffer + i); if(success != 1) break; nitems++; i++; if(i == capacity) { stream_data( buffer, i); // SOME DATA FOR YOU i = 0; } } if(i) stream_data( buffer, i); // HAVE A BIT MORE DATA stream_end(); // DONE fclose(file); }
int store_data(const char *data_dir, const char *index_path, const char *data_path, int infd, ssize_t expected_length) { DataFiles df; if (!create_or_open_datafiles(index_path, data_path, &df)) { return 0; } off_t data_offset = lseek(df.data_fd, 0, SEEK_END); if (data_offset == (off_t)-1) { perror("Failed to find data file offset"); goto fail; } SHA_CTX hash_ctx; uint8_t sha1_buf[SHA_DIGEST_LENGTH]; char sha1_hex_buf[2*SHA_DIGEST_LENGTH + 1]; if (SHA1_Init(&hash_ctx) == 0) { fprintf(stderr, "Failed to init SHA1 hash\n"); goto fail; } off_t data_len = 0; int status = stream_data(infd, df.data_fd, &data_len, expected_length, &hash_ctx); if (SHA1_Final(sha1_buf, &hash_ctx) == 0) { fprintf(stderr, "Failed to finish SHA1 hash\n"); goto fail; } if (!status) { goto fail; } if (fdatasync(df.data_fd) == -1) { perror("Failed to sync data file to disk"); goto fail; } to_hex(sha1_buf, SHA_DIGEST_LENGTH, sha1_hex_buf); if (!write_index(df.index_fd, data_offset, data_len, sha1_hex_buf)) { goto fail; } if (fdatasync(df.index_fd) == -1) { perror("Failed to sync index file to disk"); goto fail; } if (df.is_new_file) { write_site_index(data_dir); // Ignore potential error. It was logged. } close_datafiles(df); return 1; fail: close_datafiles(df); return 0; }
stress_data::stress_data(string &i_sdata): files_w_data(i_sdata) { ifstream stream_data(files_w_data); int ct = 0; int tn_points = 0; while(!stream_data.eof() && !is_file_empty(stream_data)) { string tmp_string; stream_data >> tmp_string; data_points<data_point_with_stress> tmp_data(tmp_string, ct++); data_points_collection.insert({tmp_string, tmp_data}); tn_points += tmp_data.number_of_points; } num_of_zones = ct; total_num_of_points = tn_points; }
static void server_handle_input(struct server_connection *conn, const unsigned char *data, size_t size) { string_t *str; size_t i, start; if (printing_conn == conn) { /* continue printing */ } else if (printing_conn == NULL) { printing_conn = conn; } else { /* someone else is printing. don't continue until it goes away */ io_remove(&conn->io); return; } if (data[size-1] == '\001') { /* last character is an escape */ size--; } str = t_str_new(128); for (i = start = 0; i < size; i++) { if (data[i] == '\n') { if (i != start) { i_error("doveadm server sent broken print input"); server_connection_destroy(&conn); return; } conn->state = SERVER_REPLY_STATE_RET; i_stream_skip(conn->input, i + 1); print_connection_released(); return; } if (data[i] == '\t') { server_flush_field(conn, str, data + start, i - start); start = i + 1; } } if (start != size) { conn->streaming = TRUE; stream_data(str, data + start, size - start); } i_stream_skip(conn->input, size); }
static void server_flush_field(struct server_connection *conn, string_t *str, const unsigned char *data, size_t size) { if (conn->streaming) { conn->streaming = FALSE; if (size > 0) stream_data(str, data, size); doveadm_print_stream("", 0); } else { const char *text; str_truncate(str, 0); str_append_n(str, data, size); text = str_tabunescape(str_c_modifiable(str)); doveadm_print(text); } }
void loop() { recieve_commands(); if (!docking && !auto_cover) { execute_move(); interaction(); } if (move_time == 0) { if (stream) // @t stream_data(); if (exp_auto) // @a feb_experiment_scanning();//katie_auto(); if (auto_on ) // @u katie_auto(); // if (auto_cover){ /// send state message at a regular interval during script // int diff = millis() - picture_timer; // if (diff > 3000) { // send_state("picture timer"); // picture_timer = millis(); // } // } if (exp_stream ) // @e // arduino_hub_stream(); // experiment_dec_2013 if (debug_stream ) // @g stream_debug_sensors(); } BUTTONS_STATE = COIFetchSingleSensor(BUTTONS); if (PLAY_BUTTON(BUTTONS_STATE) == HIGH) { delay(200); COIChangeMode(CMD_MODE_PASSIVE); play_toggle = true; send_response("SAFE MODE ON", 1); } if ((CHARGING_SOURCE_STATE == 1 || CHARGING_SOURCE_STATE == 2) && play_toggle == true ) { charge_toggle = true; play_toggle = false; send_response("CHARGING SOURCE DETECTED", 1); } if ((CHARGING_SOURCE_STATE == 0) && (OI_MODE_STATE == OI_PASSIVE) && (charge_toggle == true) && (play_toggle == false)){ COIChangeMode(CMD_MODE_FULL); charge_toggle = false; send_response("FULL MODE ON", 1); } update_battery_sensors(); charger(); if (!digitalRead(INPUT_20) && !auto_cover ) { // check to see if not in script so command does not interfere //update_create_fast_sensors(); // so that collision detection works BUMPS_WHEEL_DROPS_STATE = COIFetchSingleSensor(BUMPS_WHEELS); //charger(); // detects charger (once this works move make nest it deeper in framework) } if ((BUMPS_WHEEL_DROPS_STATE > 0 && BUMPS_WHEEL_DROPS_STATE < 4) && bp == false) { bp = true; send_state("collision detected"); } if ((BUMPS_WHEEL_DROPS_STATE == 0) && bp == true) { bp = false; send_state("bumper released"); } //heading = update_header(heading, COIFetchSingleSensor(ANGLE_SINCE_LAST); // Mostly for testing, for now delay(20); // serial gets overrun if no delay }
int main(void) { struct vlc_http_stream *s, *s2; struct vlc_http_msg *m; struct block_t *b; uint_fast32_t sid = -1; /* Second guessed stream IDs :-/ */ conn_create(); conn_destroy(); conn_create(); conn_send(vlc_h2_frame_ping(42)); conn_expect(PING); /* Test rejected stream */ sid += 2; s = stream_open(); assert(s != NULL); conn_expect(HEADERS); conn_send(vlc_h2_frame_rst_stream(sid, VLC_H2_REFUSED_STREAM)); m = vlc_http_stream_read_headers(s); assert(m == NULL); b = vlc_http_stream_read(s); assert(b == NULL); vlc_http_stream_close(s, false); conn_expect(RST_STREAM); /* Test accepted stream */ sid += 2; s = stream_open(); assert(s != NULL); stream_reply(sid, false); m = vlc_http_msg_get_initial(s); assert(m != NULL); vlc_http_msg_destroy(m); stream_data(3, "Hello ", false); /* late data */ stream_data(3, "world!", true); conn_expect(HEADERS); conn_expect(RST_STREAM); conn_expect(RST_STREAM); conn_expect(RST_STREAM); /* Test continuation then accepted stream */ sid += 2; s = stream_open(); assert(s != NULL); stream_continuation(sid); m = vlc_http_msg_get_initial(s); assert(m != NULL); assert(vlc_http_msg_get_status(m) == 100); stream_reply(sid, false); m = vlc_http_msg_iterate(m); assert(m != NULL); stream_data(sid, "Hello ", false); stream_data(sid, "world!", true); stream_data(sid, "Stray message", false); /* data after EOS */ b = vlc_http_msg_read(m); assert(b != NULL); block_Release(b); b = vlc_http_msg_read(m); assert(b != NULL); block_Release(b); b = vlc_http_msg_read(m); assert(b == NULL); vlc_http_msg_destroy(m); conn_expect(HEADERS); conn_expect(RST_STREAM); conn_expect(RST_STREAM); /* Test accepted stream after continuation */ sid += 2; s = stream_open(); assert(s != NULL); stream_continuation(sid); stream_reply(sid, true); sid += 2; s2 = stream_open(); /* second stream to enforce test timing/ordering */ assert(s2 != NULL); stream_reply(sid, true); m = vlc_http_msg_get_initial(s2); assert(m != NULL); vlc_http_msg_destroy(m); m = vlc_http_msg_get_initial(s); assert(m != NULL); assert(vlc_http_msg_get_status(m) == 200); b = vlc_http_msg_read(m); assert(b == NULL); vlc_http_msg_destroy(m); conn_expect(HEADERS); conn_expect(HEADERS); conn_expect(RST_STREAM); conn_expect(RST_STREAM); /* Test nonexistent stream reset */ conn_send(vlc_h2_frame_rst_stream(sid + 100, VLC_H2_REFUSED_STREAM)); /* Test multiple streams in non-LIFO order */ sid += 2; s = stream_open(); assert(s != NULL); sid += 2; s2 = stream_open(); assert(s2 != NULL); stream_reply(sid, false); stream_reply(sid - 2, true); stream_data(sid, "Discarded", false); /* not read data */ m = vlc_http_msg_get_initial(s); assert(m != NULL); vlc_http_msg_destroy(m); m = vlc_http_msg_get_initial(s2); assert(m != NULL); vlc_http_msg_destroy(m); conn_expect(HEADERS); conn_expect(HEADERS); conn_expect(RST_STREAM); conn_expect(RST_STREAM); /* might or might not seen one or two extra RST_STREAM now */ /* Test graceful connection termination */ sid += 2; s = stream_open(); assert(s != NULL); conn_send(vlc_h2_frame_goaway(sid - 2, VLC_H2_NO_ERROR)); m = vlc_http_stream_read_headers(s); assert(m == NULL); /* Test stream after connection shut down */ assert(stream_open() == NULL); /* Test releasing connection before stream */ conn_destroy(); vlc_http_stream_close(s, false); return 0; }