int q_test(void) { msg_t my_msg; int i=0; int size = 5; print("size of msg_t [%d] sizeof qb_t[%d]",sizeof(msg_t),sizeof(qb_t)); qb_t *p = malloc(sizeof(qb_t)); p->buffer = (msg_t *)malloc(sizeof(msg_t)*size); p->wptr=p->rptr=p->buffer; p->end = (msg_t *)p->buffer + size; my_msg.key=31; my_msg.type=1; q_write(p,&my_msg,sizeof(msg_t)); my_msg.key=32; my_msg.type=2; q_write(p,&my_msg,sizeof(msg_t)); my_msg.key=33; my_msg.type=3; q_write(p,&my_msg,sizeof(msg_t)); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); i++; q_free(p); return 0; }
int fifo_test(void) { int size= 10; u8 buf; qb_t *p = malloc(sizeof(qb_t)); p->buffer = (u8 *)malloc(size); p->wptr=p->rptr=p->buffer; p->end = (msg_t *)p->buffer + size; print("fifo test"); buf=1; q_write(p,&buf,1); buf=2; q_write(p,&buf,1); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); //q_free(p->buffer); q_free(p); return 0; }
static char *test_q_read() { packet *q = q_create(); packet p = pkt_create(REFERENCE, 0, 0, 0, 0); packet p2 = pkt_create(ERROR, 0, 0, 0, 0); q_write(p, 0, q, N); q_read(&p2, 0, q, N); mu_assert("FAIL: test_q_read [1]", (p.x == p2.x) && (p.y == p2.y)); q_read(&p2, 0, q, N); mu_assert("FAIL: test_q_read [2]", !q_read(&p2, 0, q, N)); q_destroy(q); return NULL; }
static void readable(struct sockifo* ifo) { if (ifo->state.type == TYPE_LISTEN) { if (ifo->ifo_newfd >= 0) { ifo->state.poll = POLL_HANG; return; } union sockaddrs addr; unsigned int addrlen = sizeof(addr); char linebuf[100]; int fd = accept(ifo->fd, &addr.sa, &addrlen); if (fd < 0) return; if (addr.sa.sa_family == AF_INET6) { inet_ntop(AF_INET6, &addr.in6.sin6_addr, linebuf, sizeof(linebuf)); char* atxt = linebuf; if (!strncmp("::ffff:", linebuf, 7)) atxt += 7; qprintf(&sockets->net[0].sendq, "P %d %s\n", ifo->netid, atxt); } else { inet_ntop(AF_INET, &addr.in4.sin_addr, linebuf, sizeof(linebuf)); qprintf(&sockets->net[0].sendq, "P %d %s\n", ifo->netid, linebuf); } ifo->ifo_newfd = fd; ifo->state.poll = POLL_HANG; return; } if (ifo->state.poll == POLL_FORCE_ROK) { ifo->state.poll = POLL_NORMAL; } #if SSL_ENABLED if (ifo->state.ssl) { ssl_readable(ifo); } else #endif { int r = q_read(ifo->fd, &ifo->recvq); if (r) { esock(ifo, r == 1 ? "Connection closed" : strerror(errno)); } } while (1) { struct line line = q_getl(&ifo->recvq); if (!line.data) break; if (ifo->state.type == TYPE_NETWORK && !ifo->state.mplex_dropped) { qprintf(&sockets->net[0].sendq, "%d ", ifo->netid); q_putl(&sockets->net[0].sendq, line, 1); ifo->death_time = now + TIMEOUT; } else if (ifo->state.type == TYPE_MPLEX) { mplex_parse(line); } } // prevent memory DoS by sending infinite text without \n if (ifo->recvq.end - ifo->recvq.start > IDEAL_QUEUE) { esock(ifo, "Line too long"); } }
static char *test_q_get_head_index() { packet *q = q_create(); packet i; mu_assert("FAIL: test_q_get_head_index [1]", q_get_head_index(0, 0, q, N) == 0); q_write(i, 0, q, N); q_read(&i, 0, q, N); mu_assert("FAIL: test_q_get_head_index [2]", q_get_head_index(0, 0, q, N) == 1); q_destroy(q); return NULL; }
static char *test_q_is_empty() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_is_empty [1]", q_is_empty(0, 0, q, N)); q_write(p, 0, q, N); mu_assert("FAIL: test_q_is_empty [2]", !q_is_empty(0, 0, q, N)); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_is_empty [3]", q_is_empty(0, 0, q, N)); q_destroy(q); return NULL; }
static char *test_q_transfer() { packet *q = q_create(); packet *rq = q_create(); packet p = pkt_create(DATA, 1, 2, 3, 4); packet p2; q_write(p, 0, rq, 4); q_transfer(rq, q, 4); q_read(&p2, 0, q, 4); mu_assert("FAIL: test_q_transfer", (p.x == p2.x) && (p.y == p2.y)); q_destroy(q); q_destroy(rq); return NULL; }
static char *test_q_size() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_size [1]", q_size(0, 0, q, N) == 0); for (int i = 0; i < 20; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_size [2]", q_size(0, 0, q, N) == 16); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_size [3]", q_size(0, 0, q, N) == 15); q_destroy(q); return NULL; }
static char *test_q_is_full() { packet *q = q_create(); packet p = pkt_create(ERROR, 0, 0, 0, 0); mu_assert("FAIL: test_q_is_full [1]", !q_is_full(0, 0, q, N)); for (int i = 0; i < 16; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_is_full [2]", q_is_full(0, 0, q, N)); q_read(&p, 0, q, N); mu_assert("FAIL: test_q_is_full [3]", !q_is_full(0, 0, q, N)); q_destroy(q); return NULL; }
static void setup_call(SIG_ENTITY *sig,unsigned long call_ref) { SOCKET *sock,*this,**walk; struct sockaddr_atmsvc in_addr; struct atm_sap in_sap; struct atm_qos in_qos; unsigned int problem; int i; problem = sap_decode(&in_dsc,&in_addr,&in_sap,&in_qos,sig->uni); if (problem) { send_release_complete(sig,call_ref,IE_PB_CAUSE(problem), IE_PB_IE(problem)); return; } if (!atmsvc_addr_in_use(in_addr)) { send_release_complete(sig,call_ref,ATM_CV_UNALLOC); return; } if (!allow(&in_addr,ACL_IN)) { send_release_complete(sig,call_ref,ATM_CV_REJ_CLIR); return; } this = new_sock(kptr_null); this->sig = sig; sock = lookup_sap(&in_addr,&in_sap,&in_qos,&this->local,&this->sap, &this->qos,0); if (!sock) { free_sock(this); send_release_complete(sig,call_ref,ATM_CV_INCOMP_DEST); return; } this->state = sig->mode == sm_net ? ss_proceeding : ss_indicated; this->call_state = cs_in_proc; this->call_ref = call_ref; if (q_present(&in_dsc,QF_ep_ref)) this->ep_ref = cvt_ep_ref(sig,q_fetch(&in_dsc,QF_ep_ref)); #ifdef CISCO else #endif if (sig->mode == sm_net) { int error; error = send_call_proceeding(this); if (error) { free_sock(this); send_release_complete(sig,call_ref,ATM_CV_NO_CI); return; } } /* if (sock->local) *this->local->sas_addr = sock->local->sas_addr; ??? */ diag(COMPONENT,DIAG_DEBUG,"AAL type %ld",q_fetch(&in_dsc,QF_aal_type)); if (sig->mode == sm_user) { /* already set by send_call_proceeding */ int vpci; vpci = q_fetch(&in_dsc,QF_vpi); this->pvc.sap_family = AF_ATMPVC; this->pvc.sap_addr.itf = get_itf(sig,&vpci); this->pvc.sap_addr.vpi = vpci; this->pvc.sap_addr.vci = q_fetch(&in_dsc,QF_vci); } diag(COMPONENT,DIAG_DEBUG,"ITF.VPI.VCI: %d.%d.%d",this->pvc.sap_addr.itf, this->pvc.sap_addr.vpi,this->pvc.sap_addr.vci); if (q_present(&in_dsc,QF_cgpn)) { /* should handle E.164 too */ char buffer[MAX_ATM_ADDR_LEN+1]; int plan; plan = q_fetch(&in_dsc,QF_cgpn_plan); switch (plan) { case ATM_NP_AEA: i = q_read(&in_dsc,QF_cgpn,(void *) this->remote.sas_addr.prv, ATM_ESA_LEN); break; case ATM_NP_E164: i = q_read(&in_dsc,QF_cgpn,(void *) this->remote.sas_addr.pub, ATM_E164_LEN); break; default: diag(COMPONENT,DIAG_WARN,"Ignoring cgpn with unrecognized " "numbering plan 0x%x\n",plan); i = 0; } if (i) { this->remote.sas_family = AF_ATMSVC; if (atm2text(buffer,MAX_ATM_ADDR_LEN+1, (struct sockaddr *) &this->remote,pretty) < 0) strcpy(buffer,"<invalid address>"); diag(COMPONENT,DIAG_DEBUG,"Incoming call from %s",buffer); } } send_kernel(kptr_null,sock->id,as_indicate,0,&this->pvc,&this->remote, &in_addr,&this->sap,&this->qos); for (walk = &sock->listen; *walk; walk = &(*walk)->listen); *walk = this; diag(COMPONENT,DIAG_DEBUG,"SE vpi.vci=%d.%d",this->pvc.sap_addr.vpi, this->pvc.sap_addr.vci); }