利用Winsock2,能否实现Multicast + Overlapped ? ( 积分: 200 )

  • 主题发起人 主题发起人 killghost
  • 开始时间 开始时间
K

killghost

Unregistered / Unconfirmed
GUEST, unregistred user!
即想了解一下能否实现在组播收发的过程中,使用overlapped i/o (重叠I/O)?
我是用回调方式实现的。

下面两个函数分别是发起一个回调和回调函数的具体实现。测试中发现在收到数据后Sleepex就死调。谁有没有这方面的例子?

procedure TMultiCast.CallMyFun;
var
Flags:DWORD;
RecvBytes:DWORD;
Index:DWORD;
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,RecvBytes:DWORD;
Flags:DWORD;
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;

大家给点建议吧?
 
即想了解一下能否实现在组播收发的过程中,使用overlapped i/o (重叠I/O)?
我是用回调方式实现的。

下面两个函数分别是发起一个回调和回调函数的具体实现。测试中发现在收到数据后Sleepex就死调。谁有没有这方面的例子?

procedure TMultiCast.CallMyFun;
var
Flags:DWORD;
RecvBytes:DWORD;
Index:DWORD;
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,RecvBytes:DWORD;
Flags:DWORD;
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;

大家给点建议吧?
 
后退
顶部