示例#1
0
/**	文字入力チェック
 *	@param	cnsl	コンソール
 *	@return			受信データ長( エラー時マイナス )
 ****************************************************************************** */
int		TELNET_GetReceiveLen( CONSOLE *cnsl )
{
ID		cepid;
UB		*rcvbf;
TELNET_PARA 	*para;
ER		rcvlen = 0;

	para = (TELNET_PARA*)cnsl->Parameter;

	if( !para->OpenFg )
		goto EXIT;
	cepid =para->CepID;

//	rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, para->Timeout );	/* データ受信	*/
	rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, TMO_POL );	/* データ受信	*/
	if( rcvlen == E_TMOUT )
		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 ) ));
		rcvlen = 0;
	}
EXIT:;
//	DBG_PRINT( DBG_DISPLAY_CONDITION, ( "TELNET_GetReceiveLen()=%d" LINE_END, rcvlen ));
	return( rcvlen );
}
示例#2
0
/**	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 );
}
示例#3
0
/**	受信データ破棄
 *	@param	cnsl	コンソール
 ****************************************************************************** */
void	TELNET_Flash( CONSOLE *cnsl )
{
TELNET_PARA 	*para;
static	ER		rcvlen = 0;
UB		*rcvbf;
ER		errcd;

	para = (TELNET_PARA*)cnsl->Parameter;
	if( !para->OpenFg )
		return;

	for( ;; )
	{
	//	rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, TMO_POL ); /* データ受信	*/
		rcvlen = tcp_rcv_buf( para->CepID, (VP*)&rcvbf, 1 ); /* データ受信	*/
		if( rcvlen == E_TMOUT )
			rcvlen = 0;	// タイムアウトだったら受信長をゼロにする。
		else
		if( rcvlen == 0 )
			rcvlen = E_TMOUT;	// 受信長なし(切断)だったらエラーにする。

		if( rcvlen == 0 )
			break;

		if( rcvlen < 0 )
		{	/* エラー */
			//DBG_PRINT( DBG_DISPLAY_ERROR, ( "tcp_rcv_buf() Error: %s" LINE_END, itron_strerror( rcvlen ) ));
			break;
		}

		errcd = tcp_rel_buf( para->CepID, rcvlen );	/* 受信用バッファの解放 */
		if( errcd != E_OK )
		{
			//DBG_PRINT( DBG_DISPLAY_ERROR, ( "tcp_rel_buf() Error: %s" LINE_END, itron_strerror( errcd ) ));
			break;
		}
	}
}
示例#4
0
int
get_char_raw (ID cepid)
{
	if (connected) {
		if (rcv_off >= rcv_len) {
			rcv_off = 0;
			if (tcp_rel_buf(TCP_CEPID, rcv_len) != E_OK) {
				disconnecting();
				return EOF;
				}
			if ((rcv_len = tcp_rcv_buf(TCP_CEPID, (VP*)&rcv_buff, TMO_FEVR)) == 0) {
				disconnecting();
				return EOF;
				}
			else if (rcv_len < 0) {
				disconnecting();
				return EOF;
				}
			}
		return rcv_buff[rcv_off ++];
		}
	else
		return EOF;
	}
示例#5
0
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;
	}
示例#6
0
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;
	}
示例#7
0
文件: telnet.c 项目: inouema/toppers
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);
	}
}
示例#8
0
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);
    }
}
示例#9
0
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);
    }
}
示例#10
0
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;
	}