/** TELNETデーモン・タスク(ブロッキング、省コピーAPI) * @param exinf タスク起動時パラメータ ****************************************************************************** */ void TELNET_Task( VP_INT exinf ) { static TELNET_PARA mTelnetParaTbl[] = { { FALSE, TELNET_DAEMON_REPID1, TELNET_DAEMON_CEPID1, TELNET_DEFAULT_TIMEOUT }, { FALSE, TELNET_DAEMON_REPID2, TELNET_DAEMON_CEPID2, TELNET_DEFAULT_TIMEOUT } }; TELNET_PARA *para; CONSOLE cnsl; ER errcd = E_OK; T_IPV4EP dst; para = &mTelnetParaTbl[ (int)exinf ]; CONSOLE_MakeConsole( &cnsl, (void*)para, TELNET_Read, TELNET_Write, NULL, (char*)mTelnetWork.WorkBuffer[ (int)exinf ], WORK_BUFFER_LEN ); cnsl.EchoBack = FALSE; cnsl.Flash = (void*)TELNET_Flash; while(1) { /*----- 接続待ち -----------------------------------*/ errcd = tcp_acp_cep( para->CepID, para->RepID, &dst, TMO_FEVR ); /* 接続待ち開始 */ if( errcd != E_OK ) continue; /*----- 接続した -----------------------------------*/ // CONSOLE_Flash( &cnsl ); para->OpenFg = TRUE; Shell_Main( &cnsl ); /* Shell実行 */ /*----- 切断した -----------------------------------*/ para->OpenFg = FALSE; errcd = tcp_sht_cep( para->CepID ); /* 通信端点切断 */ errcd = tcp_cls_cep( para->CepID, TMO_FEVR ); /* 通信端点クローズ */ } }
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>]# eOpener_close * name: eOpener_close * global_name: tTINETClient_eOpener_close * oneway: false * #[</ENTRY_FUNC>]# */ ER eOpener_close(CELLIDX idx, TMO tmo) { ER ercd = E_OK; CELLCB *p_cellcb; if (VALID_IDX(idx)) { p_cellcb = GET_CELLCB(idx); } else { return(E_ID); } /* ここに処理本体を記述します #_TEFB_# */ ercd = tcp_cls_cep( ATTR_cep_id, 0 ); /* mikan エラー処理 */ return(ercd); }
ER disconnecting (void) { ER error = E_OK; if (connected) { syscall(wai_sem(SEM_NET_SEND)); if (snd_off > 0) tcp_snd_buf(TCP_CEPID, snd_off); tcp_sht_cep(TCP_CEPID); tcp_cls_cep(TCP_CEPID, TMO_FEVR); connected = FALSE; syscall(sig_sem(SEM_NET_SEND)); IP2STR(addr, &dst.ipaddr); syslog(LOG_NOTICE, "disconnected: %s.%d", addr, dst.portno); } 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; }
static ER tcp_echo_srv (ID cepid, ID repid) { ER error; SYSTIM now; uint32_t total; uint16_t rblen, sblen, rlen, slen, soff, scount, rcount; char *rbuf, *sbuf, 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 */ rlen = scount = rcount = total = 0; while (true) { if ((error = tcp_rcv_buf(cepid, (void**)&rbuf, 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; rblen = nblk_rlen; /* バッファの残りにより、受信長を調整する。*/ if (rblen > BUF_SIZE - rlen) rblen = BUF_SIZE - rlen; total += rblen; rlen = rblen; head = *rbuf; tail = *(rbuf + rblen - 1); rcount ++; #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d RCV] " "rcount: %4d, len: %4d, data %02x -> %02x", cepid, rcount, rblen, head, tail); #endif /* of #ifdef SHOW_RCV_RANGE */ memcpy(buffer, rbuf, rblen); if ((error = tcp_rel_buf(cepid, rlen)) < 0) { syslog(LOG_NOTICE, "[TES:%02d REL] error: %s", cepid, itron_strerror(error)); break; } soff = 0; while (rlen > 0) { if ((error = tcp_get_buf(cepid, (void**)&sbuf, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d GET] 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 GET] error: %s", cepid, itron_strerror(nblk_slen)); goto err_fin; } sblen = nblk_slen; scount ++; slen = sblen < rlen ? sblen : rlen; memcpy(sbuf, buffer + soff, slen); if ((error = tcp_snd_buf(cepid, slen)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d SND] error: %s", cepid, itron_strerror(error)); goto err_fin; } #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; }
BOOL cg_socket_close(CgSocket *sock) { cg_log_debug_l4("Entering...\n"); if (cg_socket_isbound(sock) == FALSE) return TRUE; #if defined(CG_USE_OPENSSL) if (cg_socket_isssl(sock) == TRUE) { if (sock->ctx) { SSL_shutdown(sock->ssl); SSL_free(sock->ssl); sock->ssl = NULL; } if (sock->ctx) { SSL_CTX_free(sock->ctx); sock->ctx = NULL; } } #endif #if (defined(WIN32) || defined(__CYGWIN__)) && !defined(ITRON) #if !defined(WINCE) WSAAsyncSelect(sock->id, NULL, 0, FD_CLOSE); #endif shutdown(sock->id, SD_BOTH ); #if defined WINCE { int nRet = 1; char achDiscard[256]; while (nRet && (nRet != SOCKET_ERROR)){ if (nRet>0) { achDiscard[nRet]=(char)0; #if defined DEBUG_SOCKET printf("DUMMY READ WHILE CLOSING SOCKET \n%s\n",achDiscard); #endif } nRet = recv(sock->id,achDiscard,128,0); } } #endif closesocket(sock->id); #if !defined(__CYGWIN__) && !defined(__MINGW32__) sock->id = INVALID_SOCKET; #else sock->id = -1; #endif #else #if defined(BTRON) || (defined(TENGINE) && !defined(CG_TENGINE_NET_KASAGO)) so_shutdown(sock->id, 2); so_close(sock->id); #elif defined(TENGINE) && defined(CG_TENGINE_NET_KASAGO) ka_tfClose(sock->id); #elif defined(ITRON) if (cg_socket_issocketstream(sock) == TRUE) { tcp_can_cep(sock->id, TFN_TCP_ALL); tcp_sht_cep(sock->id); tcp_del_cep(sock->id); tcp_cls_cep(sock->id, TMO_FEVR); tcp_del_rep(sock->id); } else { udp_can_cep(sock->id, TFN_UDP_ALL); udp_del_cep(sock->id); } #else int flag = fcntl(sock->id, F_GETFL, 0); if (0 <= flag) fcntl(sock->id, F_SETFL, flag | O_NONBLOCK); shutdown(sock->id, 2); close(sock->id); #endif sock->id = -1; #endif cg_socket_setaddress(sock, ""); cg_socket_setport(sock, -1); return TRUE; cg_log_debug_l4("Leaving...\n"); }
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_telnet_srv_task(VP_INT exinf) { UW total; UH rblen, sblen, rlen, slen, soff, count; UB *rbuf, *sbuf, head, tail; ID tskid; ER error = E_OK; T_IF_SOFTC *ic; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK):%d,%d] (copy save API) 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; total = rlen = count = 0; while (TRUE) { if ((error = tcp_rcv_buf((INT)exinf, (VP *)&rbuf, 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; rblen = (UH)nblk_rlen; /* バッファの残りにより、受信長を調整する。*/ if (rblen > BUF_SIZE - rlen) rblen = BUF_SIZE - rlen; total += rblen; rlen = rblen; head = *rbuf; tail = *(rbuf + rblen - 1); count ++; /*syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) RCV] " "count: %4d, len: %4d, data %02x -> %02x", ++ count, rblen, head, tail);*/ memcpy(buffer, rbuf, rblen); if ((error = tcp_rel_buf((INT)exinf, rlen)) < 0) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) REL] error: %s", itron_strerror(error)); break; } soff = 0; while (rlen > 0) { if ((error = tcp_get_buf((INT)exinf, (VP *)&sbuf, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) GET] 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) GET] error: %s", itron_strerror(nblk_slen)); goto err_fin; } else /*syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) GET] len: %d", nblk_slen)*/; sblen = (UH)nblk_slen; slen = sblen < rlen ? sblen : rlen; #if 0 /* ROI DEBUG */ memcpy(sbuf, buffer + soff, slen); #else /* ROI DEBUG */ slen = telnet_copy(sbuf, buffer + soff, slen, &rblen); #endif /* ROI DEBUG */ if ((error = tcp_snd_buf((INT)exinf, slen)) != E_OK) { syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SND] error: %s", itron_strerror(error)); goto err_fin; } /*syslog(LOG_NOTICE, "[TCP TELNET SRV (NBLK) SND] len: %d", slen);*/ #if 0 /* ROI DEBUG */ rlen -= slen; #else /* ROI DEBUG */ rlen -= rblen; #endif /* ROI DEBUG */ 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 count: %d, len: %d", count, total); } }
void tcp_echo_srv_snd_task(intptr_t exinf) { ID tskid, cepid; ER error; ER_UINT slen; SYSTIM now; uint16_t blen, last; char head, tail; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV SND:%d] started.", tskid); while (true) { if ((error = rcv_dtq(DTQ_TCP_ECHO_SRV_SND, (intptr_t*)&cepid)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d SND] sync error: %s", cepid, itron_strerror(error)); continue; } while (true) { /* バッファに文字が入るまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_SND_READY)); /* 受信完了で、バッファに文字がなければ終了する。*/ if (!ena_rcv && chars == 0) break; /* 送信サイズを計算する。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); if (rptr > sptr) blen = rptr - sptr; else blen = sizeof(buffer) - (sptr - buffer); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); if ((slen = tcp_snd_dat(cepid, sptr, blen, TMO_FEVR)) <= 0) { syslog(LOG_NOTICE, "[TES:%02d SND] send error = %s", cepid, itron_strerror(slen)); break; } head = *sptr; tail = *(sptr + slen - 1); #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d SND] len: %4d, data %02x -> %02x", cepid, (uint16_t)slen, head, tail); #endif /* of #ifdef SHOW_RCV_RANGE */ snd_count ++; snd_total += slen; syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); /* 送信ポインタを進める。*/ if (sptr - buffer + slen >= sizeof(buffer)) sptr -= sizeof(buffer) - slen; else sptr += slen; /* バッファ内の文字数を減らす。*/ last = chars; chars -= (uint16_t)slen; /* 受信完了で、バッファに文字がなければ終了する。*/ if (!ena_rcv && chars == 0) { syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); break; } /* バッファ内に文字があれば、送信タスクを起床する。*/ if (chars > 0) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); /* 受信可能で、バッファ内に空きができれば、受信タスクを起床する。*/ if (ena_rcv && last == sizeof(buffer) && sizeof(buffer) - chars > 0) sig_sem(SEM_TCP_ECHO_SRV_RCV_READY); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); } /* 受信バッファに空ができるを待っている受信タスクを起床する。*/ if (chars == sizeof(buffer)) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); #ifdef USE_TCP_SHT_CEP if ((error = tcp_sht_cep(cepid)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d SND] shtudown error = %s", cepid, itron_strerror(error)); #endif /* of #ifdef USE_TCP_SHT_CEP */ if ((error = tcp_cls_cep(cepid, TMO_FEVR)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d SND] close error = %s", cepid, itron_strerror(error)); get_tim(&now); syslog(LOG_NOTICE, "[TES:%02d SND] finished: %6ld, snd: %4d, rcv: %4d, len: %ld", cepid, now / SYSTIM_HZ, snd_count, rcv_count, snd_total); sig_sem(SEM_TCP_ECHO_SRV_CLS_READY); pol_sem(SEM_TCP_ECHO_SRV_SND_READY); pol_sem(SEM_TCP_ECHO_SRV_RCV_READY); } }
void tcp_echo_srv_task(intptr_t exinf) { ID tskid; ER_UINT rblen, sblen; ER error = E_OK; uint32_t total; uint16_t rlen, slen, soff, count; char *rbuf, *sbuf, head, tail; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV:%d,%d] (copy save API) 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 ((rblen = tcp_rcv_buf((int_t)exinf, (void **)&rbuf, TMO_FEVR)) <= 0) { if (rblen != E_OK) syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] error: %s", itron_strerror(rblen)); break; } rlen = (uint16_t)rblen; total += (uint32_t)rblen; head = *rbuf; tail = *(rbuf + rlen - 1); count ++; /*syslog(LOG_NOTICE, "[TCP ECHO SRV RCV] count: %4d, len: %4d, data %02x -> %02x", ++ count, rlen, head, tail);*/ soff = 0; while (rlen > 0) { if ((sblen = tcp_get_buf((int_t)exinf, (void **)&sbuf, TMO_FEVR)) < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV GET] error: %s", itron_strerror(sblen)); goto err_fin; } /*syslog(LOG_NOTICE, "[TCP ECHO SRV GET] len: %d", sblen);*/ slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen; memcpy(sbuf, rbuf + soff, slen); if ((error = tcp_snd_buf((int_t)exinf, slen)) != E_OK) { syslog(LOG_NOTICE, "[TCP ECHO SRV SND] error: %s", itron_strerror(error)); goto err_fin; } /*syslog(LOG_NOTICE, "[TCP ECHO SRV SND] len: %d", slen);*/ rlen -= slen; soff += slen; } if ((error = tcp_rel_buf((int_t)exinf, rblen)) < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV REL] error: %s", itron_strerror(error)); break; } } 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); } }
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); } }
void tcp_echo_srv_task(intptr_t exinf) { ID tskid; ER error = E_OK; uint32_t total; uint16_t rblen, sblen, rlen, slen, soff, count; char *rbuf, *sbuf, head, tail; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK):%d,%d] (copy save API) 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; } total = rlen = count = 0; while (true) { if ((error = tcp_rcv_buf((int_t)exinf, (void **)&rbuf, 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; rblen = (uint16_t)nblk_rlen; /* バッファの残りにより、受信長を調整する。*/ if (rblen > BUF_SIZE - rlen) rblen = BUF_SIZE - rlen; total += rblen; rlen = rblen; head = *rbuf; tail = *(rbuf + rblen - 1); count ++; /*syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) RCV] " "count: %4d, len: %4d, data %02x -> %02x", ++ count, rblen, head, tail);*/ memcpy(buffer, rbuf, rblen); if ((error = tcp_rel_buf((int_t)exinf, rlen)) < 0) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) REL] error: %s", itron_strerror(error)); break; } soff = 0; while (rlen > 0) { if ((error = tcp_get_buf((int_t)exinf, (void **)&sbuf, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) GET] 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) GET] error: %s", itron_strerror(nblk_slen)); goto err_fin; } else /*syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) GET] len: %d", nblk_slen)*/; sblen = (uint16_t)nblk_slen; slen = sblen < rlen ? sblen : rlen; memcpy(sbuf, buffer + soff, slen); if ((error = tcp_snd_buf((int_t)exinf, slen)) != E_OK) { syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND] error: %s", itron_strerror(error)); goto err_fin; } /*syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND] len: %d", 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 count: %d, len: %d", count, total); } }
static ER tcp_discard_srv (ID cepid, ID repid) { T_IPEP dst; ER_UINT rlen; ER error; SYSTIM time; uint32_t total; uint16_t count; uint8_t *buf; #ifdef SHOW_RCV_DATA uint_t ix; #endif /* of #ifdef SHOW_RCV_DATA */ if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) { syslog(LOG_NOTICE, "[TDS:%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, "[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_buf(cepid, (void*)&buf, 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 */ #ifdef SHOW_RCV_DATA for (ix = 0; ix < rlen; ix ++) cons_putchar(CONSOLE_PORTID, *(buf + ix)); #endif /* of #ifdef SHOW_RCV_DATA */ if ((error = tcp_rel_buf(cepid, rlen)) != E_OK) { syslog(LOG_NOTICE, "[TDS:%02d RCV] rel buf error: %s", cepid, itron_strerror(error)); rlen = 0; break; } total += rlen; } if (rlen != 0) syslog(LOG_NOTICE, "[TDS:%02d RCV] recv buf 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; }
static ER tcp_echo_srv (ID cepid, ID repid) { ER_UINT rblen, sblen; SYSTIM now; ER error; uint32_t total; uint16_t rlen, slen, soff, scount, rcount; char *rbuf, *sbuf, head, tail; 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 ((rblen = tcp_rcv_buf(cepid, (void**)&rbuf, RCV_TMO)) <= 0) { if (rblen != E_OK) syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", cepid, itron_strerror(rblen)); break; } head = *rbuf; tail = *(rbuf + rblen - 1); rcount ++; //syslog(LOG_NOTICE, "[TES:%02d RCV] len: %4d", cepid, (uint16_t)rblen); #ifdef SHOW_RCV_RANGE syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x", cepid, rcount, (uint16_t)rblen, head, tail); #endif /* of #ifdef SHOW_RCV_RANGE */ rlen = (uint16_t)rblen; total += rblen; soff = 0; while (rlen > 0) { if ((sblen = tcp_get_buf(cepid, (void**)&sbuf, SND_TMO)) < 0) { syslog(LOG_NOTICE, "[TES:%02d GET] error: %s", cepid, itron_strerror(sblen)); goto err_fin; } //syslog(LOG_NOTICE, "[TES:%02d SND] len: %4d", cepid, (uint16_t)sblen); scount ++; slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen; memcpy(sbuf, rbuf + soff, slen); if ((error = tcp_snd_buf(cepid, slen)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d SND] error: %s", cepid, itron_strerror(error)); goto err_fin; } #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; } if ((error = tcp_rel_buf(cepid, rblen)) < 0) { syslog(LOG_NOTICE, "[TES:%02d REL] error: %s", cepid, itron_strerror(error)); break; } } 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) { 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; }
void tcp_echo_srv_snd_task(intptr_t exinf) { ER error; ID tskid, cepid; uint16_t blen; get_tid(&tskid); syslog(LOG_NOTICE, "[TCP ECHO SRV (NBLK) SND:%d] started.", tskid); while (true) { if ((error = rcv_dtq(DTQ_TCP_ECHO_SRV_SND, (intptr_t*)&cepid)) != E_OK) { syslog(LOG_NOTICE, "[TES:%02d SND] sync error: %s", cepid, itron_strerror(error)); continue; } while (true) { /* バッファに文字が入るまで待つ。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_SND_READY)); /* 待っている間にエラーになったら終了する。*/ if (snd_error <= 0) break; /* 受信完了で、バッファに文字がなければ終了する。*/ if (!ena_rcv && chars == 0) break; /* 送信サイズを計算する。*/ syscall(wai_sem(SEM_TCP_ECHO_SRV_LOCK)); if (rptr > sptr) blen = rptr - sptr; else blen = sizeof(buffer) - (sptr - buffer); syscall(sig_sem(SEM_TCP_ECHO_SRV_LOCK)); /* 送信する。*/ if ((error = tcp_snd_dat(cepid, sptr, blen, TMO_NBLK)) != E_WBLK) { syslog(LOG_NOTICE, "[TES:%02d SND] send error = %s", cepid, itron_strerror(error)); break; } } /* 受信バッファに空ができるを待っている受信タスクを起床する。*/ if (chars == sizeof(buffer)) sig_sem(SEM_TCP_ECHO_SRV_SND_READY); #ifdef USE_TCP_SHT_CEP if ((error = tcp_sht_cep(cepid)) != E_OK) syslog(LOG_NOTICE, "[TES:%02d SND] shutdown 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 SND] close error = %s", cepid, itron_strerror(error)); } pol_sem(SEM_TCP_ECHO_SRV_SND_READY); pol_sem(SEM_TCP_ECHO_SRV_RCV_READY); } }