K
killghost
Unregistered / Unconfirmed
GUEST, unregistred user!
即想了解一下能否实现在组播收发的过程中,使用overlapped i/o (重叠I/O)?
我是用回调方式实现的。
下面两个函数分别是发起一个回调和回调函数的具体实现。测试中发现在收到数据后Sleepex就死调。谁有没有这方面的例子?
procedure TMultiCast.CallMyFun;
var
FlagsWORD;
RecvBytesWORD;
IndexWORD;
begin
printf(Format('FAsyncSocket is %d', [FAsyncSocket]));
Flags := 0;
ZeroMemory(@Overlapped, sizeof(TOverlapped));
DataBuf.len := DATA_BUFSIZE;
DataBuf.buf := Buffer;
WSARecv(FAsyncSocket, @DataBuf, 1, RecvBytes,
Flags, @Overlapped, @TMultiCast.MyFun);
while True do
SleepEx( 1, True );
end;
procedure TMultiCast.MyFun(const dwError, cbTransferred: DWORD;
const AOverlapped: Pointer; const dwFlags: DWORD);
var
SendBytes,RecvBytesWORD;
FlagsWORD;
Ret:integer;
begin
printf('procedure TMultiCast.MyFun(const dwError, cbTransferred: DWORD;');
if (dwError <> 0 ) or (cbTransferred = 0) then
begin
closesocket(FAsyncSocket);
exit;
end;
Flags := 0;
ZeroMemory(@AOverlapped, sizeof(WSAOVERLAPPED));
DataBuf.len := DATA_BUFSIZE;
DataBuf.buf := Buffer;
Ret:= WSARecv(FAsyncSocket, @DataBuf, 1, RecvBytes, Flags, @Overlapped, @TMultiCast.MyFun);
if Ret=SOCKET_ERROR then
begin
if WSAGetLastError<>WSA_IO_PENDING then
begin
printf(Format('WSARecv() failed with error %d', [WSAGetLastError]));
exit;
end;
end;
end;
大家给点建议吧?
我是用回调方式实现的。
下面两个函数分别是发起一个回调和回调函数的具体实现。测试中发现在收到数据后Sleepex就死调。谁有没有这方面的例子?
procedure TMultiCast.CallMyFun;
var
FlagsWORD;
RecvBytesWORD;
IndexWORD;
begin
printf(Format('FAsyncSocket is %d', [FAsyncSocket]));
Flags := 0;
ZeroMemory(@Overlapped, sizeof(TOverlapped));
DataBuf.len := DATA_BUFSIZE;
DataBuf.buf := Buffer;
WSARecv(FAsyncSocket, @DataBuf, 1, RecvBytes,
Flags, @Overlapped, @TMultiCast.MyFun);
while True do
SleepEx( 1, True );
end;
procedure TMultiCast.MyFun(const dwError, cbTransferred: DWORD;
const AOverlapped: Pointer; const dwFlags: DWORD);
var
SendBytes,RecvBytesWORD;
FlagsWORD;
Ret:integer;
begin
printf('procedure TMultiCast.MyFun(const dwError, cbTransferred: DWORD;');
if (dwError <> 0 ) or (cbTransferred = 0) then
begin
closesocket(FAsyncSocket);
exit;
end;
Flags := 0;
ZeroMemory(@AOverlapped, sizeof(WSAOVERLAPPED));
DataBuf.len := DATA_BUFSIZE;
DataBuf.buf := Buffer;
Ret:= WSARecv(FAsyncSocket, @DataBuf, 1, RecvBytes, Flags, @Overlapped, @TMultiCast.MyFun);
if Ret=SOCKET_ERROR then
begin
if WSAGetLastError<>WSA_IO_PENDING then
begin
printf(Format('WSARecv() failed with error %d', [WSAGetLastError]));
exit;
end;
end;
end;
大家给点建议吧?