Мои Конспекты
Главная | Обратная связь

...

Автомобили
Астрономия
Биология
География
Дом и сад
Другие языки
Другое
Информатика
История
Культура
Литература
Логика
Математика
Медицина
Металлургия
Механика
Образование
Охрана труда
Педагогика
Политика
Право
Психология
Религия
Риторика
Социология
Спорт
Строительство
Технология
Туризм
Физика
Философия
Финансы
Химия
Черчение
Экология
Экономика
Электроника

With BiDirPipeLocks do





Помощь в ✍️ написании работы
Поможем с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой

Begin

With Cli2ServLocks do

Begin

With BiDirPipe.Cli2ServPipe do

Begin

If ReaderBlocked then

Begin

ReaderBlocked := false;

ReleaseSemaphore(ReaderSem, 1, nil);

end;

If WriterBlocked then

Begin

WriterBlocked := false;

ReleaseSemaphore(WriterSem, 1, nil);

end;

end;

end;

With Serv2CliLocks do

Begin

With BiDirPipe.Serv2CliPipe do

Begin

If ReaderBlocked then

Begin

ReaderBlocked := false;

ReleaseSemaphore(ReaderSem, 1, nil);

end;

If WriterBlocked then

Begin

WriterBlocked := false;

ReleaseSemaphore(WriterSem, 1, nil);

end;

end;

end;

{Now have to think about functions waiting for peer.}

{We basically have to unblock all threads blocked waiting for peer

on our handle}

With BiDirPipe^ do

Begin

If Server then

Begin

If ServPeerWait then

Begin

ServPeerWait := false;

ReleaseSemaphore(ServPeerWaitSem, 1, nil);

end;

End

Else

Begin

If CliPeerWait then

Begin

CliPeerWait := false;

ReleaseSemaphore(CLiPeerWaitSem, 1, nil);

end;

end;

end;

end;

end;

{Release mutex before unblocking}

ReleaseMutex(BiDirPipeLocks.BiLock);

if Result = meOK then

Begin

ReleaseMutex(BiDirPipeLocks.Cli2ServLocks.PipeLock);

ReleaseMutex(BiDirPipeLocks.Serv2CliLocks.PipeLock);

end;

end;

 

function ConnectServer(var hHandle: TMCHHandle): TMCHError stdcall;

{Returns error if server already connected}

Begin

SetLastError(0);

result := GenericConnect(hHandle, true);

end;

 

function ConnectClient(var hHandle: TMCHHandle): TMCHError stdcall;

{Returns error if client already connected}

Begin

SetLastError(0);

result := GenericConnect(hHandle, false);

end;

 

function DisconnectServer(hHandle: TMCHHandle): TMCHError stdcall;

Begin

SetLastError(0);

result := GenericDisconnect(hHandle, true);

end;

 

function DisconnectClient(hHandle: TMCHHandle): TMCHError stdcall;

Begin

SetLastError(0);

result := GenericDisconnect(hHandle, false);

end;

 

{Generic procedures to prevent duplicity}

 

{This function is *highly* cunning.

It simply wraps up both reading and writing by both client and server int one procedure.

He that writeth less code, debuggeth less at the end of the day.}

 

function GenericReadWrite(var Buf; Count: integer; var SrcDestPipe: TPipe;

var Locks: TPipeLocks; Read: boolean): TMCHError;

Var

BlockSelf, UnblockPeer: boolean;

DoThisTime: integer;

SrcDestPtr: PByte;

Avail: integer;

Begin

{Game plan.

Check that neither client or server disconnected.

Read/Write as much as possible and block if required.

upon unblock, recheck connection status before proceeding.

Once any data has been read/written, unblock the peer on the buffer.

Nested mutex aquisition also required here. Respect ordering.}

result := meOK;

SrcDestPtr := @Buf;

Repeat

{connection data critical section}

WaitForSingleObject(BiDirPipeLocks.BiLock, INFINITE);

WaitForSingleObject(Locks.PipeLock, INFINITE);

{Now check connection status}

if not BiDirPipe.ServConnected then result := meServerNotConnected;

if not BiDirPipe.CliConnected then result := meClientNotConnected;

if result <> meOK then

Begin

{bomb out if not all connected}

ReleaseMutex(BiDirPipeLocks.BiLock);

ReleaseMutex(Locks.PipeLock);

Exit;

end;

{So far, it's okay to read/write}

{Read/write as much as we can this time.}

Доверь свою работу ✍️ кандидату наук!
Поможем с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой



Поиск по сайту:







©2015-2020 mykonspekts.ru Все права принадлежат авторам размещенных материалов.