Ejemplo n.º 1
0
static void 
to_data_new(struct tor_conn *tc)
{
	int from, to, amnt;
	char *buf;
	cbuf_t cb;

	from = tc->from;
	to   = tc->to;
	while (1) {
		int ret;

		if (!(buf = cbuf_alloc_ext(BUFF_SZ, &cb, CBUF_TMEM))) BUG();
		amnt = tread(cos_spd_id(), to, cb, BUFF_SZ-1);
		if (0 == amnt) break;
		else if (-EPIPE == amnt) {
			goto close;
		} else if (amnt < 0) {
			printc("read from fd %d produced %d.\n", from, amnt);
			BUG();
		}
		assert(amnt <= BUFF_SZ);
		if (amnt != (ret = from_twrite(cos_spd_id(), from, cb, amnt))) {
			printc("conn_mgr: write failed w/ %d of %d on fd %d\n", 
			       ret, amnt, to);
			goto close;
		}
		cbuf_free(cb);
	}
done:
	cbuf_free(cb);
	return;
close:
	mapping_remove(from, to, tc->feid, tc->teid);
	from_trelease(cos_spd_id(), from);
	trelease(cos_spd_id(), to);
	assert(tc->feid && tc->teid);
	evt_put(tc->feid);
	evt_put(tc->teid);
	goto done;
}
Ejemplo n.º 2
0
static int timer_info(struct simio_device *dev)
{
    struct timer *tr = (struct timer *)dev;
    int i;

    printc("Base address: 0x%04x\n", tr->base_addr);
    printc("IV address:   0x%04x\n", tr->iv_addr);
    printc("IRQ0:         %d\n", tr->irq0);
    printc("IRQ1:         %d\n", tr->irq1);
    printc("\n");
    printc("TACTL:        0x%04x\n", tr->tactl);
    printc("TAR:          0x%04x\n", tr->tar);
    printc("TAIV:         0x%02x\n", calc_iv(tr, 0));
    printc("\n");

    for (i = 0; i < tr->size; i++)
        printc("Channel %2d, TACTL = 0x%04x, TACCR = 0x%04x\n",
               i, tr->ctls[i], tr->ccrs[i]);

    return 0;
}
Ejemplo n.º 3
0
static void lock_print_all(void)
{
	struct meta_lock *ml;

	for (ml = FIRST_LIST(&locks, next, prev) ; 
	     ml != &locks ; // && ml != FIRST_LIST(ml, next, prev) ; 
	     ml = FIRST_LIST(ml, next, prev)) {
		printc("lock @ %p (next %p, prev %p), id %d, spdid %d\n", 
		       ml, ml->next, ml->prev, (unsigned int)ml->lock_id, ml->spd);
	}
	prints("\n");
}
Ejemplo n.º 4
0
Archivo: secho.c Proyecto: Orc/secho
/* print an argument.
 */
void
printarg(FILE *out)
{
    int i;

    if ( counter > 1 )
	printc(outputdelim, out);
    if ( numbered )
	printfmt(out, "%d\t", counter);
    for (i=0; i < S(arg); i++)
	outc(T(arg)[i], out);
}
Ejemplo n.º 5
0
Archivo: secho.c Proyecto: Orc/secho
/* write a character (in some arbitrary printf format)
 * to the output buffer
 */
void
printfmt(FILE *out, char *fmt, unsigned char arg)
{
    int i;
    static Cstring Ppbuf = { 0 };

    S(Ppbuf) = 0;
    Cprintf(&Ppbuf, fmt, arg);

    for (i=0; i < S(Ppbuf); i++)
	printc(T(Ppbuf)[i], out);
}
void cos_init(void *arg)
{
	cos_map_init_static(&conn_map);

	while (1) {
		timed_event_block(cos_spd_id(), HTTP_REPORT_FREQ);
		printc("HTTP conns %ld, reqs %ld\n", http_conn_cnt, http_req_cnt);
		http_conn_cnt = http_req_cnt = 0;
	}
	
	return;
}
Ejemplo n.º 7
0
}

