![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Обработка событий WInSock
GreatLesh © (2003-06-19 07:55:00)
Как узнать, что произошел disconnect с другой стороны?
panov (2003-06-19 10:41:00) [1]Вот так, например:
function TThSC.fWaitEvent(aTimeOut:Cardinal): Cardinal;
var
wne: WSANETWORKEVENTS;
begin
WSAResetEvent(fEvent);
WaitForSingleObject(fEvent,aTimeOut);
WSAEnumNetworkEvents(fSocket,fEvent,@wne);
Result := wne.lNetworkEvents;
Exit;
end;
procedure TThSC.Execute;
var
WaitResult: Cardinal;
begin
repeat
WaitResult := fWaitEvent(1);
if WaitResult=WSA_WAIT_FAILED then Terminate;
if WaitResult=WSA_WAIT_TIMEOUT then continue;
if Terminated then Exit;
if (WaitResult and FD_READ)=FD_READ then
begin
onReceive;
end;
if (WaitResult and FD_CLOSE)=FD_CLOSE then
begin
OnClosed;
Terminate;
break;
end;
if (WaitResult and FD_WRITE)=FD_WRITE then
begin
OnWrite;
( WaitResult = WAIT_FAILED)Вот так, например:
function TThSC.fWaitEvent(aTimeOut:Cardinal): Cardinal;
var
wne: WSANETWORKEVENTS;
begin
WSAResetEvent(fEvent);
WaitForSingleObject(fEvent,aTimeOut);
WSAEnumNetworkEvents(fSocket,fEvent,@wne);
Result := wne.lNetworkEvents;
Exit;
end;
procedure TThSC.Execute;
var
WaitResult: Cardinal;
begin
repeat
WaitResult := fWaitEvent(1);
if WaitResult=WSA_WAIT_FAILED then Terminate;
if WaitResult=WSA_WAIT_TIMEOUT then continue;
if Terminated then Exit;
if (WaitResult and FD_READ)=FD_READ then
begin
onReceive;
end;
if (WaitResult and FD_CLOSE)=FD_CLOSE then
begin
OnClosed;
Terminate;
break;
end;
if (WaitResult and FD_WRITE)=FD_WRITE then
begin
OnWrite;
end;
until (WaitResult = WAIT_FAILED) or Terminated;
end;
Digitman (2003-06-19 08:09:00) [2]
именно в WinsockAPI ?