recv

/* Now, read the data as fast as we can until no more to read */
time(&last_time);
do {
	do {
	;
	} while (ShoutBlockingHook()); /* Dispatch messages while available */
	if (run_cancelled) {
	WSASetLastError(WSAEINTR);
	break; /* Non-blocking mode was cancelled */
	}
	len = recv(hAcceptSock, ReadBuf, read_len, 0);
	if (len == SOCKET_ERROR) {
		if (h_errno == WSAEWOULDBLOCK)
		continue;
		else
		break;
	}
	else if (len == 0)
	break;
	num_reads++;
	bytes_read += len;
	wsprintf((LPSTR)prbuf,"%d\n",num_reads);
	SetDlgItemText( IDD_WRITE, (LPSTR) prbuf);
	wsprintf((LPSTR)prbuf,"%ld\n",bytes_read);
	SetDlgItemText( IDD_SENT, (LPSTR) prbuf);//. 70 .
	if (bTemp) { /* To update our main display once */
	/* Do not use wsprintf() or you will add an extra char */
	memcpy(prbuf, inet_ntoa(local.sin_addr), 4*sizeof(u_long));
	//SetDlgItemText( IDD_HNAME, (LPSTR) prbuf);
	SetDlgItemText( IDD_COMMENT, "Reading TCP Data ...");
	bTemp = FALSE;
	}
} while ((len != 0) || (len != SOCKET_ERROR));
time (&now);
if (len == SOCKET_ERROR) {
	if ((h_errno == WSAESHUTDOWN) || (h_errno == WSAENOTCONN)) {
	/* nothing available for read. */
	wsprintf((LPSTR)prbuf,
	"Connection from %s closed.\n",inet_ntoa(local.sin_addr));
	SetDlgItemText( IDD_COMMENT, prbuf);
	}
	else { /* Other error */
	wshout_err ( WSAGetLastError(), "recv()");
	}
}
else if (len == 0) {
	/* Other side shut down the connection */
	wsprintf((LPSTR)prbuf,
	"Connection from %s closed.\n",inet_ntoa(local.sin_addr));
	SetDlgItemText( IDD_COMMENT, prbuf);
}
AcceptLinger.l_onoff = 1;
AcceptLinger.l_linger = 0;
ret = setsockopt(hAcceptSock, SOL_SOCKET, SO_LINGER,
(char FAR *) &AcceptLinger, sizeof(AcceptLinger));
if (ret == SOCKET_ERROR) {
	wshout_err (WSAGetLastError(), "setsockopt()");
}
ret = closesocket(hAcceptSock);
if (ret == SOCKET_ERROR) {
	wshout_err ( WSAGetLastError(), "closesocket()");
}//. 71 .
total_time = (long) difftime(now, last_time);
if (total_time == 0)
	total_time = 1L; /* Avoid dividing by zero */
wsprintf((LPSTR)prbuf,"%ld\n",total_time);
SetDlgItemText( IDD_TIME, (LPSTR) prbuf);
ltemp = num_reads/total_time;
wsprintf((LPSTR)prbuf,"%ld\n", ltemp);
SetDlgItemText( IDD_WRITES,(LPSTR) prbuf);
ltemp = bytes_read/total_time;
wsprintf((LPSTR)prbuf,"%ld\n", ltemp);
SetDlgItemText( IDD_BYTES, (LPSTR) prbuf);
ltemp = 8 * (bytes_read/total_time);
wsprintf((LPSTR)prbuf,"%ld\n", ltemp);
SetDlgItemText( IDD_BITS, (LPSTR) prbuf);
if (bytes_read) {
	SetDlgItemText( IDD_COMMENT, "...TCP Listen Done\n");
} /* end: if (bytes_read) */
return (bytes_read);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值