start method
Implementation
Future<void> start() async {
while (!_stopped) {
final waitResult = synchronizer.waitForRequest();
if (waitResult == Atomics.timedOut) {
// No requests for some time, transition to idle
_releaseImplicitLocks();
continue;
}
int rc;
WorkerOperation? opcode;
Object? request;
try {
opcode = WorkerOperation.values[synchronizer.takeOpcode()];
request = opcode.readRequest(messages);
Message response;
switch (opcode) {
case WorkerOperation.xSleep:
_releaseImplicitLocks();
await Future<void>.delayed(
Duration(milliseconds: (request as Flags).flag0));
response = const EmptyMessage();
break;
case WorkerOperation.xAccess:
response = await _xAccess(request as NameAndInt32Flags);
break;
case WorkerOperation.xDelete:
await _xDelete(request as NameAndInt32Flags);
response = const EmptyMessage();
break;
case WorkerOperation.xOpen:
response = await _xOpen(request as NameAndInt32Flags);
break;
case WorkerOperation.xRead:
response = await _xRead(request as Flags);
break;
case WorkerOperation.xWrite:
response = await _xWrite(request as Flags);
break;
case WorkerOperation.xClose:
await _xClose(request as Flags);
response = const EmptyMessage();
break;
case WorkerOperation.xFileSize:
response = await _xFileSize(request as Flags);
break;
case WorkerOperation.xTruncate:
response = await _xTruncate(request as Flags);
break;
case WorkerOperation.xSync:
response = await _xSync(request as Flags);
break;
case WorkerOperation.xLock:
response = await _xLock(request as Flags);
break;
case WorkerOperation.xUnlock:
response = await _xUnlock(request as Flags);
break;
case WorkerOperation.stopServer:
response = const EmptyMessage();
_stopped = true;
_releaseImplicitLocks();
break;
}
messages.write(response);
rc = 0;
} on VfsException catch (e) {
_log('Caught $e while handling $opcode($request)');
rc = e.returnCode;
} catch (e) {
_log('Caught $e while handling $opcode($request)');
rc = 1;
}
synchronizer.respond(rc);
}
}