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 int encode_blli(Q_DSC *dsc,const struct atm_blli *blli) { if (blli->l2_proto != ATM_L2_NONE) { q_assign(dsc,QF_uil2_proto,blli->l2_proto); switch (blli->l2_proto) { case ATM_L2_X25_LL: case ATM_L2_X25_ML: case ATM_L2_HDLC_ARM: case ATM_L2_HDLC_NRM: case ATM_L2_HDLC_ABM: case ATM_L2_Q922: case ATM_L2_ISO7776: if (blli->l2.itu.mode != ATM_IMD_NONE) q_assign(dsc,QF_l2_mode,blli->l2.itu.mode); if (blli->l2.itu.window) q_assign(dsc,QF_window_size,blli->l2.itu.window); break; case ATM_L2_USER: q_assign(dsc,QF_user_l2,blli->l2.user); break; default: break; } } if (blli->l3_proto != ATM_L3_NONE) { q_assign(dsc,QF_uil3_proto,blli->l3_proto); switch (blli->l3_proto) { case ATM_L3_X25: case ATM_L3_ISO8208: case ATM_L3_X223: if (blli->l3.itu.mode != ATM_IMD_NONE) q_assign(dsc,QF_l3_mode,blli->l3.itu.mode); if (blli->l3.itu.def_size) q_assign(dsc,QF_def_pck_size,blli->l3.itu.def_size); if (blli->l3.itu.window) q_assign(dsc,QF_pck_win_size,blli->l3.itu.window); break; case ATM_L3_TR9577: q_assign(dsc,QF_ipi_high,blli->l3.tr9577.ipi >> 1); q_assign(dsc,QF_ipi_low,blli->l3.tr9577.ipi & 1); if (blli->l3.tr9577.ipi == NLPID_IEEE802_1_SNAP) { q_write(dsc,QF_oui,blli->l3.tr9577.snap,3); q_write(dsc,QF_pid,blli->l3.tr9577.snap+3,2); } break; case ATM_L3_USER: q_assign(dsc,QF_user_l3,blli->l3.user); break; default: diag(COMPONENT,DIAG_ERROR,"bad l3_proto (%d)", blli->l3_proto); return -EINVAL; } }
static char *test_q_get_tail_index() { packet *q = q_create(); packet i; mu_assert("FAIL: test_q_get_tail_index [1]", q_get_tail_index(0, 0, q, N) == 0); q_write(i, 1, q, N); q_write(i, 1, q, N); mu_assert("FAIL: test_q_get_tail_index [2]", q_get_tail_index(1, 0, q, N) == 2); mu_assert("FAIL: test_q_get_tail_index [3]", q_get_tail_index(0, 0, q, N) == 0); q_write(i, 0, q, N); mu_assert("FAIL: test_q_get_tail_index [4]", q_get_tail_index(0, 0, q, N) == 1); q_destroy(q); return NULL; }
static char *test_q_write() { packet *q = q_create(); packet p = pkt_create(DATA, 1, 2, 3, 4); q_write(p, 0, q, N); mu_assert("FAIL: test_q_write [1]", !q_is_empty(0, 0, q, N)); q_write(p, 0, q, N); mu_assert("FAIL: test_q_write [2]", q_size(0, 0, q, N) == 2); for (int i = 0; i < 14; i++) { q_write(p, 0, q, N); } mu_assert("FAIL: test_q_write [3]", !q_write(p, 0, q, N)); q_destroy(q); return NULL; }
static void writable(struct sockifo* ifo) { if (ifo->state.connpend) { ifo->state.connpend = 0; int err = 0; socklen_t esize = sizeof(int); getsockopt(ifo->fd, SOL_SOCKET, SO_ERROR, &err, &esize); if (err) { esock(ifo, strerror(err)); return; } ifo->state.poll = ifo->state.frozen ? POLL_HANG : POLL_NORMAL; } #if SSL_ENABLED if (ifo->state.ssl) { ssl_writable(ifo); } else #endif { int r = q_write(ifo->fd, &ifo->sendq); if (r) { esock(ifo, r == 1 ? "Connection closed" : strerror(errno)); } else if (ifo->state.mplex_dropped && ifo->sendq.start == ifo->sendq.end) { close(ifo->fd); ifo->fd = -1; } } }
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_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 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 send_status(SIG_ENTITY *sig,SOCKET *sock,unsigned long call_ref, unsigned char cause,...) { va_list ap; Q_DSC dsc; int size; q_create(&dsc,q_buffer,MAX_Q_MSG); q_assign(&dsc,QF_msg_type,ATM_MSG_STATUS); if (sock) { q_assign(&dsc,QF_call_ref,sock->call_ref); q_assign(&dsc,QF_call_state,(int) sock->call_state); if (sock->ep_ref >= 0) { q_assign(&dsc,QF_ep_ref,sock->ep_ref); q_assign(&dsc,QF_ep_state,eps_map[sock->call_state]); } } else { q_assign(&dsc,QF_call_ref,call_ref); q_assign(&dsc,QF_call_state,0); /* U0 - Null / REST 0 - Null */ } q_assign(&dsc,QF_cause,cause); va_start(ap,cause); switch (cause) { case ATM_CV_UNKNOWN_MSG_TYPE: case ATM_CV_INCOMP_MSG: q_assign(&dsc,QF_bad_msg_type,va_arg(ap,unsigned int)); break; case ATM_CV_MAND_IE_MISSING: case ATM_CV_INVALID_IE: { unsigned char ie; ie = va_arg(ap,unsigned int); q_write(&dsc,QF_ie_id6,&ie,1); break; } default: ; } va_end(ap); if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size); }
void send_release(SOCKET *sock,unsigned char reason,...) { va_list ap; Q_DSC dsc; int size; q_create(&dsc,q_buffer,MAX_Q_MSG); q_assign(&dsc,QF_msg_type,ATM_MSG_RELEASE); q_assign(&dsc,QF_call_ref,sock->call_ref); q_assign(&dsc,QF_cause,reason); va_start(ap,reason); switch (reason) { case ATM_CV_TIMER_EXP: { char buf[4]; sprintf(buf,"%d",va_arg(ap,int)); q_write(&dsc,QF_timer,buf,3); break; } default: } va_end(ap); if ((size = q_close(&dsc)) >= 0) to_signaling(sock->sig,q_buffer,size); } void send_release_complete(SIG_ENTITY *sig,unsigned long call_ref, unsigned char cause,...) { va_list ap; Q_DSC dsc; int size; q_create(&dsc,q_buffer,MAX_Q_MSG); q_assign(&dsc,QF_msg_type,ATM_MSG_REL_COMP); q_assign(&dsc,QF_call_ref,call_ref); if (cause) { q_assign(&dsc,QF_cause,cause); va_start(ap,cause); switch (cause) { case ATM_CV_INVALID_IE: { unsigned char ie; ie = va_arg(ap,int); q_write(&dsc,QF_ie_id6,&ie,1); } break; default: } va_end(ap); } if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size); } void send_modify_reject(SOCKET *sock,unsigned char reason) { Q_DSC dsc; int size; q_create(&dsc,q_buffer,MAX_Q_MSG); q_assign(&dsc,QF_msg_type,ATM_MSG_MODIFY_REJ); q_assign(&dsc,QF_call_ref,sock->call_ref); q_assign(&dsc,QF_cause,reason); if ((size = q_close(&dsc)) >= 0) to_signaling(sock->sig,q_buffer,size); }