int main(void) { char *command, *response; int success; int in_pipe = open_for_reading(IN_PIPE); int out_pipe = open_for_reading(OUT_PIPE); for(;;) { success = read_command(command); if (success) { run_command(command, response); send_response(response); success = 0; } } }
/** Open interface for reading with identifier format string. * This will create a new interface instance of the given type. The result can be * casted to the appropriate type. * @param interface_type type of the interface * @param identifier identifier format string of the interface * @param ... arguments for identifier format * @return new fully initialized interface instance of requested type * @exception OutOfMemoryException thrown if there is not enough free space for * the requested interface. */ Interface * BlackBoard::open_for_reading_f(const char *interface_type, const char *identifier, ...) { va_list arg; va_start(arg, identifier); Interface *iface = open_for_reading(interface_type, format_identifier(identifier, arg).c_str()); va_end(arg); return iface; }
int main(void) { char *response; int received = 0; mkfifo(IN_PIPE, 0666); mkfifo(OUT_PIPE, 0666); int in_pipe = open_for_reading(IN_PIPE); int out_pipe = open_for_reading(OUT_PIPE); send_command(out_pipe); while (!received) { if (read_response(in_pipe, response) <= 0) { received = 1; printf("received response"); } } }
Model::Model *Storage::Binary::read_model() { open_for_reading(); // read the 3 model components Model::Model *model = new Model::Model(); model->data_set = read_data_set(); model->classifier = read_classifier(model->data_set); model->text_pipeline = read_text_pipeline(); file.close(); return model; }
void example_result() { auto result01 = open_for_reading("/dev/null"); assert(result01.ok()); assert(result01.value() != nullptr); assert(fclose(result01.take()) == 0); (void) result01; auto result02 = open_for_reading("/dev/mem"); assert(!result02.ok()); assert(result02.bad()); assert(result02.error() == EACCES); (void) result02; assert(divide(1, 1).ok()); assert(divide(1, 1).value() == 1); assert(divide(1, 1).take() == 1); assert(!divide(1, 0).ok()); assert(divide(1, 0).take_or(1) == 1); assert(divide(1, 0).error() == "division by zero"); }
static int smb_open(struct http_data* h,unsigned short* remotefilename,size_t fnlen,struct stat* ss,enum smb_open_todo todo) { char localfilename[1024]; int64 fd; size_t i,j; char* x; if (ip_vhost(h)==-1 || fnlen/2>sizeof(localfilename)) return -1; fd=-1; for (j=0; fd==-1 && j<2; ++j) { if (j==0) { /* first try latin1 */ if (utf16tolatin1(localfilename,sizeof(localfilename),remotefilename,fnlen)==0) continue; } else { if (utf16toutf8(localfilename,sizeof(localfilename),remotefilename,fnlen)==0) break; } #if 0 { const char* what[] = {"OPEN","STAT","CHDIR"}; printf("trying \"%s\" for %s\n",localfilename,what[todo]); } #endif for (i=0; localfilename[i]; ++i) { if (localfilename[i]=='\\') localfilename[i]='/'; } x=(char*)localfilename; while ((x=strstr(x,"/."))) x[1]=':'; x=(char*)localfilename; while (*x=='/') ++x; if (todo==WANT_STAT) { if (*x==0) x="."; if (stat(x,ss)==0) { fd=0; break; } } else if (todo==WANT_OPEN) { if (*x==0) x="."; if (open_for_reading(&fd,x,ss)) break; } else if (todo==WANT_CHDIR) { if (!*x || chdir(x)==0) { fd=0; break; } } } return fd; }
uint8_t read_uint8(char *id) { uint8_t i=0; if(Add_Pipe(id,8)) return i; FILE *F = open_for_reading(id); while(fread(&i, sizeof(uint8_t), 1, F) == 0) { usleep(1000); } fclose(F); send_ack(id); return i; }
void wait_for_ack(char* id) { char txt; char* buffer = (char*) malloc(strlen(id) + 5); sprintf(buffer,"%s.ack",id); FILE *F = open_for_reading(buffer); int n = 0; while((n=fread(&txt, sizeof(char), 1, F)) == 0); fclose(F); assert(txt == 0); }
void* read_pointer(char *id) { void* i = NULL; if(Add_Pipe(id,8*sizeof(void*))) return i; FILE *F = open_for_reading(id); while(fread(&i, sizeof(void*), 1, F) == 0) { usleep(1000); } fclose(F); send_ack(id); return i; }
float read_float32(char *id) { float f = 0.0; if(Add_Pipe(id,32)) return f; FILE *F = open_for_reading(id); while(fread(&f, sizeof(float), 1, F) == 0) { usleep(1000); } fclose(F); send_ack(id); return f; }
double read_float64(char *id) { double f = 0.0; if(Add_Pipe(id,64)) return f; FILE *F = open_for_reading(id); while(fread(&f, sizeof(double), 1, F) == 0) { usleep(1000); } fclose(F); send_ack(id); return f; }
// ------------------------------------------ // public read & write methods // ------------------------------------------ DataSet::DataSet *Storage::Binary::read() { open_for_reading(); DataSet::DataSet *data_set = read_data_set(); file.close(); return data_set; }