public override TupleClass Read(TupleClass tuple) { checkFrozen(); setView(); WaitHandle[] handles = new WaitHandle[numServers]; IAsyncResult[] asyncResults = new IAsyncResult[numServers]; try { for (int i = 0; i < numServers; i++) { IServerService remoteObject = view[i]; readDelegate readDel = new readDelegate(remoteObject.Read); IAsyncResult ar = readDel.BeginInvoke(tuple, url, nonce, null, null); asyncResults[i] = ar; handles[i] = ar.AsyncWaitHandle; } int indxAsync = WaitHandle.WaitAny(handles, 1000); if (indxAsync == WaitHandle.WaitTimeout) { Thread.Sleep(200); return(Read(tuple)); } else //TODO se o retorno for nulo temos de ir ver outra resposta { IAsyncResult asyncResult = asyncResults[indxAsync]; readDelegate readDel = (readDelegate)((AsyncResult)asyncResult).AsyncDelegate; TupleClass resTuple = readDel.EndInvoke(asyncResult); nonce++; return(resTuple); } } catch (SocketException) { Console.WriteLine("Error in read. Trying again..."); return(Read(tuple)); } }
public unsafe static extern void */*MyOgreVirtualArchiveFactory*/ New( void *root, openDelegate open, closeDelegate close, readDelegate read, skipDelegate skip, seekDelegate seek, tellDelegate tell, findDelegate find, findFileInfoDelegate findFileInfo, fileExistsDelegate fileExists);