// TCP/IP recv를 버퍼 크기만큼 받을때까지 계속 받는 함수
int Receiven(SOCKET s, BYTE *lpBuff, int nBuffLength, int flags)
{
ASSERT( IsBadWritePtr(lpBuff, nBuffLength) == FALSE );
BYTE* pBuff = lpBuff;
int nLeft = nBuffLength;
int nError;
while( nLeft > 0 )
{
int nRead = recv( s, pBuff, nLeft, int flags );
// 파일 전송 에러 처리
switch( nRead )
{
case 0:
/* the connection has been closed */
break;
case SOCKET_ERROR:
nError = WSAGetLastError();
if( nError == WSAEWOULDBLOCK )
{
/* The socket is marked as nonblocking and
the Receive operation would block. */
TRACE0("Receiven - WSABLOCK\n");
break;
}
else
{
TRACE1("Receiven() - Error Code = %d\n", nError);
return SOCKET_ERROR;
}
break;
default:
if( nRead >= nBuffLength )
{
nLeft -= nRead;
pBuff += nRead;
}
else
{
return nRead;
}
break;
}
}
return ( nBuffLength - nLeft );
}
int Receiven(SOCKET s, BYTE *lpBuff, int nBuffLength, int flags)
{
ASSERT( IsBadWritePtr(lpBuff, nBuffLength) == FALSE );
BYTE* pBuff = lpBuff;
int nLeft = nBuffLength;
int nError;
while( nLeft > 0 )
{
int nRead = recv( s, pBuff, nLeft, int flags );
// 파일 전송 에러 처리
switch( nRead )
{
case 0:
/* the connection has been closed */
break;
case SOCKET_ERROR:
nError = WSAGetLastError();
if( nError == WSAEWOULDBLOCK )
{
/* The socket is marked as nonblocking and
the Receive operation would block. */
TRACE0("Receiven - WSABLOCK\n");
break;
}
else
{
TRACE1("Receiven() - Error Code = %d\n", nError);
return SOCKET_ERROR;
}
break;
default:
if( nRead >= nBuffLength )
{
nLeft -= nRead;
pBuff += nRead;
}
else
{
return nRead;
}
break;
}
}
return ( nBuffLength - nLeft );
}
덧글을 달아 주세요