Exemplo n.º 1
0
void send_at_command_sci1(char* str){
  long i;
  status = 'c';
  for (i = 0; str[i] != '\0'; i++) outchar1(str[i]);
  outchar1('\n');

  at_timeout = 10 * 100; // set at_timeout to ~10 sec  
  while(at_timeout){
    while(qempty() && at_timeout);
    c = getq();
    if (c == 'O'){
      while(qempty() && at_timeout);
      c = getq();
      if (c == 'K')
        break;
      else
        continue;
    }
  }
  
  
  // XXX: maybe clearing out nXXXXXXXXXX? 
  //empty_queue(); // clear the queue of any part of the message we may have ignored.
  
  if (at_timeout)
    status = 'i';
  else{
    status = 'e';
    set_lcd_addr(0);
    type_lcd("writing timed");
    set_lcd_addr(0x40);
    type_lcd("out.");
  }
}
Exemplo n.º 2
0
static struct mbuf *
tcq_dequeue_cl(struct tcq_if *tif, struct tcq_class *cl,
    mbuf_svc_class_t sc, cqdq_op_t op)
{
	struct ifclassq *ifq = tif->tif_ifq;
	struct mbuf *m;

	IFCQ_LOCK_ASSERT_HELD(ifq);

	if (cl == NULL) {
		cl = tcq_clh_to_clp(tif, MBUF_SCIDX(sc));
		if (cl == NULL)
			return (NULL);
	}

	if (qempty(&cl->cl_q))
		return (NULL);

	VERIFY(!IFCQ_IS_EMPTY(ifq));

	if (op == CLASSQDQ_POLL)
		return (tcq_pollq(cl));

	m = tcq_getq(cl);
	if (m != NULL) {
		IFCQ_DEC_LEN(ifq);
		IFCQ_DEC_BYTES(ifq, m_pktlen(m));
		if (qempty(&cl->cl_q))
			cl->cl_period++;
		PKTCNTR_ADD(&cl->cl_xmitcnt, 1, m_pktlen(m));
		IFCQ_XMIT_ADD(ifq, 1, m_pktlen(m));
	}
	return (m);
}
Exemplo n.º 3
0
/*
 * priq_dequeue is a dequeue function to be registered to
 * (*altq_dequeue) in struct ifaltq.
 *
 * note: ALTDQ_POLL returns the next packet without removing the packet
 *	from the queue.  ALTDQ_REMOVE is a normal dequeue operation.
 *	ALTDQ_REMOVE must return the same packet if called immediately
 *	after ALTDQ_POLL.
 */
static struct mbuf *
priq_dequeue(struct ifaltq *ifq, int op)
{
	struct priq_if	*pif = (struct priq_if *)ifq->altq_disc;
	struct priq_class *cl;
	struct mbuf *m;
	int pri;

	if (IFQ_IS_EMPTY(ifq))
		/* no packet in the queue */
		return (NULL);

	for (pri = pif->pif_maxpri;  pri >= 0; pri--) {
		if ((cl = pif->pif_classes[pri]) != NULL &&
		    !qempty(cl->cl_q)) {
			if (op == ALTDQ_POLL)
				return (priq_pollq(cl));

			m = priq_getq(cl);
			if (m != NULL) {
				IFQ_DEC_LEN(ifq);
				if (qempty(cl->cl_q))
					cl->cl_period++;
				PKTCNTR_ADD(&cl->cl_xmitcnt, m_pktlen(m));
			}
			return (m);
		}
	}
	return (NULL);
}
Exemplo n.º 4
0
void transmit (SLOT *sp)
{
  if (sp->flags.die)
    return;

  if (writequeue (sp, &sp->outq) < 0) {
    if (sp->acct.chan < NUMCHANNELS) {
      remove_from_channel (sp, sp->acct.chan); 
      remove_from_channel (sp, MAINLIST); 
    }
    if (sp->acct.chan && sp->flags.on) {
      paabout (sp, DISCONNECTED);
      sp->acct.last_logout = time (NULL);
    }
    inactivate_slot (sp, 0);
    return;
  }

  if (!qempty (&sp->stopq) && !sp->flags.stopped &&
      writequeue (sp, &sp->stopq) < 0) {
    if (sp->acct.chan < NUMCHANNELS) {
      remove_from_channel (sp, sp->acct.chan); 
      remove_from_channel (sp, MAINLIST); 
    }
    if (sp->acct.chan && sp->flags.on) {
      paabout (sp, DISCONNECTED);
      sp->acct.last_logout = time (NULL);
    }
    inactivate_slot (sp, 0);
  }
}
Exemplo n.º 5
0
static int
codel_request(struct ifaltq *ifq, int req, void *arg)
{
	struct codel_if	*cif = (struct codel_if *)ifq->altq_disc;
	struct mbuf *m;

	IFQ_LOCK_ASSERT(ifq);

	switch (req) {
	case ALTRQ_PURGE:
		if (!ALTQ_IS_ENABLED(cif->cif_ifq))
			break;

		if (qempty(cif->cl_q))
			break;

		while ((m = _getq(cif->cl_q)) != NULL) {
			PKTCNTR_ADD(&cif->cl_stats.cl_dropcnt, m_pktlen(m));
			m_freem(m);
			IFQ_DEC_LEN(cif->cif_ifq);
		}
		cif->cif_ifq->ifq_len = 0;
		break;
	}

	return (0);
}
Exemplo n.º 6
0
/*
 * priq_dequeue is a dequeue function to be registered to
 * (*altq_dequeue) in struct ifaltq.
 *
 * note: ALTDQ_POLL returns the next packet without removing the packet
 *	from the queue.  ALTDQ_REMOVE is a normal dequeue operation.
 *	ALTDQ_REMOVE must return the same packet if called immediately
 *	after ALTDQ_POLL.
 */
