int main (int argc, char *argv []) { bin_name = strip_file_path (argv[0]); if (argc < 2 || argc > 3) { display_usage (); return -1; } if (! load_config (argv[1]) ) return -1; if (argc == 3) { if (!load_body (argv[2])) { coprintf ("bad body file"); return -1; } } coprintf ( "Sending one mail from [%s] to [%s] via [%s]", main_sender, main_dest, main_server ); smt_init (); /* Initialise SMT kernel */ /* Application is latent - initialise it */ if (agent_lookup (SMT_SOCKET) == NULL) sock_init (); if (agent_lookup (AGENT_NAME) == NULL) tstsmtp_init (); thread_create (AGENT_NAME, ""); /* Application is active - execute it */ smt_exec_full (); /* Run until completed */ /* Application is halted - terminate it */ smt_term (); /* Shut-down SMT kernel */ sock_term (); mem_free (main_server); mem_free (main_sender); mem_free (main_dest); mem_free (main_body); printf ("Allocs=%ld frees=%ld\n", mem_allocs (), mem_frees ()); mem_assert (); return (0); }
//**************************************************************** // load_coarse void Finger::load_coarse( px::world_type* world, const char* filename ) { partix::SoftVolume< D3DXPartixTraits >* v = load_body( filename ); mesh_.reset( v->get_mesh() ); coarse_.reset( v ); //coarse_->set_restore_factor( 0.2f ); //coarse_->set_stretch_factor( 0.8f ); coarse_->set_name( "finger" ); coarse_->set_drag_factor( 0.4f ); coarse_->teleport( D3DXVECTOR3( 0, 2.0f, -10.0f ) ); world->add_body( coarse_.get() ); }
int fill_mem_obj(request *rq,struct mem_obj *obj,struct mem_obj *old_obj) { // struct buff *to_server_request = NULL; char *answer=NULL; char *fake_header; head_info m_head; int fake_header_len=0; int r=CONNECT_ERR; char mk1123buff[50]; ERRBUF ; memset(&m_head,0,sizeof(m_head)); if(srv_connect(rq)<=0) goto error; /* to_server_request = alloc_buff(4*CHUNK_SIZE); if ( !to_server_request ) { // change_state(obj, OBJ_READY); obj->flags |= FLAG_DEAD; goto error; } */ // stored_obj(NULL); // printf("rq->if_modified_since=%d,obj->times.last_modified=%d\n",rq->if_modified_since,old_obj->times.last_modified); if(old_obj && !TEST(rq->flags,RQ_HAS_IF_MOD_SINCE)) { if(old_obj->times.last_modified) { if (!mk1123time(old_obj->times.last_modified, mk1123buff, sizeof(mk1123buff)) ) { klog(ERR_LOG,"cann't mk1123time obj obj->times.date=%d.\n",old_obj->times.last_modified); goto error; } } else { if (!mk1123time(obj->created, mk1123buff, sizeof(mk1123buff)) ) { klog(ERR_LOG,"cann't mk1123time obj created=%d.\n",old_obj->created); goto error; } } fake_header_len=19+sizeof(mk1123buff)+4; fake_header = (char *)malloc(fake_header_len); if ( !fake_header ) { goto error; //error goto validate_err; } // printf("fake_header=%s\n",fake_header); memset(fake_header,0,fake_header_len); snprintf(fake_header,fake_header_len-1, "If-Modified-Since: %s\r\n", mk1123buff); answer=build_direct_request("GET", &rq->url, fake_header, rq, 0); free(fake_header); // printf("client have no if-modified-since.\n"); } else { answer=build_direct_request("GET",&rq->url,NULL,rq,0);//连接远程主机 } // printf("answer=%s\n",answer); if ( !answer ) { klog(ERR_LOG,"no mem to alloc.\n"); goto error; } /* if ( attach_data(answer, strlen(answer), to_server_request) ) { free_container(to_server_request); goto error; } if(answer){ free(answer); answer = NULL; } */ r = rq->client->send(answer); // free(answer); // free_container(to_server_request); to_server_request = NULL; // printf("send data to remote is:%s",to_server_request->data); if ( r <=0 ) {//send error say_bad_request("Can't send","", ERR_TRANSFER, rq); // printf("cann't send to server.\n"); //printf("errno=%d\n",ERRNO); goto error; } r=load_head(rq,obj,m_head); switch(r) { case HEAD_OK: if(load_body(rq,obj)<=0) { //printf("load body failed.\n"); r=CONNECT_ERR; goto error; } goto done; case CONNECT_ERR: //printf("load head failed.\n"); goto error; case HEAD_NOT_MODIFIED: if(old_obj && !TEST(rq->flags,RQ_HAS_IF_MOD_SINCE)) { goto error; } else { if(rq->server->send(m_head.head,m_head.len)<0) goto error; } // printf("%s\n",m_head.head); break; default: // printf("obj->content_length=%d,path=%s\n",obj->content_length,obj->url.path); if(m_head.head) { if(rq->server->send(m_head.head,m_head.len)<0) goto error; if(create_select_pipe(rq->server,rq->client,conf.time_out[HTTP],0,-1)==-2) r=1; } } error: IF_FREE(answer); IF_FREE(m_head.head); rq->client->close(); destroy_obj(obj,0); return r; done: IF_FREE(answer); IF_FREE(m_head.head); rq->client->close(); if(!old_obj) stored_obj(obj); return r; };
static SolarSystem *load_from_config(ALLEGRO_CONFIG *cfg) { SolarSystem *solsys; char **primary_names; const char *name; long num_bodies; ALLEGRO_CONFIG_SECTION *sec; int i; /* First pass: Determine the number of bodies in the file */ num_bodies = 0; sec = NULL; while ((name = get_next_config_section(cfg, &sec)) != NULL) { if (name[0] != '\0') num_bodies++; } if (num_bodies == 0) return NULL; /* Empty solarsystem */ solsys = ralloc_size(NULL, sizeof(SolarSystem) + num_bodies*sizeof(Body)); if (solsys == NULL) return NULL; solsys->num_bodies = num_bodies; primary_names = ralloc_array(solsys, char *, num_bodies); if (primary_names == NULL) { ralloc_free(solsys); return NULL; } /* Second pass: Load all celestial bodies */ i = 0; sec = NULL; while ((name = get_next_config_section(cfg, &sec)) != NULL && i < num_bodies) { if (name[0] == '\0') continue; solsys->body[i].ctx = solsys; if (!load_body(cfg, name, &solsys->body[i], &primary_names[i])) { log_err("Couldn't load body %s\n", name); ralloc_free(solsys); return NULL; } i++; } if (i < num_bodies) log_err("Internal consistency error\n"); /* Third pass: Connect each satellite body to its primary */ for (i = 0; i < num_bodies; i++) { Body *body = &solsys->body[i]; char *primary_name = primary_names[i]; if (primary_name == NULL) /* Independent body */ continue; /* Look for the primary */ body->primary = NULL; for (int j = 0; j < num_bodies; j++) { Body *body2 = &solsys->body[j]; if (strcmp(primary_name, body2->name) == 0) { body->primary = body2; break; } } if (body->primary == NULL) { log_err("Couldn't find %s's primary: %s\n", body->name, primary_name); ralloc_free(solsys); return NULL; } ralloc_free(primary_name); primary_name = NULL; /* Won't ever be used again */ body->primary->num_satellites++; body->primary->satellite = reralloc(solsys, body->primary->satellite, Body *, body->primary->num_satellites); if (body->primary->satellite == NULL) { log_err("Out of memory\n"); ralloc_free(solsys); return NULL; } body->primary->satellite[body->primary->num_satellites - 1] = body; body->orbit.epoch = 0; body->orbit.period = M_TWO_PI * sqrt(CUBE(body->orbit.SMa) / body->primary->grav_param); body->orbit.plane_orientation = quat_euler(RAD(body->orbit.LAN), RAD(body->orbit.Inc), RAD(body->orbit.APe)); } ralloc_free(primary_names); return solsys; }