void keyboard_service_routine() {
	int bits_mask;
	bits_mask = inb(0x60);
	int mask_result = bits_mask&10000000;	 	// break == released
				  		    	// make == pressed
	if (mask_result == 0) {
		int letter_map = bits_mask%10000000; 	// 10 Millons
		int character_to_print = char_map[letter_map];
		if (character_to_print != '\0') character_to_print = 'C';
		printc(character_to_print);
Ejemplo n.º 8
0
//static volatile int cur_itr = 0;
void trans_recv_lo(void)
{  
  unsigned int amnt_lo = 1;
  long evt_lo;
  td_t td_lo;
  char *params_lo = "8";

  printc("***LOW PRIO RECV STARTING***\n");
  evt_lo = evt_split(cos_spd_id(), 0, 0);
  assert(evt_lo > 0);
  td_lo = tsplit(cos_spd_id(), td_root, params_lo, strlen(params_lo), TOR_READ, evt_lo);
  printc("EVT_LO (%ld) TD_LO (%d)\n", evt_lo, td_lo);

  do {
    evt_wait(cos_spd_id(), evt_lo);
    //   if((amnt_lo++ % 1000) == 0)
    printc("lo prio count (%u) spd(%d) tid(%d)\n", amnt_lo++, cos_spd_id(), cos_get_thd_id());
  } while (1);//cur_itr++ < ITR);
  
  return;
}
Ejemplo n.º 9
0
void main()
{
    trisb=0x00;
    delay_ms(10);
    lcdinit();
    delay_ms(1000);
    while(1)
    {
        printc("Ganesh");
        delay_ms(1000);
    }
}
Ejemplo n.º 10
0
int fault_page_fault_handler(spdid_t spdid, void *fault_addr, int flags, void *ip)
{
	if (regs_active) BUG();
	regs_active = 1;
	cos_regs_save(cos_get_thd_id(), spdid, fault_addr, &regs);
	printc("Thread %d faults in spd %d @ %p\n", 
	       cos_get_thd_id(), spdid, fault_addr);
	cos_regs_print(&regs);
	BUG(); 			/* no fault is a good fault currently */
//	sched_block(spdid, 0);
	return 0;
}
void usbutil_list(void)
{
	const struct usb_bus *bus;

	for (bus = usb_get_busses(); bus; bus = bus->next) {
		const struct usb_device *dev;
		int busnum = atoi(bus->dirname);

		printc("Devices on bus %03d:\n", busnum);

		for (dev = bus->devices; dev; dev = dev->next) {
			int devnum = atoi(dev->filename);

			printc("    %03d:%03d %04x:%04x %s\n",
			       busnum, devnum,
			       dev->descriptor.idVendor,
			       dev->descriptor.idProduct,
			       device_help(dev));
		}
	}
}
Ejemplo n.º 12
0
int fault_page_fault_handler(spdid_t spdid, void *fault_addr, int flags, void *ip)
{
	unsigned long r_ip; 	/* the ip to return to */
	int tid = cos_get_thd_id();
	int i;

	/* START UNCOMMENT FOR FAULT INFO */
	if (regs_active) BUG();
	regs_active = 1;
	cos_regs_save(tid, spdid, fault_addr, &regs);
	printc("Thread %d faults in spd %d @ %p\n",
	       tid, spdid, fault_addr);
	cos_regs_print(&regs);
	regs_active = 0;

	for (i = 0 ; i < 5 ; i++)
		printc("Frame ip:%lx, sp:%lx\n",
		       cos_thd_cntl(COS_THD_INVFRM_IP, tid, i, 0),
		       cos_thd_cntl(COS_THD_INVFRM_SP, tid, i, 0));
	/* END UNCOMMENT FOR FAULT INFO */

	/* remove from the invocation stack the faulting component! */
	assert(!cos_thd_cntl(COS_THD_INV_FRAME_REM, tid, 1, 0));

	/* Manipulate the return address of the component that called
	 * the faulting component... */
	assert(r_ip = cos_thd_cntl(COS_THD_INVFRM_IP, tid, 1, 0));
	/* ...and set it to its value -8, which is the fault handler
	 * of the stub. */
	assert(!cos_thd_cntl(COS_THD_INVFRM_SET_IP, tid, 1, r_ip-8));

	/* 
	 * Look at the booter: when recover is happening, the sstub is
	 * set to 0x1, thus we should just wait till recovery is done.
	 */
	if ((int)ip == 1) failure_notif_wait(cos_spd_id(), spdid);
	else         failure_notif_fail(cos_spd_id(), spdid);

	return 0;
}
Ejemplo n.º 13
0
static int
search_cmd_sub(int cmd_id, int *pmatch_sub_id, char *sub_name, int is_print)
{

    int cmd_sub_no, pmatch_sub_nr = 0, fmatch_sub_save = GCMD_DESC_NO_MATCH;

    *pmatch_sub_id = GCMD_DESC_NO_MATCH;

    /*search for full matched */
    for (cmd_sub_no = 0; GCMD_SUB_DESC_VALID(cmd_id, cmd_sub_no); cmd_sub_no++) {
        if (!GCMD_SUB_NAME(cmd_id, cmd_sub_no))
            continue;

        if (!strcasecmp(sub_name, GCMD_SUB_NAME(cmd_id, cmd_sub_no))) {
            /*full matched */
            printc(is_print, "%-10s\t%s\n", GCMD_SUB_ACT(cmd_id, cmd_sub_no), GCMD_SUB_MEMO(cmd_id, cmd_sub_no));
            //*pmatch_sub_id = cmd_sub_no;
            if(fmatch_sub_save == GCMD_DESC_NO_MATCH) {
                *pmatch_sub_id = fmatch_sub_save = cmd_sub_no;
            }

        } else if (!strncasecmp(sub_name, GCMD_SUB_NAME(cmd_id, cmd_sub_no), strlen(sub_name))) {
            if(fmatch_sub_save != GCMD_DESC_NO_MATCH)
                continue; 

            /*partly matched */
            if (*pmatch_sub_id == GCMD_DESC_NO_MATCH || (GCMD_SUB_NAME(cmd_id, cmd_sub_no-1) &&
                    strcasecmp(GCMD_SUB_NAME(cmd_id, cmd_sub_no), GCMD_SUB_NAME(cmd_id, cmd_sub_no-1)))) {
                printc(is_print, "%-10s\t", GCMD_SUB_NAME(cmd_id, cmd_sub_no));
                pmatch_sub_nr++;
                *pmatch_sub_id = cmd_sub_no;
            }
        }
    }

    if (pmatch_sub_nr > 1)
        printc(is_print, "\n");

    return pmatch_sub_nr;
}
Ejemplo n.º 14
0
void namelist_print(struct vector *v)
{
	int i;
	int max_len = 0;
	int rows, cols;

	qsort(v->ptr, v->size, v->elemsize, namelist_cmp);

	for (i = 0; i < v->size; i++) {
		const char *text = VECTOR_AT(*v, i, const char *);
		int len = strlen(text);

		if (len > max_len)
			max_len = len;
	}

	max_len += 2;
	cols = 72 / max_len;
	rows = (v->size + cols - 1) / cols;

	for (i = 0; i < rows; i++) {
		int j;

		printc("    ");
		for (j = 0; j < cols; j++) {
			int k = j * rows + i;
			const char *text;

			if (k >= v->size)
				break;

			text = VECTOR_AT(*v, k, const char *);
			printc("%s", text);
			for (k = strlen(text); k < max_len; k++)
				printc(" ");
		}

		printc("\n");
	}
}
Ejemplo n.º 15
0
void cos_init(void)
{
	u64_t start, end, avg, tot = 0, dev = 0;
	int i, j;

	call();			/* get stack */
	printc("cpu %ld, thd %d from ping\n",cos_cpuid(), cos_get_thd_id());
	printc("Starting %d Invocations.\n", ITER);

	for (i = 0 ; i < ITER ; i++) {
		rdtscll(start);
//		cos_send_ipi(i, 0, 0, 0);
		call();
		rdtscll(end);
		meas[i] = end-start;
	}

	for (i = 0 ; i < ITER ; i++) tot += meas[i];
	avg = tot/ITER;
	printc("avg %lld\n", avg);
	for (tot = 0, i = 0, j = 0 ; i < ITER ; i++) {
		if (meas[i] < avg*2) {
			tot += meas[i];
			j++;
		}
	}
	printc("avg w/o %d outliers %lld\n", ITER-j, tot/j);

	for (i = 0 ; i < ITER ; i++) {
		u64_t diff = (meas[i] > avg) ? 
			meas[i] - avg : 
			avg - meas[i];
		dev += (diff*diff);
	}
	dev /= ITER;
	printc("deviation^2 = %lld\n", dev);

//	printc("%d invocations took %lld\n", ITER, end-start);
	return;
}
Ejemplo n.º 16
0
/* simulator ==> pid */
static int
from_data_new(ap_data *in_data)
{
	char *buf;
	cbuf_t cb;
	int amnt;
	int ret = 0;

	/* printc("from_data_new\n"); */

	buf = cbuf_alloc(BUFF_SZ, &cb);
	assert(buf);
	amnt = from_tread(cos_spd_id(), pid_torrent, cb, BUFF_SZ-1);
	if (0 == amnt) {
		/* printc("0 amnt\n"); */
		goto done;
	}
	else if (-EPIPE == amnt) {
		printc("EPIPE close connection\n");
		goto close;
	} else if (amnt < 0) {
		/* printc("read from pid_torrent %d produced %d.\n", pid_torrent, amnt); */
		goto done;
	}

	/* copy the external information here*/
	// TODO

	printc("simulator ==> pid:: %s\n", buf);

	if (buf) ret = 1;
	
done:
	cbuf_free(buf);
	return ret;
close:
	from_trelease(cos_spd_id(), pid_torrent);
	goto done;
}
Ejemplo n.º 17
0
void
stkmgr_update_stats_wakeup(struct spd_stk_info *ssi, unsigned short int tid)
{
	u64_t end, tot;

	printc("************** dude, %d found my car in %d *****************\n", 
	       tid, ssi->spdid);

	rdtscll(end);
	tot = end - ssi->thd_blk_start[tid];
	ssi->thd_blk_tot[tid] += tot;
	ssi->thd_blk_start[tid] = 0;
}
Ejemplo n.º 18
0
void runqueue_print(void)
{
	struct sched_thd *t;
	int i = 0;
	
	printc("Core %ld: Running threads (thd, prio, ticks):\n", cos_cpuid());
	for (i = 0 ; i < NUM_PRIOS ; i++) {
		for (t = FIRST_LIST(&PERCPU_GET(fprr_state)->priorities[i].runnable, prio_next, prio_prev) ; 
		     t != &PERCPU_GET(fprr_state)->priorities[i].runnable ;
		     t = FIRST_LIST(t, prio_next, prio_prev)) {
			struct sched_accounting *sa = sched_get_accounting(t);
			unsigned long diff = sa->ticks - sa->prev_ticks;

			//if (!(diff || sa->cycles)) continue;
			printc("\t%d, %d, %ld+%ld/%d\n", t->id, i, diff, (unsigned long)sa->cycles, QUANTUM);
			sa->prev_ticks = sa->ticks;
			sa->cycles = 0;
		}
	}
#ifdef DEFERRABLE
	printc("Suspended threads (thd, prio, ticks):\n");
	for (t = FIRST_LIST(&PERCPU_GET(fprr_state)->servers, sched_next, sched_prev) ; 
	     t != &PERCPU_GET(fprr_state)->servers ;
	     t = FIRST_LIST(t, sched_next, sched_prev)) {
		struct sched_accounting *sa = sched_get_accounting(t);
		unsigned long diff = sa->ticks - sa->prev_ticks;
		
		if (!sched_thd_suspended(t)) continue;
		if (diff || sa->cycles) {
			printc("\t%d, %d, %ld+%ld/%d\n", t->id, 
			       sched_get_metric(t)->priority, diff, 
			       (unsigned long)sa->cycles, QUANTUM);
			sa->prev_ticks = sa->ticks;
			sa->cycles = 0;
		}
	}
#endif
	printc("done printing runqueue.\n");
}
Ejemplo n.º 19
0
void cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i;
	
	if(first == 0){
		first = 1;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 11;
		high = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 12;
		low = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
	} else {
		if (cos_get_thd_id() == high) {
#ifdef TEST_TE
			while(1) {
				rdtscll(start);
				timed_event_block(cos_spd_id(), 100);
				rdtscll(end);
				printc("(thd %d)time even blocked for %llu ticks\n", cos_get_thd_id(), (end-start));
			}
#endif
#ifdef TEST_PERIOD
			periodic_wake_create(cos_spd_id(), 100);
			while(1) {
				rdtscll(start);
				periodic_wake_wait(cos_spd_id());
				rdtscll(end);
				printc("time even blocked for %llu ticks\n", (end-start));
			}
#endif
		}
	}
	return;
}
Ejemplo n.º 20
0
AHC_BOOL AHC_UF_IsRearCamFileExistbyIndex(UINT32 uiIndex, AHC_BOOL *bFileExist)
{
    UINT32 uiDCFIndex;
    uiDCFIndex = AHC_UF_IndexReverseMapping(uiIndex);
    
#if (DCF_FILE_NAME_TYPE == DCF_FILE_NAME_TYPE_NORMAL)
    printc("%s,%d  not support yet!\r\n",__func__, __LINE__);
    return AHC_FALSE;
#elif (DCF_FILE_NAME_TYPE == DCF_FILE_NAME_TYPE_DATE_TIME)
    return AHC_DCFDT_IsRearCamFileExistbyIndex(uiDCFIndex,bFileExist);
#endif

}
Ejemplo n.º 21
0
void 
cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i;
	

	if(first == 0){
		first = 1;

		for (i=0; i<PAGE_NUM; i++) s_addr[i] = 0;
		for (i=0; i<PAGE_NUM; i++) d_addr[i] = 0;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = THREAD1;
		sched_create_thd(cos_spd_id(), sp.v, 0, 0);

	} else {
		timed_event_block(cos_spd_id(), 50);
		periodic_wake_create(cos_spd_id(), 1);
		i = 0;
		while(i++ < 80) { /* 80 x 10 x 4k  < 4M */
			printc("<<< MM RECOVERY TEST START (thd %d) >>>\n", cos_get_thd_id());
			get_test();
#ifdef BEST_TEST
			alias_test();
			revoke_test();
#endif

			/* all_in_one(); */

			printc("<<< MM RECOVERY TEST DONE!! >>> {%d}\n\n\n", i);
			periodic_wake_wait(cos_spd_id());
		}
	}
	
	return;
}
Ejemplo n.º 22
0
void cos_upcall_fn(upcall_type_t t, void *arg1, void *arg2, void *arg3)
{
	static int first = 1;

	switch (t) {
	case COS_UPCALL_BOOTSTRAP:
		if (first) {
			start_timer_thread();
			first = 0;
		} else {
			printc("timed_event component received too many bootstrap threads.");
		}
		break;
	default:
		printc("wf_text: cos_upcall_fn error - type %x, arg1 %d, arg2 %d", 
		      (unsigned int)t, (unsigned int)arg1, (unsigned int)arg2);
		BUG();
		return;
	}
	BUG();
	return;
}
Ejemplo n.º 23
0
int
__sg_treadp(spdid_t spdid, int tid, int len, int __pad0, int *off_len)
{
	int ret = 0;
	/* printc("treadp ser passed in: spdid %d tid %d len %d\n", */
	/*        spdid, tid, len); */
	/* printc("treadp ser (before): ret %d off_len[0] %d off_len[1] %d\n", */
	/*        ret, off_len[0], off_len[1]); */
        ret = treadp(spdid, tid, len, &off_len[0], &off_len[1]);
	printc("treadp ser (after): ret %d off_len[0] %d off_len[1] %d\n",
	       ret, off_len[0], off_len[1]);
	return ret;
}
Ejemplo n.º 24
0
/* 
 * Currently, this only adds to the wildcard brand.
 */