static struct mbuf *
priq_dequeue(struct ifaltq_subque *ifsq, struct mbuf *mpolled, int op)
{
	struct ifaltq *ifq = ifsq->ifsq_altq;
	struct priq_if *pif = (struct priq_if *)ifq->altq_disc;
	struct priq_class *cl;
	struct mbuf *m;
	int pri;

	if (ifsq_get_index(ifsq) != PRIQ_SUBQ_INDEX) {
		/*
		 * Race happened, the unrelated subqueue was
		 * picked during the packet scheduler transition.
		 */
		ifsq_classic_request(ifsq, ALTRQ_PURGE, NULL);
		return NULL;
	}

	if (ifsq_is_empty(ifsq)) {
		/* no packet in the queue */
		KKASSERT(mpolled == NULL);
		return (NULL);
	}

	crit_enter();
	m = NULL;
	for (pri = pif->pif_maxpri;  pri >= 0; pri--) {
		if ((cl = pif->pif_classes[pri]) != NULL && !qempty(cl->cl_q)) {
			if (op == ALTDQ_POLL) {
				m = priq_pollq(cl);
				break;
			}

			m = priq_getq(cl);
			if (m != NULL) {
				ifsq->ifq_len--;
				if (qempty(cl->cl_q))
					cl->cl_period++;
				PKTCNTR_ADD(&cl->cl_xmitcnt, m_pktlen(m));
			}
			break;
		}
	}
	crit_exit();
	KKASSERT(mpolled == NULL || mpolled == m);
	return (m);
}
Exemplo n.º 7
0
/* this routine blocks a reader until there is data available to read */
int block_read(RPQ rpq, RP rp, CQ qp)
{
	/* data available? */
	if (qempty(qp))
	{
		/* enqueue packet */
		rpqenque(rpq,rp);

		/* no, block on this request */	
		for(;;)
		{
			RPSTAT(rp) = RPDONE;
			/**** returns here if this packet is run */
# if 0			
			if (Block(rp,-1l,0))
			{
				/* spurious, block again */
				if (RPSTAT(rp) != RPDONE)
				  continue;
				/* interrupted */
				if (rp != rpqtop(rpq))
				{
					/* this is not the current packet,
					 * unlink it, and return it as 0 bytes
					 */
					rpqdiscard(rpq,rp);
					RWCNT(rp) = 0;
					return RPDONE;
				}
			}
			break; /* leave loop */
# else
      switch (Block(rp, -1l, 0))
      {
        case 0 :  /* resumed normally */
          break;

        case 1 :  /* timeout */
        case 2 :  /* interrupted */
          if (rp != rpqtop(rpq))
          {
            /* Not the current packet, unlink and return as 0 */
            rpqdiscard(rpq, rp);
            RWCNT(rp) = 0;   /* Set to 0 */
            return RPDONE;
          }
        /* else is default */
        default:
            break;
      }
      break;   /* Leave loop */
		}
# endif		
		/* we get here after block ended, get packet */
		rp = rpqdeque(rpq);
	}
	return 0;
}
Exemplo n.º 8
0
static int
priq_class_destroy(struct priq_if *pif, struct priq_class *cl)
{
	struct ifclassq *ifq = pif->pif_ifq;
	int pri;

	IFCQ_LOCK_ASSERT_HELD(ifq);

	if (!qempty(&cl->cl_q))
		priq_purgeq(pif, cl, 0, NULL, NULL);

	VERIFY(cl->cl_pri < PRIQ_MAXPRI);
	VERIFY(!pktsched_bit_tst(cl->cl_pri, &pif->pif_bitmap));

	pif->pif_classes[cl->cl_pri] = NULL;
	if (pif->pif_maxpri == cl->cl_pri) {
		for (pri = cl->cl_pri; pri >= 0; pri--)
			if (pif->pif_classes[pri] != NULL) {
				pif->pif_maxpri = pri;
				break;
			}
		if (pri < 0)
			pif->pif_maxpri = -1;
	}

	if (pif->pif_default == cl)
		pif->pif_default = NULL;

	if (cl->cl_qalg.ptr != NULL) {
#if CLASSQ_RIO
		if (q_is_rio(&cl->cl_q))
			rio_destroy(cl->cl_rio);
#endif /* CLASSQ_RIO */
#if CLASSQ_RED
		if (q_is_red(&cl->cl_q))
			red_destroy(cl->cl_red);
#endif /* CLASSQ_RED */
#if CLASSQ_BLUE
		if (q_is_blue(&cl->cl_q))
			blue_destroy(cl->cl_blue);
#endif /* CLASSQ_BLUE */
		if (q_is_sfb(&cl->cl_q) && cl->cl_sfb != NULL)
			sfb_destroy(cl->cl_sfb);
		cl->cl_qalg.ptr = NULL;
		qtype(&cl->cl_q) = Q_DROPTAIL;
		qstate(&cl->cl_q) = QS_RUNNING;
	}

	if (pktsched_verbose) {
		log(LOG_DEBUG, "%s: %s destroyed qid=%d pri=%d\n",
		    if_name(PRIQIF_IFP(pif)), priq_style(pif),
		    cl->cl_handle, cl->cl_pri);
	}

	zfree(priq_cl_zone, cl);

	return (0);
}
Exemplo n.º 9
0
void main(void) {
  PLL_init();
  lcd_init();
  SCI0_init(9600); 
  SCI1_int_init(9600); // Channel to talk to ESP8266
  motor0_init(); // These functions actually control PWM outputs
  motor1_init(); // We use them to run the RGB LED.
  motor2_init();
  RTI_init();
  SW_enable();
  
  initq();
  
  DDRH = 0; // PORTH is an input.
  result = 0;
  status = 'b';
  
  // Populate binary search tree:

  set_lcd_addr(0);
    
  send_at_command_sci1("ATE0");  // change to ATE1 for debug
  
  status = 'i';
  
  // Establish connection to server.
  
  send_at_command_sci1("AT+CWMODE=1");  // Set ESP to station mode
  
  send_at_command_sci1("AT+CIPMODE=0"); // Set ESP to normal transmission mode
  
  send_at_command_sci1("AT+CIPMUX=0");  // Set ESP to single-connection mode 
  
  send_at_command_sci1("AT+CWJAP=\"Freynet\",\"\""); // Connect to network
  
  send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server

  
  while(1){
    command = '\0';   
    while(qempty());
    command = getq();
    
    switch (command) {
      case 'n':
        status = 'w';
        result = new_sequence();
        ms_delay(500); // If we finish too quickly, we open a connection the ESP thinks is already open, and it breaks.
        send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server

        break;
        
    }
    outchar0(result);
  }
}
Exemplo n.º 10
0
/* discard all the queued packets on the interface */
static void
hfsc_purge(struct hfsc_if *hif)
{
	struct hfsc_class *cl;

	for (cl = hif->hif_rootclass; cl != NULL; cl = hfsc_nextclass(cl))
		if (!qempty(cl->cl_q))
			hfsc_purgeq(cl);
	if (ALTQ_IS_ENABLED(hif->hif_ifq))
		hif->hif_ifq->ifq_len = 0;
}
Exemplo n.º 11
0
/*
 * note: CLASSQDQ_POLL returns the next packet without removing the packet
 *	from the queue.  CLASSQDQ_REMOVE is a normal dequeue operation.
 *	CLASSQDQ_REMOVE must return the same packet if called immediately
 *	after CLASSQDQ_POLL.
 */
