Q
QSmile
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
function TSimpleSocket.ReadBuffer(p: Pointer; BufLen: Integer;dwTimeOutWORD): Integer;
var
ov_read : TOverlapped;
ErrWORD;
nResultWORD;
dwFlagWORD;
WSBuf:TWSABUF;
dwLenWORD;
begin
//WSASend(m_hSocket,p,Len,@Len,0,@ov_read,nil);
Result := 0;
FillChar(ov_read,SizeOf(TOverlapped),#0);
ov_read.hEvent := WSACreateEvent;
WSBuf.len := BufLen;
WSBuf.buf := p;
dwFlag := 0;
nResult := WSARecv(m_hSocket,
@WSBuf,
1,
@dwLen,
@dwFlag,
@ov_Read,
nil);
if (nResult = SOCKET_ERROR) then
begin
Err := WSAGetLastError;
if (Err = WSA_IO_PENDING) then
begin
//WSAGetOverlappedResult(m_hSocket,@ov_read,@dwLen,True,@dwFlag);
Err := WaitForSingleObject(ov_read.hEvent,dwTimeOut);
if Err = WAIT_OBJECT_0 then
begin
Result := dwLen;
end;
end;
end;
Result := dwLen;
WSACloseEvent(ov_read.hEvent);
end;
数据能读出来。但 dwLen (读取的字节数) 还是 0 呢?
function TSimpleSocket.ReadBuffer(p: Pointer; BufLen: Integer;dwTimeOutWORD): Integer;
var
ov_read : TOverlapped;
ErrWORD;
nResultWORD;
dwFlagWORD;
WSBuf:TWSABUF;
dwLenWORD;
begin
//WSASend(m_hSocket,p,Len,@Len,0,@ov_read,nil);
Result := 0;
FillChar(ov_read,SizeOf(TOverlapped),#0);
ov_read.hEvent := WSACreateEvent;
WSBuf.len := BufLen;
WSBuf.buf := p;
dwFlag := 0;
nResult := WSARecv(m_hSocket,
@WSBuf,
1,
@dwLen,
@dwFlag,
@ov_Read,
nil);
if (nResult = SOCKET_ERROR) then
begin
Err := WSAGetLastError;
if (Err = WSA_IO_PENDING) then
begin
//WSAGetOverlappedResult(m_hSocket,@ov_read,@dwLen,True,@dwFlag);
Err := WaitForSingleObject(ov_read.hEvent,dwTimeOut);
if Err = WAIT_OBJECT_0 then
begin
Result := dwLen;
end;
end;
end;
Result := dwLen;
WSACloseEvent(ov_read.hEvent);
end;
数据能读出来。但 dwLen (读取的字节数) 还是 0 呢?