/** 1バイト入力 * 1つ前のデータが '¥r'だったら '¥0' が返ってくる。 * しかし、'¥r' から '¥0' の間に若干時間が掛かる。 * そのため、ここではその処理をしない。 * @param cnsl コンソール * @param c 入力文字 * @return TRUE:正常、FALSE:異常 ****************************************************************************** */ BOOL TELNET_GetByte( CONSOLE *cnsl, UB *c ) { BOOL stat = FALSE; TELNET_PARA *para; ER rcvlen; para = (TELNET_PARA*)cnsl->Parameter; if( !para->OpenFg ) goto EXIT; #if 1 // ブロッキングコール rcvlen = tcp_rcv_dat( para->CepID, (VP*)c, 1, TMO_FEVR ); if( rcvlen != 1 ) goto EXIT; /* if( rcvlen <= 0 ) { if( rcvlen != E_OK ) syslog( LOG_NOTICE, "[TCP ECHO SRV RCV] error: %s", itron_strerror( rcvlen ) ); } */ #else // 省コピー ER errcd; UB *rcvbf; // rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, para->Timeout ); /* データ受信 */ rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, TMO_FEVR ); /* データ受信 */ if( rcvlen == E_TMOUT ) // タイムアウトだったら(TMO_FEVRを指定しているので実際にはない) rcvlen = 0; // 受信長をゼロにする。 else if( rcvlen == 0 ) /* 受信終了(接続断) */ rcvlen = E_TMOUT; // タイムアウトエラーにする。 if( rcvlen < 0 ) { /* エラー */ //DBG_PRINT( DBG_DISPLAY_ERROR, ( "tcp_rcv_buf() Error: %s" LINE_END, itron_strerror( rcvlen ) )); goto EXIT; } *c = *rcvbf; //DBG_Printf( DBG_DISPLAY_CONDITION, ( "rblen:%d, Input:%c(%02X)¥n", rblen, (char)( isprint( *c )? *c: '_' ), *c ) ); errcd = tcp_rel_buf( para->CepID, 1 ); /* 受信用バッファの解放 */ if( errcd != E_OK ) { //DBG_PRINT( DBG_DISPLAY_ERROR, ( "tcp_rel_buf() Error: %s" LINE_END, itron_strerror( errcd ) )); goto EXIT; } #endif stat = TRUE; EXIT:; return( stat ); }
void tcp_echo_srv_task(intptr_t exinf) { ID tskid; ER_UINT rlen, slen; ER error = E_OK; uint16_t soff, count, total; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV:%d,%d] started.", tskid, (int_t)exinf); while (true) { if (tcp_acp_cep((int_t)exinf, TCP_ECHO_SRV_REPID, &dst, TMO_FEVR) != E_OK) { syslog(LOG_NOTICE, "[TCP ECHO SRV ACP] error: %s", itron_strerror(error)); continue; } total = count = 0; syslog(LOG_NOTICE, "[TCP ECHO SRV ACP] connected from %s:%d", ip2str(NULL, &dst.ipaddr), dst.portno); while (true) { if ((rlen = tcp_rcv_dat((int_t)exinf, buffer, BUF_SIZE - 1, TMO_FEVR)) <= 0) { if (rlen != E_OK) syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] error: %s", itron_strerror(rlen)); break; } /*syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] count: %4d, len: %4d, data %02x -> %02x", ++ count, (uint16_t)rlen, *buffer, *(buffer + rlen - 1));*/ count ++; total += (uint16_t)rlen; soff = 0; while (rlen > 0) { if ((slen = tcp_snd_dat((int_t)exinf, &buffer[soff], rlen, TMO_FEVR)) < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV SND] error: %s", itron_strerror(slen)); goto err_fin; } /*syslog(LOG_NOTICE, "[TCP ECHO SRV SND] len: %d", slen);*/ rlen -= slen; soff += (uint16_t)slen; } } err_fin: if ((error = tcp_sht_cep((int_t)exinf)) != E_OK) syslog(LOG_NOTICE, "[TCP ECHO SRV SHT] error: %s", itron_strerror(error)); if ((error = tcp_cls_cep((int_t)exinf, TMO_FEVR)) != E_OK) syslog(LOG_NOTICE, "[TCP ECHO SRV CLS] error: %s", itron_strerror(error)); syslog(LOG_NOTICE, "[TCP ECHO SRV FIN] finished, total cnt: %d, len: %d", count, total); } }
static ER tcp_discard_srv (ID cepid, ID repid) { static char buffer[BUF_SIZE]; T_IPEP dst; ER_UINT rlen; ER error; SYSTIM time; uint32_t total; uint16_t count; uint8_t *buf = buffer; if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) { syslog(LOG_NOTICE, "[TDS:%02d RCV] accept error: %s", cepid, itron_strerror(error)); return error; } #ifdef USE_TCP_EXTENTIONS if ((error = free_tcp_rep(repid, true)) != E_OK) { syslog(LOG_NOTICE, "[TDS:%02d DEL] REP delete error: %s", cepid, itron_strerror(error)); return error; } #endif /* of #ifdef USE_TCP_EXTENTIONS */ count = total = 0; get_tim(&time); syslog(LOG_NOTICE, "[TDS:%02d RCV] connected: %6ld, from: %s.%d", cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno); while ((rlen = tcp_rcv_dat(cepid, buf, BUF_SIZE - 1, TMO_FEVR)) > 0) { count ++; #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TDS:%02d RCV] count: %4d, len: %4d, data: %02x -> %02x", cepid, count, (uint16_t)rlen, *buf, *(buf + rlen - 1)); #endif /* of #ifdef SHOW_RCV_RANGE */ total += rlen; } if (rlen != 0) syslog(LOG_NOTICE, "[TDS:%02d RCV] recv error: %s", cepid, itron_strerror(rlen)); if ((error = tcp_sht_cep(cepid)) != E_OK) syslog(LOG_NOTICE, "[TDS:%02d RCV] shutdown error: %s", cepid, itron_strerror(error)); if ((error = tcp_cls_cep(cepid, TMO_FEVR)) != E_OK) syslog(LOG_NOTICE, "[TDS:%02d RCV] close error: %s", cepid, itron_strerror(error)); get_tim(&time); syslog(LOG_NOTICE, "[TDS:%02d RCV] finished: %6ld, rcv: %4d, len: %ld", cepid, time / SYSTIM_HZ, count, total); return error; }
/* #[<ENTRY_FUNC>]# eC0_receive * name: eC0_receive * global_name: tTINETClient_eC0_receive * oneway: false * #[</ENTRY_FUNC>]# */ ER_UINT eC0_receive(CELLIDX idx, int8_t* buf, int16_t size, TMO tmo) { ER ercd = E_OK; CELLCB *p_cellcb; if (VALID_IDX(idx)) { p_cellcb = GET_CELLCB(idx); } else { return(E_ID); } /* ここに処理本体を記述します */ ercd = tcp_rcv_dat( ATTR_cep_id, buf, (size_t)size, tmo ); return(ercd); }
int cg_socket_read(CgSocket *sock, char *buffer, int bufferLen) { int recvLen; #if defined(CG_USE_OPENSSL) if (cg_socket_isssl(sock) == FALSE) { #endif #if defined(BTRON) || (defined(TENGINE) && !defined(CG_TENGINE_NET_KASAGO)) recvLen = so_recv(sock->id, buffer, bufferLen, 0); #elif defined(TENGINE) && defined(CG_TENGINE_NET_KASAGO) recvLen = ka_recv(sock->id, buffer, bufferLen, 0); #elif defined(ITRON) recvLen = tcp_rcv_dat(sock->id, buffer, bufferLen, TMO_FEVR); #else recvLen = recv(sock->id, buffer, bufferLen, 0); #endif #if defined(CG_USE_OPENSSL) } else { recvLen = SSL_read(sock->ssl, buffer, bufferLen); } #endif cg_log_debug_l4("Entering...\n"); #ifdef SOCKET_DEBUG if (0 <= recvLen) buffer[recvLen] = '\0'; cg_log_debug_s("r %d : %s\n", recvLen, (0 <= recvLen) ? buffer : ""); #endif cg_log_debug_l4("Leaving...\n"); return recvLen; }
static ER tcp_echo_srv (ID cepid, ID repid) { ER_UINT rlen, slen; ER error = E_OK; SYSTIM now; uint32_t total; uint16_t soff, scount, rcount; if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error)); return error; } #ifdef USE_TCP_EXTENTIONS if ((error = free_tcp_rep(repid, true)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error)); #endif /* of #ifdef USE_TCP_EXTENTIONS */ scount = rcount = total = 0; syscall(get_tim(&now)); syslog(LOG_NOTICE, "[TES:%02d ACP] connected: %6lu, from: %s.%u", cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno); while (true) { if ((rlen = tcp_rcv_dat(cepid, buffer, BUF_SIZE - 1, RCV_TMO)) <= 0) { if (rlen != E_OK) syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", cepid, itron_strerror(rlen)); break; } rcount ++; #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x", cepid, rcount, (uint16_t)rlen, *buffer, *(buffer + rlen - 1)); #endif /* of #ifdef SHOW_RCV_RANGE */ total += rlen; soff = 0; while (rlen > 0) { scount ++; if ((slen = tcp_snd_dat(cepid, &buffer[soff], rlen, SND_TMO)) < 0) { syslog(LOG_NOTICE, "[TES:%02d SND] error: %s", cepid, itron_strerror(slen)); goto err_fin; } #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d", cepid, scount, (uint16_t)slen); #endif /* of #ifdef SHOW_RCV_RANGE */ rlen -= slen; soff += slen; } } err_fin: #ifdef USE_TCP_SHT_CEP if ((error = tcp_sht_cep(cepid)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error)); #endif /* of #ifdef USE_TCP_SHT_CEP */ if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error)); syscall(get_tim(&now)); syslog(LOG_NOTICE, "[TES:%02d FIN] finished: %6lu, snd: %4u, rcv: %4u, len: %lu", cepid, now / SYSTIM_HZ, scount, rcount, total); return error; }
static ER tcp_echo_srv (ID cepid, ID repid) { SYSTIM now; ER error; uint32_t total; uint16_t rlen, slen, soff, scount, rcount; char head, tail; if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error)); return error; } /* 相手から接続されるまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_error == E_OK) { syscall(get_tim(&now)); syslog(LOG_NOTICE, "[TES:%02d ACP] connected: %6lu, from: %s.%u", cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno); } else { syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(nblk_error)); return nblk_error; } #ifdef USE_TCP_EXTENTIONS if ((error = free_tcp_rep(repid, true)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error)); #endif /* of #ifdef USE_TCP_EXTENTIONS */ scount = rcount = total = 0; while (true) { if ((error = tcp_rcv_dat(cepid, buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", cepid, itron_strerror(error)); break; } /* 受信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_rlen < 0) { syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", cepid, itron_strerror(nblk_rlen)); break; } else if (nblk_rlen == 0) break; rlen = nblk_rlen; head = *buffer; tail = *(buffer + rlen - 1); rcount ++; #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x", cepid, rcount, rlen, head, tail); #endif /* of #ifdef SHOW_RCV_RANGE */ total += rlen; soff = 0; while (rlen > 0) { scount ++; if ((error = tcp_snd_dat(cepid, &buffer[soff], rlen, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d SND] error: %s", cepid, itron_strerror(error)); goto err_fin; } /* 送信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_slen < 0) { syslog(LOG_NOTICE, "[TES:%02d SND] error: %s", cepid, itron_strerror(nblk_slen)); goto err_fin; } slen = nblk_slen; #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d", cepid, scount, slen); #endif /* of #ifdef SHOW_RCV_RANGE */ rlen -= slen; soff += slen; } } err_fin: #ifdef USE_TCP_SHT_CEP if ((error = tcp_sht_cep(cepid)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error)); #endif /* of #ifdef USE_TCP_SHT_CEP */ if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK) syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error)); /* 開放が完了するまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); syscall(get_tim(&now)); syslog(LOG_NOTICE, "[TES:%02d FIN] finished: %6lu, snd: %4u, rcv: %4u, len: %lu", cepid, now / SYSTIM_HZ, scount, rcount, total); return error == E_WBLK ? E_OK : error; }
void tcp_telnet_srv_task(VP_INT exinf) { UW total; UH rlen, slen, soff, count, sblen, rblen; ID tskid; ER error; UB head, tail; T_IF_SOFTC *ic; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK):%d,%d] started.", tskid, (INT)exinf); while (TRUE) { if ((error = tcp_acp_cep((INT)exinf, TCP_TELNET_SRV_REPID, &dst, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) ACP] error: %s", itron_strerror(error)); continue; } /* 相手から接続されるまで待つ。*/ syscall(wai_sem(SEM_TCP_TELNET_SRV_NBLK_READY)); if (nblk_error == E_OK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) ACP] connected from %s:%d", ip2str(NULL, &dst.ipaddr), dst.portno); } else { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) ACP] error: %s", itron_strerror(nblk_error)); continue; } connect = TRUE; count = total = 0; while (TRUE) { if ((error = tcp_rcv_dat((INT)exinf, buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) RCV] error: %s", itron_strerror(error)); break; } /* 受信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_TELNET_SRV_NRCV_READY)); if (nblk_rlen < 0) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) RCV] error: %s", itron_strerror(nblk_rlen)); break; } else if (nblk_rlen == 0) break; rlen = (UH)nblk_rlen; total += (UW)nblk_rlen; head = *buffer; tail = *(buffer + rlen - 1); count ++; /*syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) RCV] count: %4d, len: %4d, data %02x -> %02x", ++ count, rlen, head, tail);*/ soff = 0; while (rlen > 0) { sblen, telnet_copy(buffer + soff, buffer + soff, rlen, &rblen); if ((error = tcp_snd_dat((INT)exinf, &buffer[soff], sblen, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SND] error: %s", itron_strerror(error)); goto err_fin; } /* 送信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_TELNET_SRV_NSND_READY)); if (nblk_slen < 0) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SND] error: %s", itron_strerror(nblk_slen)); goto err_fin; } else /*syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SND] len: %4d", nblk_slen)*/; slen = (UH)nblk_slen; rlen -= rblen; soff += slen; } } err_fin: if ((error = tcp_sht_cep((INT)exinf)) != E_OK) syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SHT] error: %s", itron_strerror(error)); if ((error = tcp_cls_cep((INT)exinf, TMO_NBLK)) != E_WBLK) syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) CLS] error: %s", itron_strerror(error)); connect = FALSE; /* 開放が完了するまで待つ。*/ syscall(wai_sem(SEM_TCP_TELNET_SRV_NBLK_READY)); syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) FIN] finished, total cnt: %d, len: %d", count, total); } }
void tcp_echo_srv_task(intptr_t exinf) { ID tskid; ER error; uint32_t total; uint16_t rlen, slen, soff, count; char head, tail; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK):%d,%d] started.", tskid, (int_t)exinf); while (true) { if ((error = tcp_acp_cep((int_t)exinf, TCP_ECHO_SRV_REPID, &dst, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) ACP] error: %s", itron_strerror(error)); continue; } /* 相手から接続されるまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_error == E_OK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) ACP] connected from %s:%d", ip2str(NULL, &dst.ipaddr), dst.portno); } else { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) ACP] error: %s", itron_strerror(nblk_error)); continue; } count = total = 0; while (true) { if ((error = tcp_rcv_dat((int_t)exinf, buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) RCV] error: %s", itron_strerror(error)); break; } /* 受信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_rlen < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) RCV] error: %s", itron_strerror(nblk_rlen)); break; } else if (nblk_rlen == 0) break; rlen = (uint16_t)nblk_rlen; total += (uint32_t)nblk_rlen; head = *buffer; tail = *(buffer + rlen - 1); count ++; /*syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) RCV] count: %4d, len: %4d, data %02x -> %02x", ++ count, rlen, head, tail);*/ soff = 0; while (rlen > 0) { if ((error = tcp_snd_dat((int_t)exinf, &buffer[soff], rlen, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND] error: %s", itron_strerror(error)); goto err_fin; } /* 送信完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); if (nblk_slen < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND] error: %s", itron_strerror(nblk_slen)); goto err_fin; } else /*syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND] len: %4d", nblk_slen)*/; slen = (uint16_t)nblk_slen; rlen -= slen; soff += slen; } } err_fin: if ((error = tcp_sht_cep((int_t)exinf)) != E_OK) syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SHT] error: %s", itron_strerror(error)); if ((error = tcp_cls_cep((int_t)exinf, TMO_NBLK)) != E_WBLK) syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) CLS] error: %s", itron_strerror(error)); /* 開放が完了するまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY)); syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) FIN] finished, total cnt: %d, len: %d", count, total); } }
ER tcp_echo_srv_rcv (ID cepid, ID repid) { ER_UINT rlen; ER error; SYSTIM now; uint16_t blen, last; char head, tail; if ((error = psnd_dtq(DTQ_TCP_ECHO_SRV_SND, (intptr_t)cepid)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d RCV] sync error: %s", cepid, itron_strerror(error)); return error; } if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d ACP] accept error = %s", cepid, itron_strerror(error)); return error; } #ifdef USE_TCP_EXTENTIONS if ((error = free_tcp_rep(repid, true)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error)); return error; } #endif /* of #ifdef USE_TCP_EXTENTIONS */ syscall(get_tim(&now)); syslog(LOG_NOTICE, "[TES:%02d ACP] connected: %6ld, from: %s.%d", cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno); sptr = rptr = buffer; snd_count = snd_total = rcv_count = rcv_total = chars = 0; ena_rcv = true; while (true) { /* 受信サイズを計算する。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); if (sptr > rptr) blen = sptr - rptr; else blen = sizeof(buffer) - (rptr - buffer); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); /* 受信する。*/ if ((rlen = tcp_rcv_dat(cepid, rptr, blen, TMO_FEVR)) <= 0) { if (rlen < 0) syslog(LOG_NOTICE, "[TES:%02d RCV] recv error = %s", cepid, itron_strerror(rlen)); break; } head = *rptr; tail = *(rptr + rlen - 1); #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d RCV] len: %4d, data %02x -> %02x", cepid, (uint16_t)rlen, head, tail); #endif /* of #ifdef SHOW_RCV_RANGE */ rcv_count ++; rcv_total += rlen; syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); /* 受信ポインタを進める。*/ if (rptr - buffer + rlen >= sizeof(buffer)) rptr -= sizeof(buffer) - rlen; else rptr += rlen; /* バッファ内の文字数を増やす。*/ last = chars; chars += (uint16_t)rlen; /* バッファ内に文字が入れば、送信タスクを起床する。*/ if (last == 0 && chars > 0) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); /* バッファ内に空きがあれば、受信タスクを起床する。*/ if (sizeof(buffer) - chars > 0) sig_sem(SEM_TCP_ECHO_SRV_RCV_READY); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); /* バッファに空きができるまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_RCV_READY)); } /* 受信完了 */ ena_rcv = false; /* 受信バッファに文字が入るのを待っている送信タスクを起床する。*/ if (chars == 0) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); /* コネクションの切断が完了するまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_CLS_READY)); return error; }
ER tcp_echo_srv_rcv (ID cepid, ID repid) { ER error; uint16_t blen; if ((error = psnd_dtq(DTQ_TCP_ECHO_SRV_SND, (intptr_t)cepid)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d RCV] sync error: %s", cepid, itron_strerror(error)); return error; } if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d ACP] accept error = %s", cepid, itron_strerror(error)); return error; } /* コネクション開設完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_RCV_READY)); /* 待っている間にエラーになったら、コネクションの開設待ちに戻る。*/ if (rcv_error != E_OK) return rcv_error; #ifdef USE_TCP_EXTENTIONS if ((error = free_tcp_rep(repid, true)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error)); return error; } #endif /* of #ifdef USE_TCP_EXTENTIONS */ while (true) { /* 受信サイズを計算する。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); if (sptr > rptr) blen = sptr - rptr; else blen = sizeof(buffer) - (rptr - buffer); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); /* 受信する。*/ if ((error = tcp_rcv_dat(cepid, rptr, blen, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d RCV] recv error = %s", cepid, itron_strerror(error)); break; } /* 受信バッファに空ができるまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_RCV_READY)); /* 待っている間に、受信文字数が 0 になるか、エラーになったら終了する。*/ if (rcv_error <= 0) break; } /* 受信完了 */ ena_rcv = false; /* 受信バッファに文字が入るのを待っている送信タスクを起床する。*/ if (chars == 0) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); /* コネクション切断完了まで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_CLS_READY)); return error == E_WBLK ? E_OK : error; }