struct mbuf *
priq_dequeue(struct priq_if *pif, cqdq_op_t op)
{
	struct ifclassq *ifq = pif->pif_ifq;
	struct priq_class *cl;
	struct mbuf *m;
	u_int32_t pri, len;

	IFCQ_LOCK_ASSERT_HELD(ifq);

	if (pif->pif_bitmap == 0) {
		/* no active class; nothing to dequeue */
		return (NULL);
	}
	VERIFY(!IFCQ_IS_EMPTY(ifq));

	pri = pktsched_fls(pif->pif_bitmap) - 1;	/* zero based */
	VERIFY(pri < PRIQ_MAXPRI);
	cl = pif->pif_classes[pri];
	VERIFY(cl != NULL && !qempty(&cl->cl_q));

	if (op == CLASSQDQ_POLL)
		return (priq_pollq(cl));

	m = priq_getq(cl);
	VERIFY(m != NULL);	/* qalg must be work conserving */
	len = m_pktlen(m);

	IFCQ_DEC_LEN(ifq);
	IFCQ_DEC_BYTES(ifq, len);
	if (qempty(&cl->cl_q)) {
		cl->cl_period++;
		/* class is now inactive; indicate it as such */
		pktsched_bit_clr(pri, &pif->pif_bitmap);
	}
	PKTCNTR_ADD(&cl->cl_xmitcnt, 1, len);
	IFCQ_XMIT_ADD(ifq, 1, len);

	return (m);
}
Exemplo n.º 12
0
mblk_t *rtp_getq(queue_t *q,guint32 timestamp, int *rejected)
{
	mblk_t *tmp,*ret=NULL,*old;
	rtp_header_t *tmprtp;
	guint32 oldest;
	guint32 ts_found=0;
	
	*rejected=0;
	ortp_debug("rtp_getq(): Timestamp %i wanted.",timestamp);

	if (qempty(q))
	{
		/*ortp_debug("rtp_getq: q is empty.");*/
		return NULL;
	}
	/* prevent somebody to ask for a timestamp that is older than the oldest of the queue */
	oldest=((rtp_header_t*) qfirst(q)->b_rptr)->timestamp;
	if (RTP_TIMESTAMP_IS_STRICTLY_NEWER_THAN(oldest,timestamp))
	{
		ortp_debug("rtp_getq(): asking for too old packet ! oldest=%i",oldest);
		return NULL;
	}
	ret=NULL;
	old=NULL;
	/* return the packet with ts just equal or older than the asked timestamp */
	while ((tmp=qfirst(q))!=NULL)
	{
		tmprtp=(rtp_header_t*)tmp->b_rptr;
		ortp_debug("rtp_getq: Seeing packet with ts=%i",tmprtp->timestamp);
		if ( RTP_TIMESTAMP_IS_NEWER_THAN(timestamp,tmprtp->timestamp) )
		{
			if (ret!=NULL && tmprtp->timestamp==ts_found) {
				/* we've found two packets with same timestamp. return the first one */
				break;
			}
			if (old!=NULL) {
				ortp_debug("rtp_getq: discarding too old packet with ts=%i",ts_found);
				(*rejected)++;
				freemsg(old);
			}
			ret=getq(q); /* dequeue the packet, since it has an interesting timestamp*/
			ts_found=tmprtp->timestamp;
			ortp_debug("rtp_getq: Found packet with ts=%i",tmprtp->timestamp);
			old=ret;
		}
		else
		{
			break;
		}
	}
	return ret;
}
Exemplo n.º 13
0
/* discard all the queued packets on the interface */
static void
priq_purge(struct priq_if *pif)
{
	struct priq_class *cl;
	int pri;

	for (pri = 0; pri <= pif->pif_maxpri; pri++) {
		if ((cl = pif->pif_classes[pri]) != NULL && !qempty(cl->cl_q))
			priq_purgeq(cl);
	}
	if (ifq_is_enabled(pif->pif_ifq))
		pif->pif_ifq->altq_subq[PRIQ_SUBQ_INDEX].ifq_len = 0;
}
Exemplo n.º 14
0
/* discard all the queued packets on the interface */
static void
priq_purge(struct priq_if *pif)
{
	struct priq_class *cl;
	int pri;

	for (pri = 0; pri <= pif->pif_maxpri; pri++) {
		if ((cl = pif->pif_classes[pri]) != NULL && !qempty(cl->cl_q))
			priq_purgeq(cl);
	}
	if (ALTQ_IS_ENABLED(pif->pif_ifq))
		pif->pif_ifq->ifq_len = 0;
}
Exemplo n.º 15
0
static void
priq_purgeq(struct priq_class *cl)
{
	struct mbuf *m;

	if (qempty(cl->cl_q))
		return;

	while ((m = _getq(cl->cl_q)) != NULL) {
		PKTCNTR_ADD(&cl->cl_dropcnt, m_pktlen(m));
		m_freem(m);
	}
	KKASSERT(qlen(cl->cl_q) == 0);
}
Exemplo n.º 16
0
static int
priq_class_destroy(struct priq_class *cl)
{
	struct priq_if *pif;
	int s, pri;

	s = splnet();
	IFQ_LOCK(cl->cl_pif->pif_ifq);

#ifdef ALTQ3_CLFIER_COMPAT
	/* delete filters referencing to this class */
	acc_discard_filters(&cl->cl_pif->pif_classifier, cl, 0);
#endif

	if (!qempty(cl->cl_q))
		priq_purgeq(cl);

	pif = cl->cl_pif;
	pif->pif_classes[cl->cl_pri] = NULL;
	if (pif->pif_maxpri == cl->cl_pri) {
		for (pri = cl->cl_pri; pri >= 0; pri--)
			if (pif->pif_classes[pri] != NULL) {
				pif->pif_maxpri = pri;
				break;
			}
		if (pri < 0)
			pif->pif_maxpri = -1;
	}
	IFQ_UNLOCK(cl->cl_pif->pif_ifq);
	splx(s);

	if (cl->cl_red != NULL) {
#ifdef ALTQ_RIO
		if (q_is_rio(cl->cl_q))
			rio_destroy((rio_t *)cl->cl_red);
#endif
#ifdef ALTQ_RED
		if (q_is_red(cl->cl_q))
			red_destroy(cl->cl_red);
#endif
#ifdef ALTQ_CODEL
		if (q_is_codel(cl->cl_q))
			codel_destroy(cl->cl_codel);
#endif
	}
	free(cl->cl_q, M_DEVBUF);
	free(cl, M_DEVBUF);
	return (0);
}
Exemplo n.º 17
0
void *alitem(void *list, ptrdiff_t itemsize)
{
	STDITEM	*freelist = (STDITEM *)list;

	if (qempty(STDITEM, link, freelist)) {
		STDITEM *i = (STDITEM *) joe_malloc(itemsize * 16);
		STDITEM *z = (STDITEM *) ((char *) i + itemsize * 16);

		while (i != z) {
			enquef(STDITEM, link, freelist, i);
			i = (STDITEM *) ((char *) i + itemsize);
		}
	}
	return (void *) deque_f(STDITEM, link, freelist->link.prev);
}
Exemplo n.º 18
0
void   *
madns_response(MADNS * mp, in_addr_t * ip)
{
    while (1) {
        char    pkt[DNS_PACKET_LEN];
        INADDR  sa;
        socklen_t salen = sizeof sa;
        RESPONSE resp;
        char    ips[99];

        int     len = recvfrom(mp->sock, pkt, sizeof pkt, 0,
                               (SADDR *) & sa, &salen);
        if (len <= 0)
            break;

        if (!parse_response(pkt, len, &resp))
            continue;

        LOG("resp: ip %s ttl %lu tid %hu name %s\n",
            ipstr(resp.ip, ips), resp.ttl, resp.tid, resp.name);

        QUERY  *qp = &mp->queries[(int)resp.tid % mp->qsize];

        if (qp->ctx && qp->tid == resp.tid && qp->server
            && qp->server->ip == sa.sin_addr.s_addr) {

            if (resp.ip != INADDR_ANY && !strcasecmp(resp.name, qp->name))
                update_cache(mp, &resp);
            return destroy_query(mp, qp, *ip = resp.ip);
        }

        log_packet(__LINE__, pkt, len);
        if (qp->server && qp->server->ip != sa.sin_addr.s_addr)
            LOG("resp.addr=%s tid=%hu ttl=%lu serv=%s\n",
                ipstr(sa.sin_addr.s_addr, pkt), resp.tid, resp.ttl,
                ipstr(qp->server->ip, pkt + 33));
    }

    if (!qempty(&mp->active)) {
        QUERY  *qp = link_QUERY(mp->active.next);

        if (qp->expires <= time(0))
            return destroy_query(mp, qp, *ip = INADDR_ANY);
    }

    return NULL;
}
Exemplo n.º 19
0
/* Wait for an RTP packet to arrive and return it */
mblk_t *MastTool::wait_for_rtp_packet( int seconds )
{
	struct timeval timeout;
	fd_set readfds;
	int retval = -1;


	/* reset the session */
	rtp_session_reset( session );
	
	/* set the timeout */
	timeout.tv_sec = seconds;
	timeout.tv_usec = 0;

	/* Watch socket to see when it has input */
	FD_ZERO(&readfds);
	FD_SET( rtp_session_get_rtp_socket(session), &readfds);
	retval = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);


	// Check return value 
	if (retval == -1) {
		MAST_ERROR("select() failed: %s", strerror(errno));
		return NULL;
	} else if (retval==0) {
		MAST_ERROR("Timed out waiting for packet after %d seconds", seconds);
		return NULL;
	}
	
	

	/* recieve packet and put it in queue */
	rtp_session_rtp_recv( session, 0 );
	
	
	/* check that there is something in the queue */
	if (qempty(&session->rtp.rq) ) {
		MAST_ERROR("Queue is empty after trying to recieve packet");
		return NULL;
	}
	
	/* take the packet off the queue and return it */
	return getq(&session->rtp.rq);

}
Exemplo n.º 20
0
void
madns_destroy(MADNS * mp)
{
    if (!mp)
        return;
    if (mp->sock != -1)
        (void)close(mp->sock);

    int     i;

    for (i = 0; i < mp->limit; ++i)
        free(mp->cachev[i]);

    while (!qempty(&mp->active))
        destroy_query(mp, link_QUERY(mp->active.next), 0);

    free(mp->queries), free(mp->serv), free(mp);
}
Exemplo n.º 21
0
/*
 * void
 * rmc_queue_packet(struct rm_class *cl, struct mbuf *m) - Add packet given by
 *	mbuf 'm' to queue for resource class 'cl'.  This routine is called
 *	by a driver's if_output routine.  This routine must be called with
 *	output packet completion interrupts locked out (to avoid racing with
 *	rmc_dequeue_next).
 *
 *	Returns:	0 on successful queueing
 *			-1 when packet drop occurs
 */
