int wait_for_response(void) { int good_rsp = 0; u32 rsp = 0; int i; debug_printf(3, "waiting for response...\n"); inc_seq(); for (i = 0; i < 50; i++) { struct card_seq_num cardseq = read_seq_from(RSPC); debug_printf(4, "read rsp code: %x, looking for: %x raw: %x\n", rsp, eyefi_current_seq(), cardseq.seq); rsp = cardseq.seq; if (rsp == eyefi_current_seq()) { good_rsp = 1; break; } if (eyefi_debug_level > 4) { read_from(REQM); debug_printf(1, "command issued was: '%c'\n", ((char *)eyefi_buf)[0]); } usleep(300000); } if (!good_rsp) { debug_printf(1, "never saw card seq response\n"); return -1; } debug_printf(4, "got good seq (%d), reading RSPM...\n", rsp); read_from(RSPM); debug_printf(4, "done reading RSPM\n"); return 0; }
/* Receive data through socket * @param socket: file descriptor of server * @param fdout: file descriptor to write * * @return: -1 on error. Positive integer otherwise */ int receive_data(int socket, int fdout) { int aux; int dir, files; while (TRUE) { aux = receive_file(socket, fdout); if (aux == END) { read_from(socket, &dir, sizeof(int)); read_from(socket, &files, sizeof(int)); if ((DIR_R == dir) && (FILES_R == files)) { dprintf(fdout, "\nTransferencia realizada con exito.\n"); dprintf(fdout, "\nSe han transferido: - %d de %d carpetas\n", \ DIR_R, dir); dprintf(fdout, " - %d de %d archivos\n", \ FILES_R, files); } else { dprintf(fdout, \ "\nAlgunos archivos no se pudieron transferir.\n"); dprintf(fdout, "\nSe han transferido: - %d carpetas\n", DIR_R); dprintf(fdout, " - %d archivos\n", FILES_R); } break; } else if (aux < 0) { dprintf(fdout, "\nSe ha producido un error en la transferencia.\n"); return -1; } } return 0; }
void ObjectValue::read_object(DebugInfoReadStream* stream) { _klass = read_from(stream); assert(_klass->is_constant_oop(), "should be constant java mirror oop"); int length = stream->read_int(); for (int i = 0; i < length; i++) { ScopeValue* val = read_from(stream); _field_values.append(val); } }
/* * The real manager does this so we might * as well, too. */ void zero_card_files(void) { char zbuf[EYEFI_BUF_SIZE]; memset(&zbuf[0], 0, EYEFI_BUF_SIZE); // write_to(REQM, zbuf, EYEFI_BUF_SIZE); // write_to(REQC, zbuf, EYEFI_BUF_SIZE); write_to(RSPM, zbuf, EYEFI_BUF_SIZE); // write_to(RSPC, zbuf, EYEFI_BUF_SIZE); read_from(REQM); read_from(REQC); read_from(RSPM); // read_from(RSPC); }
struct card_seq_num read_seq_from(enum eyefi_file file) { struct card_seq_num *ret; read_from(file); ret = eyefi_buf; return *ret; }
ColorTable::ColorTable(pn::data_view in) { pn::file f = in.open(); read_from(f, this); if (!f.read(pn::pad(1)).eof()) { throw std::runtime_error("extra bytes at end of 'clut' resource."); } }
void read_from(pn::file_view in, ColorTable* out) { in.read(&out->seed, &out->flags, &out->size).check(); for (uint32_t i : range(uint32_t(out->size) + 1)) { in.read(pn::pad(2)).check(); read_from(in, &out->table[i]); } }
/** Similar to `read_from()`, but in case of socket error, `terminate_session()` is called using `BAD_READ_QUIT_MSG` as a quit message. @param client The client to read from. @param buf Buffer to store the message read. @param len Maximum length of the message. This is usually bounded by the size of `buf`. This parameter avoids buffer overflow. @return A positive integer denoting the number of characters read. */ inline ssize_t read_from_noerr(struct irc_client *client, char *buf, size_t len) { ssize_t msg_size; if ((msg_size = read_from(client, buf, len)) <= 0) { terminate_session(client, BAD_READ_QUIT_MSG); } return msg_size; }
int read(std::string *h, char *dst, size_t len, off_t off) { update(); auto &v = *h; if (!off) v = v_; return read_from(v, dst, len, off); }
int DiscreteProperty::read (std::string *h, char *dst, statefs_size_t len, statefs_off_t off) { if (!off) { std::lock_guard<std::mutex> lock(m_); *h = v_; } return read_from(*h, dst, len, off); }
int read(std::string *h, char *dst, size_t len, off_t off) { if (!slot_) v_ = calc(); auto &v = *h; if (!off) v = v_; return read_from(v, dst, len, off); }
void memory_model_sct::operator()(symex_target_equationt &equation) { print(8, "Adding SC constraints"); build_event_lists(equation); build_clock_type(equation); read_from(equation); write_serialization_external(equation); program_order(equation); from_read(equation); }
void load_density_contrast_grid(char *path, double *grid_delta, config_struct *conf) { FILE *file; open_file(&file, path, "rb"); size_t tot_num_of_grids = pow(conf->params.numOfAxisGrids, 3); read_from(file, tot_num_of_grids, sizeof(double), (void *)grid_delta); fclose(file); }
void load_fourier_transformed_data(char *path, fftw_complex *grid_fourier, config_struct *conf) { FILE *file; open_file(&file, path, "rb"); size_t tot_num_of_grids = pow(conf->params.numOfAxisGrids, 3); read_from(file, tot_num_of_grids, sizeof(fftw_complex), (void *)grid_fourier); fclose(file); }
int AnalogProperty::read(std::string *h, char *dst, statefs_size_t len, statefs_off_t off) { if (!h) return -ENOENT; if (!source_) return -ENOENT; if (!off) *h = source_->read(); return read_from(*h, dst, len, off); }
// return the Lisp expression in the given tokens cell read_from(std::list<std::string> & tokens) { const std::string token(tokens.front()); tokens.pop_front(); if (token == "(") { cell c(List); while (tokens.front() != ")") c.list.push_back(read_from(tokens)); tokens.pop_front(); return c; } else return atom(token); }
void memory_model_psot::operator()(symex_target_equationt &equation) { print(8, "Adding PSO constraints"); build_event_lists(equation); build_clock_type(equation); read_from(equation); write_serialization_external(equation); program_order(equation); #ifndef CPROVER_MEMORY_MODEL_SUP_CLOCK from_read(equation); #endif }
//! The method creates an input stream from the text file and passes it to the //! other Gene::read_from(). void Gene::read_from(const std::string& file_name) { auto ifs = std::ifstream(file_name); std::string line; while(std::getline(ifs, line)) { if(String::starts_with(line, "Name: ")) { auto gene_name = String::trim_outer_whitespace(String::split(line, ":", 1)[1]); if(gene_name == name()) { read_from(ifs); return; } } } throw Genetic_AI_Creation_Error(name() + " not found in " + file_name); }
network::connection ana_network_manager::read_from( network::connection connection_num, config& cfg, size_t timeout_ms) { if ( components_.empty() ) return 0; ana_component_set::iterator it; if ( connection_num == 0 ) { if ( components_.size() == 1 ) return read_from( components_.begin(), cfg, timeout_ms ); else { //Check first if there is an available buffer for (it = components_.begin(); it != components_.end(); ++it) if ( (*it)->new_buffer_ready() ) return read_from_ready_buffer( it, cfg ); // If no timeout was requested, return if (timeout_ms == 0 ) return 0; // Wait timeout_ms milliseconds to see if any component will receive something ana_multiple_receive_handler handler( components_ ); for (it = components_.begin(); it != components_.end(); ++it ) (*it)->listener()->set_listener_handler( &handler ); handler.wait_completion( timeout_ms ); for (it = components_.begin(); it != components_.end(); ++it ) (*it)->listener()->set_listener_handler( this ); if ( handler.error() ) { for (it = components_.begin(); it != components_.end(); ++it) if ( (*it)->new_buffer_ready() ) return read_from_ready_buffer( it, cfg ); // So nothing was read: return 0; } else { read_config( handler.buffer(), cfg); return handler.get_wesnoth_id(); } } } else { ana::net_id id( connection_num ); it = std::find_if( components_.begin(), components_.end(), boost::bind(std::logical_or<bool>(), (boost::bind(&ana_component::get_wesnoth_id, _1) == connection_num), (boost::bind(&ana_component::get_id, _1) == id ) ) ); //Make a broad attempt at finding it, test for both ANA's id and the assigned one. if ( it != components_.end()) return read_from(it, cfg, timeout_ms); else throw std::runtime_error("Trying a network read from an invalid component id."); } }
void testit0(void) { char c; struct testbuf tb; int i; int fdin; int fdout; //start_direct(); print_direct_status(); //enable_direct_mode(60, 120); enable_direct_mode(DIRECT_WAIT_FOREVER, DIRECT_WAIT_FOREVER); print_direct_status(); start_direct(); exit(0); //char new_cmd[] = {'O', 0x06, 0x0d, 0x0a, 0x31, 0x30, 0x2e, 0x36, 0x2e, 0x30, 0x2e, 0x31, 0x33, 0x37}; //printf("waiting...\n"); //print_transfer_status(); //exit(0); //int doagain = 1; //wlan_disable(0); //int to_test[] = {5, 8, 9, 11, 15, 16, 255, -1}; int to_test[] = {0xFF, -1}; zero_card_files(); for (i = 0; i < 100; i++) { print_transfer_status(); } exit(0); while (1) { //fprintf(stderr, "testing...\n"); for (i = 0; i < 255; i++) { int cmd = to_test[i]; if (cmd == -1) break; //zero_card_files(); card_info_cmd(cmd); printf("UNKNOWN %3d result: ", cmd); int printed = dumpbuf(eyefi_buf, 256); if (!printed) printf("\n"); print_transfer_status(); print_connected_to(); } } exit(0); scan_print_nets(); printf("WLAN enabled: %d\n", wlan_enabled()); //wlan_disable(); printf("WLAN enabled: %d\n", wlan_enabled()); for (i = 10; i <= 13; i++) { int printed; zero_card_files(); card_info_cmd(i); printf("UNKNOWN %d result:\n", i); printed = dumpbuf(eyefi_buf, 64); printf("WLAN enabled: %d\n", wlan_enabled()); } i = 0xff; card_info_cmd(i); printf("UNKNOWN %d result:", i); dumpbuf(eyefi_buf, 64); exit(3); card_info_cmd(3); printf("o3 result:\n"); dumpbuf(eyefi_buf, 64); memset(&zbuf[0], 0, EYEFI_BUF_SIZE); zbuf[0] = 'o'; zbuf[1] = 2; write_to(REQM, &zbuf[0], 16384); printf("o2 written\n"); printf("seq: %x\n", (int)eyefi_seq.seq); inc_seq(); for (i=0; i < 4; i++) { read_from(RSPC); printf("RSPC %d:\n", i); dumpbuf(eyefi_buf, 64); usleep(20000); } printf("RSPM1:\n"); read_from(RSPM); dumpbuf(eyefi_buf, 64); memset(&zbuf[0], 0, EYEFI_BUF_SIZE); write_to(RSPM, zbuf, EYEFI_BUF_SIZE); write_to(REQM, zbuf, EYEFI_BUF_SIZE); fdin = open("/home/dave/projects/eyefi/EYEFIFWU.BIN.2.0001", O_RDONLY); perror("fdin"); fdout = open("/media/EYE-FI/EYEFIFWU.BIN", O_WRONLY|O_CREAT); perror("fdout"); if (fdin <= 0 || fdout <= 0) exit(1); fd_flush(fdin); i = read(fdin, &fwbuf[0], 524288); perror("read"); if (i != 524288) exit(2); i = write(fdout, &fwbuf[0], 524288); fd_flush(fdout); perror("write"); if (i != 524288) exit(3); printf("RSPM2:\n"); read_from(RSPM); dumpbuf(eyefi_buf, 64); reboot_card(); printf("after reboot:\n"); dumpbuf(eyefi_buf, 64); printf("cic3:\n"); card_info_cmd(3); dumpbuf(eyefi_buf, 64); printf("cic2:\n"); card_info_cmd(2); dumpbuf(eyefi_buf, 64); memset(&zbuf[0], 0, EYEFI_BUF_SIZE); write_to(RSPM, zbuf, EYEFI_BUF_SIZE); write_to(REQM, zbuf, EYEFI_BUF_SIZE); printf("cic2v2:\n"); card_info_cmd(2); dumpbuf(eyefi_buf, 64); exit(0); strcpy(tb.name, "www.sr71.net/"); tb.l1 = strlen(tb.name); for (i = 0; i < 10; i++) { tb.cmd = 'O'; tb.l1 = i; write_struct(RSPM, &z); write_struct(REQM, &tb); wait_for_response(); printf("buffer after O %d:\n", i); dumpbuf(eyefi_buf, 64); printf("----------------\n"); write_struct(REQM, &tb); card_info_cmd(i); printf("card info(%d):\n", i); dumpbuf(eyefi_buf, 64); printf("-----------\n"); } return; strcpy(tb.name, "/public/eyefi/servname"); strcpy(tb.name, "/config/networks.xml"); //tb.len = strlen(tb.name); tb.l1 = 0; for (c = 'O'; c <= 'O'; c++) { tb.cmd = c; write_struct(REQM, &tb); wait_for_response(); printf("dumping buffer:\n"); dumpbuf(eyefi_buf, 64); printf("buffer dump done\n"); } }
int main(void) { struct protocol_double_sha dsha; struct protocol_net_address netaddr; int fds[2]; char *p, *mem1, *mem2, *mem3; int status; size_t maxmem = sizeof(struct log_entry) * 4 + 25 + 25 + 28 + 161; void *ctx = tal(NULL, char); struct log *log = new_log(ctx, NULL, "PREFIX", LOG_BROKEN+1, maxmem); assert(tal_parent(log) == ctx); my_time.ts.tv_sec = 1384064855; my_time.ts.tv_nsec = 500; log_debug(log, "This is a debug %s!", "message"); my_time.ts.tv_nsec++; log_info(log, "This is an info %s!", "message"); my_time.ts.tv_nsec++; log_unusual(log, "This is an unusual %s!", "message"); my_time.ts.tv_nsec++; log_broken(log, "This is a broken %s!", "message"); my_time.ts.tv_nsec++; log_add(log, "the sha is "); memset(&dsha, 0xFF, sizeof(dsha)); log_add_struct(log, struct protocol_double_sha, &dsha); log_add(log, " and the address is: "); memset(netaddr.addr, 0, 10); memset(netaddr.addr + 10, 0xFF, 2); netaddr.addr[12] = 127; netaddr.addr[13] = 0; netaddr.addr[14] = 0; netaddr.addr[15] = 1; netaddr.port = cpu_to_le16(65000); netaddr.time = time_now().ts.tv_sec - 10; log_add_struct(log, struct protocol_net_address, &netaddr); /* Make child write log, be sure it's correct. */ pipe(fds); switch (fork()) { case -1: err(1, "forking"); case 0: close(fds[0]); setenv("TZ", "UTC", 1); log_to_file(fds[1], log); tal_free(ctx); exit(0); } close(fds[1]); p = read_from(ctx, fds[0]); /* Shouldn't contain any NUL chars */ assert(strlen(p) + 1 == tal_count(p)); assert(tal_strreg(p, p, "PREFIX ([0-9])* bytes, Sun Nov 10 06:27:35 2013\n" "\\+0\\.000000500 DEBUG: This is a debug message!\n" "\\+0\\.000000501 INFO: This is an info message!\n" "\\+0\\.000000502 UNUSUAL: This is an unusual message!\n" "\\+0\\.000000503 BROKEN: This is a broken message!the sha is ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and the address is: ::ffff:127\\.0\\.0\\.1:65000 \\(10 seconds old\\)\n\n", &mem1)); assert(atoi(mem1) < maxmem); tal_free(p); wait(&status); assert(WIFEXITED(status) && WEXITSTATUS(status) == 0); /* This cleans us out! */ log_debug(log, "Overflow!"); /* Make child write log, be sure it's correct. */ pipe(fds); switch (fork()) { case -1: err(1, "forking"); case 0: close(fds[0]); setenv("TZ", "UTC", 1); log_to_file(fds[1], log); tal_free(ctx); exit(0); } close(fds[1]); p = read_from(ctx, fds[0]); /* Shouldn't contain any NUL chars */ assert(strlen(p) + 1 == tal_count(p)); assert(tal_strreg(p, p, "PREFIX ([0-9]*) bytes, Sun Nov 10 06:27:35 2013\n" "\\.\\.\\. 4 skipped\\.\\.\\.\n" "\\+0.000000504 DEBUG: Overflow!\n" "\\+0.000000504 DEBUG: Log pruned 4 entries \\(mem ([0-9]*) -> ([0-9]*)\\)\n\n", &mem1, &mem2, &mem3)); assert(atoi(mem1) < maxmem); assert(atoi(mem2) >= maxmem); assert(atoi(mem3) < maxmem); tal_free(ctx); wait(&status); assert(WIFEXITED(status) && WEXITSTATUS(status) == 0); return 0; }
int main(int argc, char const *argv[]) { // string.buffer = read_from("/Volumes/Flash/0ws0110.txt"); // string.buffer = read_from("/Volumes/Flash/pgwht04.txt"); // string.buffer = read_from("/Users/michael/Dropbox/University/dev/thesis/test3.txt"); // string.buffer = read_from("/Users/michael/Dropbox/University/dev/thesis/test2.txt"); assert_in(1, "ab", "abcabxabcd$", 3); assert_in(1, "x", "abcabxabcd$", 1); assert_in(1, "a", "abcabxabcd$", 3); assert_in(2, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test.txt"), 9); assert_in(2, "**", read_from("/Users/michael/Dropbox/University/dev/thesis/test.txt"), 5); assert_in(2, "**T", read_from("/Users/michael/Dropbox/University/dev/thesis/test.txt"), 2); assert_in(3, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test3.txt"), 8); assert_in(3, "**", read_from("/Users/michael/Dropbox/University/dev/thesis/test3.txt"), 4); assert_in(3, "**", read_from("/Users/michael/Dropbox/University/dev/thesis/test3.txt"), 4); assert_in(3, "***", read_from("/Users/michael/Dropbox/University/dev/thesis/test3.txt"), 2); assert_in(4, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test4.txt"), 10); assert_in(5, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test2.txt"), 38); assert_in(5, "***", read_from("/Users/michael/Dropbox/University/dev/thesis/test2.txt"), 30); assert_in(6, "English", read_from("/Volumes/Flash/0ws0110.txt"), 27); assert_in(7, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test6.txt"), 9); assert_in(7, "***", read_from("/Users/michael/Dropbox/University/dev/thesis/test6.txt"), 3); assert_in(8, "*", read_from("/Users/michael/Dropbox/University/dev/thesis/test8.txt"), 19); }
MSG_data::MSG_data( std::ifstream &in, MSG_header &header) { read_from(in, header); }
/* Receive file through socket * @param socket: file descriptor of server * @param fdout: file descriptor to write * * @return: -1 on error. Positive integer otherwise */ int receive_file(int socket, int fdout) { file_t file; char buffer[SIZE_BUF]; int numb_bytes; int recibed = 0; char type; int offset; int read_until; /* read type of file to receive */ bzero(&file, sizeof(file_t)); read_from(socket, &type, sizeof(char)); read_from(socket, &file.size_string, sizeof(int)); read_from(socket, &file.name_of_file, file.size_string); /* receiving file */ if (type == (char) FILE) { read_from(socket, &file.size_file, sizeof(int)); offset = file.size_file; dprintf(fdout, "\tReceiving '%s'...", file.name_of_file); /* create file with user permissions */ if ((file.fd_file = creat(file.name_of_file, S_IRWXU)) < 0) error("ERROR"); while (TRUE) { bzero(buffer, SIZE_BUF); if (SIZE_BUF < offset) read_until = SIZE_BUF; else read_until = offset; if ((numb_bytes = read(socket, buffer, read_until)) < 0) { dprintf(fdout, "\tbytes = %d\n", numb_bytes); error("\tNo se pudo leer el archivo: "); break; } /* write readed bytes in file */ write(file.fd_file, buffer, numb_bytes); offset -= numb_bytes; recibed += numb_bytes; /* printf("Recibidos: %.3fkB (%.3f/%.3f) kB\n", numb_bytes/1000., recibed/1000., file.size_file/1000.); */ if (offset <= 0) break; } close(file.fd_file); if (recibed != file.size_file) { error("No se pudo recibir el archivo."); return -1; } else { dprintf(fdout, " %.3f/%.3f kB [%.3f%%]\n", recibed/1000., \ file.size_file/1000., (recibed*100.)/file.size_file); FILES_R++; return recibed; } /* receiving directory */ } else if (type == (char) DIRECTORY) { mkdir(file.name_of_file, 0700); dprintf(fdout, "\tCreating '%s'...\n", file.name_of_file); DIR_R++; return 0; /* end transmission */ } else if (type == (char) END) { return 2; } return -1; }
// return the Lisp expression represented by the given string cell read(const std::string & s) { std::list<std::string> tokens(tokenize(s)); return read_from(tokens); }
enum {loop_end,still_going} service_select_request (int x_fd) { size_t i, j; size_t selects_num=-1; //Create the descriptor set (creation can't be static due to inclusion condition). int select_max_arg=0; //Minimum legal fd value. FD_ZERO(&backup_set); for (i=0; i<MACHINE_NUM; i++) { for (j=0; j<SENSOR_NUM; j++) { //Remote testing: MyRA[i][j].status==online -- Normal operation: MyRA[i][j].status!=error if (MyRA[i][j].status==online) //only non-error streams FD_SET(MyRA[i][j].file_d, &backup_set); select_max_arg=(MyRA[i][j].file_d>select_max_arg) ? MyRA[i][j].file_d : select_max_arg; } } FD_SET(x_fd, &backup_set); select_max_arg=(select_max_arg>x_fd) ? select_max_arg : x_fd; select_max_arg++; check_set=backup_set; //Do the select. DEBUG_(fprintf(log_stream, "Select called with max_fd %d.\n", select_max_arg)); if (select(select_max_arg, &check_set, NULL, NULL, NULL)==-1) goto error_check; //Check the descriptor set. for (i=0; i<MACHINE_NUM; i++) { for (j=0; j<SENSOR_NUM; j++) { //Normal requests serviced here. if (FD_ISSET(MyRA[i][j].file_d, &check_set)) { DEBUG_(fprintf(stderr, "Request: Descriptor [%d, %d].\n", i, j)); read_from(i, j); } } } //X requests serviced here. if (FD_ISSET(x_fd, &check_set)) { DEBUG_(fprintf(stderr, "Request X: ")); char RetV[2]={0}; XNextEvent(_D, &_E); if (_E.type==Expose) { display_update(); } else if (_E.type == KeyPress) { XLookupString(&_E.xkey, RetV, 1, &key, NULL); if (key=='q' || key=='Q') return loop_end; } } else if (MyRA_Updated==1 && selects_num>=updates_every) { //Non-event triggered updates on multiples. display_update(); usleep(10000); selects_num=0; } //Normal exit point. return still_going; //Return 'loop_end' when all sensor fds are non-responsive. error_check: fprintf(log_stream, "Select call returned with %d: ", errno); switch (errno) { case EBADF: fprintf(log_stream, "EBADF: Terminating.\n"); break; case EINTR: fprintf(log_stream, "EINTR: Relooping.\n"); return still_going; break; case EINVAL: fprintf(log_stream, "EINVAL: Terminating.\n"); break; case ENOMEM: fprintf(log_stream, "ENOMEM: Relooping after 5 seconds.\n"); sleep(5); return still_going; break; default: fprintf(log_stream, "Undefined error: Terminating.\n"); } //Default error exit point. return loop_end; }