70 likes | 283 Views
Lab4. TA: Yi Cui 02/19/2013. Part 3. The category of CC caves: Cave 0-899: normal Cave 900-999: no exit Cave >999: monsters appear Two abnormal conditions with monsters (extra credit): A flybot is eaten Corrupted response . A flybot is eaten. Two conditions:
E N D
Lab4 TA: Yi Cui 02/19/2013
Part 3 • The category of CC caves: • Cave 0-899: normal • Cave 900-999: no exit • Cave >999: monsters appear • Two abnormal conditions with monsters (extra credit): • A flybot is eaten • Corrupted response
A flybot is eaten • Two conditions: • A timeout on WriteFile or ReadFile • An error in Windows API • The pipe is probably closed • Actions to take: • Put the node back to U • Update # running thread, # active thread • Kill the thread
A flybot is eaten • How to detect? • Non-blocking ReadFile and WriteFile to detect timeout • Check the return value of Windows APIs to catch error • Non-blocking functions OVERLAPPED ol; memset(&ol, 0, sizeof(OVERLAPPED)); BOOL bRet = ReadFile(pipe, buffer, bytesToRead, NULL, &ol); if (bRet == 0 && GetLastError() != ERROR_IO_PENDING) // API error bRet = WaitForSingleObject (pipe, timeout); // normally 2 sec timeout GetOverlappedResult (pipe, &ol, ...);
Corrupted response • Several conditions: • Invalid status code • Truncated message • Bogus room id • Actions to take: • Retry this node (do not kill the thread)
Corrupted response • How to detect? • status != SUCCESS && status != FAILURE • Invalid status code • responseSize < sizeof(ResponseRobot) • nonsense response • (responseSize- sizeof(ResponseRobot)) % sizeof(NodTuple64) != 0 • Truncated response