int netif_event_create(spdid_t spdid)
{
	unsigned short int ucid = cos_get_thd_id();

	assert(wildcard_brand_id > 0);
	NET_LOCK_TAKE();
	if (sched_add_thd_to_brand(cos_spd_id(), wildcard_brand_id, ucid)) BUG();
	add_thd_map(ucid, /*0 wildcard port ,*/ &rb1_md_wildcard);
	NET_LOCK_RELEASE();
	printc("created net uc %d associated with brand %d\n", ucid, wildcard_brand_id);

	return 0;
}
Ejemplo n.º 25
0
MMP_ERR Gsensor_ReadDeviceID(struct _3RD_PARTY_GSENSOR *pthis, GSNR_ATTRIBUTE *pgsnr_attr)
{
	MMP_ERR 	status 		= MMP_ERR_NONE;
	MMP_UBYTE	usdeviceID 	= 0;
	
	status |= pthis->MMPF_Gsensor_GetReg(pthis, GSensor_Reg_STADR, &usdeviceID);
	
	if (usdeviceID != GSENSOR_ID_GMA301)
	{
		status = 1;	// ERROR
		printc(FG_RED("GMA301 Gsensor Read Device ID 0x%x  %d Error\r\n"),usdeviceID, status);
		pgsnr_attr->ubGsensorID = 0xFF;
	}
	else
	{
		status = 0;	// SUCCESS
		printc(FG_GREEN("GMA301 Gsensor Read Device ID 0x%x %d Success\r\n"),usdeviceID, status);
		pgsnr_attr->ubGsensorID = (MMP_UBYTE)usdeviceID;
	}
	
	return status; 
}
Ejemplo n.º 26
0
static int http_make_request(struct http_request *r)
{
	switch (r->type) {
	case HTTP_TYPE_GET:
		return http_get_request(r);
		break;
	default:
		printc("unknown request type\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 27
0
void cos_init(void) {
	static int first = 1;

	printc("thd %d, core %ld in pong\n", cos_get_thd_id(), cos_cpuid());

	if (first) {
		first = 0;
		create_thd(1, HIGH_PRIO);
		printc("thd %d, core %ld done init in pong\n", cos_get_thd_id(), cos_cpuid());

		return;
	}

//core 1
	static int first_core1 = 1;
	if (cos_cpuid() == 1) {
		if (first_core1 == 1) {
			first_core1 = 0;
			core1_high();
		} else {
			core1_low();
		}
		return;
	}
	
//core 0
	static int first_core0 = 1;
	if (cos_cpuid() == 0) {
		if (first_core0 == 1) {
			first_core0 = 0;
			core0_high();
		} else {
			core0_low();
		}
		return;
	}
	
	return;
}
Ejemplo n.º 28
0
static void
walk_stack_all(spdid_t spdid, struct cos_regs *regs)
{
    unsigned long *fp, *stack, fp_off;
    int i, tid = cos_get_thd_id();

    printc("Stack trace for thread %d [spdid, instruction pointer]:\n", tid);

    fp = (unsigned long *)regs->regs.bp;
    stack = map_stack(spdid, (vaddr_t)fp);
    printc("\t[%d, %lx]\n", spdid, (unsigned long)regs->regs.ip);
    walk_stack(spdid, fp, stack);
    unmap_stack(spdid, stack);

    assert(cos_spd_id() == cos_thd_cntl(COS_THD_INV_FRAME, tid, 0, 0));
    assert(spdid == cos_thd_cntl(COS_THD_INV_FRAME, tid, 1, 0));

    for (i = 2 ; (spdid = cos_thd_cntl(COS_THD_INV_FRAME, tid, i, 0)) != 0 ; i++) {
        unsigned long sp;

        /* We're ignoring the initial IPs the IP is in the
         * invocation stubs, and noone cares about the
         * stubs */
        sp = cos_thd_cntl(COS_THD_INVFRM_SP, tid, i, 0);
        assert(sp);

        stack = map_stack(spdid, sp);
        /* The invocation stubs save ebp last, thus *(esp+16)
         * = ebp.  This offset corresponds to the number of
         * registers pushed in
         * SS_ipc_client_marshal_args... */
        fp_off = ((sp & (~PAGE_MASK))/sizeof(unsigned long));
        fp = (unsigned long *)&stack[fp_off];

        walk_stack(spdid, fp, stack);
        unmap_stack(spdid, stack);
    }

}
Ejemplo n.º 29
0
static void to_data_new(struct tor_conn *tc)
{
	int from, to, amnt;
	char *buf;

	from = tc->from;
	to   = tc->to;
	buf = cos_argreg_alloc(BUFF_SZ);
	assert(buf);
	while (1) {
		int ret;

		amnt = tread_pack(cos_spd_id(), to, buf, BUFF_SZ-1);
		if (0 == amnt) break;
		else if (-EPIPE == amnt) {
			goto close;
		} else if (amnt < 0) {
			printc("read from fd %d produced %d.\n", from, amnt);
			BUG();
		}
		if (amnt != (ret = net_send(cos_spd_id(), from, buf, amnt))) {
			printc("conn_mgr: write failed w/ %d on fd %d\n", ret, to);
			goto close;

		}

	}
done:
	cos_argreg_free(buf);
	return;
close:
	net_close(cos_spd_id(), from);
	trelease(cos_spd_id(), to);
	tor_del_pair(from, to);
	if (tc->feid) cvect_del(&evts, tc->feid);
	if (tc->teid) cvect_del(&evts, tc->teid);
	goto done;
}
Ejemplo n.º 30
0
Archivo: lib.c Proyecto: Tayacan/OSM
/* Output 'n' in base 'base' into buffer 'buf' or to TTY.  At least
 * 'prec' numbers are output, padding with zeros if needed, and at
 * least 'width' characters are output, padding with spaces on the
 * left if needed. 'flags' tells whether to use the buffer or TTY for
 * output and whether to use capital digits.
 */
static int print_uint(char *buf,
		      int size,
		      unsigned int n,
		      unsigned int base,
		      int flags,
		      int prec,
		      int width)
{
  static const char digits[32] = "0123456789ABCDEF0123456789abcdef";
  char rev[11]; /* space for 32-bit int in octal */
  int i = 0, written = 0;

  if (size <= 0) return 0;
  
  /* produce the number string in reverse order to the temp buffer 'rev' */
  do {
    if (flags & FLAG_SMALLS)
      rev[i] = digits[16 + n % base];
    else
      rev[i] = digits[n % base];
    i++;
    n /= base;
  } while (n != 0);

  /* limit precision and field with */
  prec = MIN(prec, 11);
  width = MIN(width, 11);

  /* zero pad until at least 'prec' digits written */
  while (i < prec) {
    rev[i] = '0';
    i++;
  }

  /* pad with spaces until at least 'width' chars written */
  while (i < width) {
    rev[i] = ' ';
    i++;
  }

  /* output the produced string in reverse order */
  i--;
  while (i >= 0 && written < size) {
    printc(buf++, rev[i], flags);
    written++;
    i--;
  }

  return written;
}