void dgramtesttrigger( void) { PState *ps = (PState *)dgramtestprotocol->state; if ( x_server ) { xError("Starting server"); evDetach(evSchedule(evAlloc(dgramtestprotocol->path), server, dgramtestprotocol, 0)); } else if ( x_client ) { d_area_s.prod = 0; d_area_s.cons = 0; #if MACH_KERNEL (void)kmem_alloc(kernel_map, (vm_offset_t *)&d_area_s.addr, DUMP_AREA_SIZE); #else /* MACH_KERNEL */ d_area_s.addr = (char *)pathAlloc(dgramtestprotocol->path, DUMP_AREA_SIZE); #endif /* MACH_KERNEL */ if (!d_area_s.addr) { xError("dgramtest: couldn't allocate dump area\n"); pathFree(ps); return; } xError("Starting client"); evDetach(evSchedule(evAlloc(dgramtestprotocol->path), client, dgramtestprotocol, 0)); } else printf("Pls. assert either x_client or x_server\n"); }
void server( Event ev, void *arg ) { XObj self = (XObj)arg; XObj llp; Part_s participants, *p; long serverport = SERVERPORT; llp = xGetDown(self, 0); if ( ! xIsProtocol(llp) ) { xError("Test protocol has no lower protocol"); return; } self->opendone = saveServerSessn; self->demux = serverDemux; p = &participants; partInit(p, 1); partPush(*p, ANY_HOST, 0); partPush(*p, &serverport, sizeof(long)); if ( xOpenEnable(self, self, llp, p) == XK_FAILURE ) { sprintf(errBuf, "%s server can't openenable lower protocol", PROT_STRING); xError(errBuf); } else { sprintf(errBuf, "%s server done with xopenenable", PROT_STRING); xError(errBuf); } }
xkern_return_t dgramtest_init( XObj self ) { static XObj firstServer; PState *ps; dgramtestprotocol = self; ps = pathAlloc(self->path, sizeof(PState)); if (!ps) { xError("dgramtest: couldn't allocate PState\n"); return XK_FAILURE; } self->state = ps; if ((ps->evdgram = evAlloc(self->path)) == 0) { pathFree(ps); return XK_FAILURE; } ps->mark = '.'; ps->loop = LOOP_DEFAULT; ps->delay = 0; ps->dgramtest_priority = DGRAMTEST_PRIORITY; ps->groupsize = ALL_TOGETHER; bcopy((char *)&defaultServer, (char *)&ps->server, sizeof(IPhost)); if ( findXObjRomOpts(self, dgramOpts, sizeof(dgramOpts)/sizeof(XObjRomOpt), ps) == XK_FAILURE ) { xError("dgramtest: romfile config errors, not running"); return XK_FAILURE; } { /* * Overload standard path with custom path */ Path p; XkThreadPolicy_s policy; int pri = ps->dgramtest_priority; xkern_return_t xkr; p = pathCreate(31, "test path"); policy.func = xkPolicyFixedFifo; policy.arg = &pri; policy.argLen = sizeof(int); xkr = pathEstablishPool(p, 10, 1, &policy, 0); if ( xkr != XK_SUCCESS ) { xError("pathEstablishPool fails"); } self->path = p; } #if !DIPC_XKERN dgramtesttrigger(); #endif /* DIPC_XKERN */ self->control = dgramtestControlProtl; return XK_SUCCESS; }
static xkern_return_t customOpenDone( XObj self, XObj s, XObj llp, XObj hlpType, Path path) { u_short space = BUFFER_SIZE; xTrace0(prottest, TR_MAJOR_EVENTS, "tcp test program openDone"); xDuplicate(s); if (xControl(s, TCP_SETRCVBUFSIZE, (char*)&space, sizeof(space)) < 0) { xError("saveServerSessn: TCP_SETRCVBUFSIZE failed"); } /* if */ if (xControl(s, TCP_SETRCVBUFSPACE, (char*)&space, sizeof(space)) < 0){ xError("saveServerSessn: TCP_SETRCVBUFSPACE failed"); } /* if */ return XK_SUCCESS; }
static xkern_return_t customClientDemux( XObj self, XObj lls, Msg dg, int unused) { u_short space = BUFFER_SIZE; xTrace1(prottest, TR_DETAILED, "TCP custom demux resets buffer to size %d", BUFFER_SIZE); if (xControl(lls, TCP_SETRCVBUFSPACE, (char*)&space, sizeof(space)) < 0) { xError("TCP custom test_demux: TCP_SETRCVBUFSPACE failed"); } /* if */ return XK_SUCCESS; }
int pVehicle::initEngine(int flags) { driveLine=new pDriveLine(this); engine=new pEngine(this); engine->setToDefault(); gearbox=new pGearBox(this); gearbox->setToDefault(); driveLine->SetRoot(engine); engine->AddChild(gearbox); driveLine->SetGearBox(gearbox); differentials = 0 ; //---------------------------------------------------------------- // // setup differential , a single one for the first // pDifferential *d = new pDifferential(this); d->setToDefault(); pWheel *w1 = NULL;int w1Index = -1; pWheel *w2 = NULL;int w2Index = -1; findDifferentialWheels(w1Index,w2Index); w1 = (w1Index !=-1) ? _wheels[w1Index] : NULL; w2 = (w2Index !=-1) ? _wheels[w2Index] : NULL; if ( !w1||!w2 || ( !w1&&!w2 ) ) { xError("Couldn't find differential wheels"); return -1; } d->wheel[0]=w1; w1->setDifferential(d,0); d->wheel[1]=w2; w2->setDifferential(d,1); d->engine = engine; AddDifferential(d); // Add differentials and wheels to the driveline // Note this code does NOT work for 3 diffs, need more work for that. driveLine->SetDifferentials(differentials); if(differentials>0) { // Hook first diff to the gearbox gearbox->AddChild(differential[0]); } // Make the wheels children of the differentials // A diff with 2 diffs as children is not yet supported. for(int i=0;i<differentials;i++) { differential[i]->AddChild(differential[i]->wheel[0]); differential[i]->AddChild(differential[i]->wheel[1]); } driveLine->CalcPreClutchInertia(); gearbox->SetGear(0); return 0; }
static void client( Event ev, void *arg ) { Part_s participants, *p; XObj self = (XObj)arg; XObj llp; PState *ps = (PState *)self->state; int testNumber = 0, len, count, lenindex, noResponseCount = 0; long port = SERVERPORT; xAssert(xIsXObj(self)); xTrace1(prottest, TR_ALWAYS, "sending to %s", ipHostStr(&ps->server)); printf("DGRAM timing test\n"); llp = xGetDown(self, 0); if ( ! xIsProtocol(llp) ) { xError("Test protocol has no lower protocol"); return; } printf("I am the client\n"); if ( ps->delay ) { xTrace1(prottest, TR_ALWAYS, "Delaying %d seconds", ps->delay); Delay( ps->delay * 1000 ); } self->demux = clientDemux; p = &participants; partInit(p, 1); partPush(*p, &ps->server, sizeof(IPhost)); partPush(*p, &port, sizeof(long)); ps->lls = xOpen(self, self, llp, p, self->path); if ( ps->lls == ERR_XOBJ ) { printf("%s test: open failed!\n", PROT_STRING); xError("End of test"); return; } /* * HACK! client will steal an event thread that it will not return * for a while. */ if ( xkPolicyFixedFifo(&ps->dgramtest_priority, sizeof(ps->dgramtest_priority)) != XK_SUCCESS ) { printf("WARNING: xk_service_thread is being TIMESHARED!\n"); } /* * Delay to allow incoming messages to finalize opens (if necessary) */ Delay(1000); for (lenindex = 0; lenindex < sizeof(lens)/sizeof(long) || ps->loop; lenindex++) { if (lenindex >= sizeof(lens)/sizeof(long)) { lenindex = 0; } len = lens[lenindex]; #ifdef VERBOSE printf("Sending (%d, [%c]) ...\n", ++testNumber, ps->mark); #endif /* VERBOSE */ count = tryPush(self, ps->lls, xk_trips, len); if ( count == xk_trips ) { #ifdef VERBOSE printf("\n[%c] len = %4d, %d trips: %6d.%06d\n", ps->mark, len, xk_trips, ps->nettime.sec, ps->nettime.usec); #endif /* VERBOSE */ } if ( count == 0 ) { if ( noResponseCount++ == FAILURE_LIMIT ) { printf("Server looks dead. I'm outta here.\n"); break; } } else { noResponseCount = 0; } Delay(DELAY * 1000); } printf("[%c] End of test\n", ps->mark); xClose(ps->lls); ps->lls = 0; xTrace0(prottest, TR_FULL_TRACE, "test client returns"); out: { /* * restore the event priority! */ int new_priority = XK_EVENT_THREAD_PRIORITY; if ( xkPolicyFixedFifo(&new_priority, sizeof(new_priority)) != XK_SUCCESS ) { printf("WARNING: xk_service_thread is being lost!\n"); } } }