/* 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);
}
recv
最新推荐文章于 2023-04-06 10:48:36 发布