int
rmc_queue_packet(struct rm_class *cl, struct mbuf *m)
{
	struct timeval now;
	struct rm_ifdat *ifd = cl->ifdat_;
	int cpri = cl->pri_;
	int is_empty = qempty(cl->q_);

	RM_GETTIME(now);
	if (ifd->cutoff_ > 0) {
		if (TV_LT(&cl->undertime_, &now)) {
			if (ifd->cutoff_ > cl->depth_)
				ifd->cutoff_ = cl->depth_;
			CBQTRACE(rmc_queue_packet, 'ffoc', cl->depth_);
		}
#if 1 /* ALTQ */
		else {
			/*
			 * the class is overlimit. if the class has
			 * underlimit ancestors, set cutoff to the lowest
			 * depth among them.
			 */
			struct rm_class *borrow = cl->borrow_;

			while (borrow != NULL &&
			       borrow->depth_ < ifd->cutoff_) {
				if (TV_LT(&borrow->undertime_, &now)) {
					ifd->cutoff_ = borrow->depth_;
					CBQTRACE(rmc_queue_packet, 'ffob', ifd->cutoff_);
					break;
				}
				borrow = borrow->borrow_;
			}
		}
#else /* !ALTQ */
		else if ((ifd->cutoff_ > 1) && cl->borrow_) {
			if (TV_LT(&cl->borrow_->undertime_, &now)) {
				ifd->cutoff_ = cl->borrow_->depth_;
				CBQTRACE(rmc_queue_packet, 'ffob',
					 cl->borrow_->depth_);
			}
		}
#endif /* !ALTQ */
	}
Exemplo n.º 22
0
static void iappend(BW *bw, struct isrch *isrch, char *s, ptrdiff_t len)
{				/* Append text and search */
	/* Append char and search */
	IREC *i = alirec();
	SRCH *srch;

	i->what = len;
	i->disp = bw->cursor->byte;
	isrch->pattern = vsncpy(sv(isrch->pattern), s, len);
	if (!qempty(IREC, link, &isrch->irecs)) {
		pgoto(bw->cursor, isrch->irecs.link.prev->start);
		if (globalsrch)
			globalsrch->wrap_flag = isrch->irecs.link.prev->wrap_flag;
	}
	i->start = bw->cursor->byte;

	if (!globalsrch)
		srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0);
	else {
		srch = globalsrch;
		globalsrch = 0;
	}

	srch->addr = bw->cursor->byte;

	if (!srch->wrap_p || srch->wrap_p->b!=bw->b) {
		prm(srch->wrap_p);
		srch->wrap_p = pdup(bw->cursor, "iappend");
		srch->wrap_p->owner = &srch->wrap_p;
		srch->wrap_flag = 0;
	}

	i->wrap_flag = srch->wrap_flag;

	setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern)));
	srch->backwards = isrch->dir;

	if (dopfnext(bw, srch, NULL)) {
		if(joe_beep)
			ttputc(7);
	}
	enqueb(IREC, link, &isrch->irecs, i);
}
Exemplo n.º 23
0
int new_sequence(void) {
  unsigned long num = 0, newnum = 0;
  char c;
  for(i = 0; i < 10; i++) {
    while(qempty());
    c = getq();
    newnum = (c - '0') * pow(10, 9 - i);
    if (num + newnum < num) { // Check for rollover
         status = 'e';
         set_lcd_addr(0);
         type_lcd("Sequence goes");
         set_lcd_addr(0x40);
         type_lcd("above 2^32!");
         return -1;
    }
    
    num += newnum; // we passed test
  }
   
  while (num != 1){
      
      set_lcd_addr(0);
      if (display_mode) write_long_lcd(num);
     if (num % 2 == 0)
        num /= 2;
     else{
        newnum = (num * 3) + 1;
        if (newnum < num){ // Check for rollover.
          status = 'e';
          set_lcd_addr(0);
          type_lcd("Sequence goes");
          set_lcd_addr(0x40);
          type_lcd("above 2^32!");
          return -1;
        }
        num = newnum; // we passed test
     }
     if (slow_mode) ms_delay(750);// to make sure we see what numbers we're getting
  }
  if (display_mode) write_long_lcd(num);
  status = 'i'; 
  return num;  
}
Exemplo n.º 24
0
/* discard all the queued packets on the interface */
void
priq_purge(struct priq_if *pif)
{
	struct priq_class *cl;
	int pri;

	IFCQ_LOCK_ASSERT_HELD(pif->pif_ifq);

	for (pri = 0; pri <= pif->pif_maxpri; pri++) {
		if ((cl = pif->pif_classes[pri]) != NULL && !qempty(&cl->cl_q))
			priq_purgeq(pif, cl, 0, NULL, NULL);
	}
#if !PF_ALTQ
	/*
	 * This assertion is safe to be made only when PF_ALTQ is not
	 * configured; otherwise, IFCQ_LEN represents the sum of the
	 * packets managed by ifcq_disc and altq_disc instances, which
	 * is possible when transitioning between the two.
	 */
	VERIFY(IFCQ_LEN(pif->pif_ifq) == 0);
#endif /* !PF_ALTQ */
}
Exemplo n.º 25
0
static int
priq_class_destroy(struct priq_class *cl)
{
	struct priq_if *pif;
	int pri;

	crit_enter();

	if (!qempty(cl->cl_q))
		priq_purgeq(cl);

	pif = cl->cl_pif;
	pif->pif_classes[cl->cl_pri] = NULL;
	if (pif->pif_maxpri == cl->cl_pri) {
		for (pri = cl->cl_pri; pri >= 0; pri--)
			if (pif->pif_classes[pri] != NULL) {
				pif->pif_maxpri = pri;
				break;
			}
		if (pri < 0)
			pif->pif_maxpri = -1;
	}
	crit_exit();

	if (cl->cl_red != NULL) {
#ifdef ALTQ_RIO
		if (q_is_rio(cl->cl_q))
			rio_destroy((rio_t *)cl->cl_red);
#endif
#ifdef ALTQ_RED
		if (q_is_red(cl->cl_q))
			red_destroy(cl->cl_red);
#endif
	}
	kfree(cl->cl_q, M_ALTQ);
	kfree(cl, M_ALTQ);
	return (0);
}
Exemplo n.º 26
0
/* put an rtp packet in queue. It is called by rtp_parse()*/
void rtp_putq(queue_t *q, mblk_t *mp)
{
	mblk_t *tmp;
	rtp_header_t *rtp=(rtp_header_t*)mp->b_rptr,*tmprtp;
	/* insert message block by increasing time stamp order : the last (at the bottom)
		message of the queue is the newest*/
	ortp_debug("rtp_putq(): Enqueuing packet with ts=%i and seq=%i",rtp->timestamp,rtp->seq_number);
	
	if (qempty(q)) {
		putq(q,mp);
		return;
	}
	tmp=qlast(q);
	/* we look at the queue from bottom to top, because enqueued packets have a better chance
	to be enqueued at the bottom, since there are surely newer */
	while (!qend(q,tmp))
	{
		tmprtp=(rtp_header_t*)tmp->b_rptr;
		ortp_debug("rtp_putq(): Seeing packet with seq=%i",tmprtp->seq_number);
		
 		if (rtp->seq_number == tmprtp->seq_number)
 		{
 			/* this is a duplicated packet. Don't queue it */
 			ortp_debug("rtp_putq: duplicated message.");
 			freemsg(mp);
 			return;
		}else if (RTP_SEQ_IS_GREATER(rtp->seq_number,tmprtp->seq_number)){
			
			insq(q,tmp->b_next,mp);
			return;
 		}
		tmp=tmp->b_prev;
	}
	/* this packet is the oldest, it has to be 
	placed on top of the queue */
	insq(q,qfirst(q),mp);
	
}
void bfs_search(int (*map)[NODESIZE]) {
    int i,step;
    struct Node *currentnode=malloc(sizeof(struct Node));
    currentnode->vertex=STARTNODE,currentnode->prev=NULL,currentnode->height=0;
    enqueue(currentnode);
    int neibors[NODESIZE],neiborsize;
    struct Node *node;
    while(!qempty()) {
        currentnode=dequeue();
        step=currentnode->height;
        if(step==NODESIZE-1 && isneibor(map,currentnode->vertex,STARTNODE)) {
            displayout_come(currentnode);
            //break;
        }
        getneibors(map,currentnode->vertex,neibors,&neiborsize);
        for(i=0; i<neiborsize; i++)
            if(!inme(currentnode,neibors[i])) {
                node=malloc(sizeof(struct Node));
                node->height=step+1,node->prev=currentnode,node->vertex=neibors[i];
                enqueue(node);
            }
    }
}
Exemplo n.º 28
0
static struct priq_class *
priq_class_create(struct priq_if *pif, int pri, int qlimit, int flags, int qid)
{
	struct priq_class *cl;
	int s;

#ifndef ALTQ_RED
	if (flags & PRCF_RED) {
#ifdef ALTQ_DEBUG
		printf("priq_class_create: RED not configured for PRIQ!\n");
#endif
		return (NULL);
	}
#endif

	if ((cl = pif->pif_classes[pri]) != NULL) {
		/* modify the class instead of creating a new one */
		s = splnet();
		if (!qempty(cl->cl_q))
			priq_purgeq(cl);
		splx(s);
#ifdef ALTQ_RIO
		if (q_is_rio(cl->cl_q))
			rio_destroy((rio_t *)cl->cl_red);
#endif
#ifdef ALTQ_RED
		if (q_is_red(cl->cl_q))
			red_destroy(cl->cl_red);
#endif
	} else {
		cl = malloc(sizeof(struct priq_class), M_DEVBUF,
		    M_WAITOK|M_ZERO);
		if (cl == NULL)
			return (NULL);

		cl->cl_q = malloc(sizeof(class_queue_t), M_DEVBUF,
		    M_WAITOK|M_ZERO);
		if (cl->cl_q == NULL)
			goto err_ret;
	}

	pif->pif_classes[pri] = cl;
	if (flags & PRCF_DEFAULTCLASS)
		pif->pif_default = cl;
	if (qlimit == 0)
		qlimit = 50;  /* use default */
	qlimit(cl->cl_q) = qlimit;
	qtype(cl->cl_q) = Q_DROPTAIL;
	qlen(cl->cl_q) = 0;
	cl->cl_flags = flags;
	cl->cl_pri = pri;
	if (pri > pif->pif_maxpri)
		pif->pif_maxpri = pri;
	cl->cl_pif = pif;
	cl->cl_handle = qid;

#ifdef ALTQ_RED
	if (flags & (PRCF_RED|PRCF_RIO)) {
		int red_flags, red_pkttime;

		red_flags = 0;
		if (flags & PRCF_ECN)
			red_flags |= REDF_ECN;
#ifdef ALTQ_RIO
		if (flags & PRCF_CLEARDSCP)
			red_flags |= RIOF_CLEARDSCP;
#endif
		if (pif->pif_bandwidth < 8)
			red_pkttime = 1000 * 1000 * 1000; /* 1 sec */
		else
			red_pkttime = (int64_t)pif->pif_ifq->altq_ifp->if_mtu
			  * 1000 * 1000 * 1000 / (pif->pif_bandwidth / 8);
#ifdef ALTQ_RIO
		if (flags & PRCF_RIO) {
			cl->cl_red = (red_t *)rio_alloc(0, NULL,
						red_flags, red_pkttime);
			if (cl->cl_red != NULL)
				qtype(cl->cl_q) = Q_RIO;
		} else
#endif
		if (flags & PRCF_RED) {
			cl->cl_red = red_alloc(0, 0,
			    qlimit(cl->cl_q) * 10/100,
			    qlimit(cl->cl_q) * 30/100,
			    red_flags, red_pkttime);
			if (cl->cl_red != NULL)
				qtype(cl->cl_q) = Q_RED;
		}
	}
#endif /* ALTQ_RED */

	return (cl);

 err_ret:
	if (cl->cl_red != NULL) {
#ifdef ALTQ_RIO
		if (q_is_rio(cl->cl_q))
			rio_destroy((rio_t *)cl->cl_red);
#endif
#ifdef ALTQ_RED
		if (q_is_red(cl->cl_q))
			red_destroy(cl->cl_red);
#endif
	}
	if (cl->cl_q != NULL)
		free(cl->cl_q, M_DEVBUF);
	free(cl, M_DEVBUF);
	return (NULL);
}
Exemplo n.º 29
0
static void freeall(void)
{
	while (!qempty(ERROR, link, &errors))
		freeerr(deque_f(ERROR, link, errors.link.next));
	errptr = &errors;
}
Exemplo n.º 30
0
/* When called with c==-1, it just creates the prompt */
static int itype(W *w, int c, void *obj, int *notify)
{
	IREC *i;
	int omid;
	BW *bw;
	struct isrch *isrch = (struct isrch *)obj;
	WIND_BW(bw,w);

	if (isrch->quote) {
		goto in;
	}
	if (c == 8 || c == 127) {	/* Backup */
		if ((i = isrch->irecs.link.prev) != &isrch->irecs) {
			pgoto(bw->cursor, i->disp);
			if (globalsrch)
				globalsrch->wrap_flag = i->wrap_flag;
			omid = opt_mid;
			opt_mid = 1;
			dofollows();
			opt_mid = omid;
			isrch->pattern = vstrunc(isrch->pattern, sLEN(isrch->pattern) - i->what);
			frirec(deque_f(IREC, link, i));
		} else {
			if(joe_beep)
				ttputc(7);
		}
	} else if (c == 'Q' - '@' /* || c == '`' */) {
		isrch->quote = 1;
	} else if (c == 'S' - '@' || c == '\\' - '@' || c == 'L' - '@' || c == 'R' - '@') {
		/* Repeat */
		if (c == 'R' - '@') {
			isrch->dir = 1;
		} else {
			isrch->dir = 0;
		}
		if (qempty(IREC, link, &isrch->irecs)) {
			if (lastpat && lastpat[0]) {
				iappend(bw, isrch, sv(lastpat));
			}
		} else {
			SRCH *srch;
			i = alirec();
			i->disp = i->start = bw->cursor->byte;
			i->what = 0;

			if (!globalsrch)
				srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0);
			else {
				srch = globalsrch;
				globalsrch = 0;
			}

			srch->addr = bw->cursor->byte;

			if (!srch->wrap_p || srch->wrap_p->b!=bw->b) {
				prm(srch->wrap_p);
				srch->wrap_p = pdup(bw->cursor, "itype");
				srch->wrap_p->owner = &srch->wrap_p;
				srch->wrap_flag = 0;
			}

			i->wrap_flag = srch->wrap_flag;

			setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern)));
			srch->backwards = isrch->dir;

			if (dopfnext(bw, srch, NULL)) {
				if(joe_beep)
					ttputc(7);
				frirec(i);
			} else {
				enqueb(IREC, link, &isrch->irecs, i);
			}
		}
	} else if (c >= 0 && c < 32) {
		/* Done when a control character is received */
		nungetc(c);
		if (notify) {
			*notify = 1;
		}
		smode = 2;
		if (lastisrch) {
			lastpat = vstrunc(lastpat, 0);
			lastpat = vsncpy(lastpat, 0, lastisrch->pattern, sLen(lastisrch->pattern));
			rmisrch(lastisrch);
		}
		lastisrch = isrch;
		return 0;
	} else if (c != -1) {
		char buf[16];
		ptrdiff_t buf_len;
		/* Search */

		in:

		if (bw->b->o.charmap->type) {
			buf_len = utf8_encode(buf, c);
		} else {
			buf[0] = TO_CHAR_OK(from_uni(bw->b->o.charmap, c));
			buf_len = 1;
		}		

		isrch->quote = 0;
		iappend(bw, isrch, buf, buf_len);
	}
	omid = opt_mid;
	opt_mid = 1;
	bw->cursor->xcol = piscol(bw->cursor);
	dofollows();
	opt_mid = omid;

	isrch->prompt = vstrunc(isrch->prompt, isrch->ofst);

	if (locale_map->type && !bw->b->o.charmap->type) {
		/* Translate bytes to utf-8 */
		char buf[16];
		int x;
		for (x=0; x!=sLEN(isrch->pattern); ++x) {
			int tc = to_uni(bw->b->o.charmap, isrch->pattern[x]);
			utf8_encode(buf, tc);
			isrch->prompt = vsncpy(sv(isrch->prompt),sz(buf));
		}
	} else if (!locale_map->type && bw->b->o.charmap->type) {
		/* Translate utf-8 to bytes */
		const char *p = isrch->pattern;
		ptrdiff_t len = sLEN(isrch->pattern);
		while (len) {
			int tc = utf8_decode_fwrd(&p, &len);
			if (tc >= 0) {
				tc = from_uni(locale_map, tc);
				isrch->prompt = vsadd(isrch->prompt, TO_CHAR_OK(tc));
			}
		}
	} else {
		/* FIXME: translate when charmaps do not match */
		isrch->prompt = vsncpy(sv(isrch->prompt),sv(isrch->pattern));
	}

	if (mkqwnsr(bw->parent, sv(isrch->prompt), itype, iabrt, isrch, notify)) {
		return 0;
	} else {
		rmisrch(isrch);
		return -1;
	}
}