void TlsPskAdaptor::processBytes(std::vector<Botan::byte> buffer) { if (buffer.size() == 0) return handleEof(); auto bytesNeeded = channel->received_data(kj::mv(buffer)); if (bytesNeeded) { buffer.resize(bytesNeeded); tasks.add(stream->read(buffer.data(), buffer.size(), buffer.size()).then( [this, buffer = kj::mv(buffer)](size_t bytesRead) mutable { buffer.resize(bytesRead); processBytes(kj::mv(buffer)); })); } else startReadLoop(); }
bool com_milvich_driver_Thrustmaster::handleStart( IOService * provider ) { IOLog("%s: handleStart\n", NAME); // let the super do its thing if(!super::handleStart(provider)) { IOLog("%s: super failed to start\n", NAME); return false; } // get the interface fIface = OSDynamicCast(IOUSBInterface, provider); if(!fIface) { IOLog("%s: The provider is not an IOUSBInterface..\n", NAME); return false; } // open the interface if(!fIface->open(this)) { IOLog("%s: Failed to open the provider\n", NAME); fIface = NULL; return false; } // find the pipe to talk to the iMate over IOUSBFindEndpointRequest request; request.type = kUSBInterrupt; request.direction = kUSBIn; request.maxPacketSize = 0; request.interval = 0; fPipe = fIface->FindNextPipe(NULL, &request); if(fPipe) { //IOLog("%s: Found a pipe! type = %d, direction = %d, maxPacketSize = %04x, interval = %d\n", NAME, request.type, request.direction, request.maxPacketSize, request.interval); } else { IOLog("%s: Couldn't find a pipe\n", NAME); fIface->close(this); return false; } // lets retain things fIface->retain(); fPipe->retain(); // we want to setup a command gate to sync some actions fGate = IOCommandGate::commandGate(this); if(getWorkLoop()->addEventSource(fGate) != kIOReturnSuccess) { IOLog("%s: Failed to add the gate to the work loop\n", NAME); fIface->close(this); return false; } // kick off the read chain if(startReadLoop() != kIOReturnSuccess) { fIface->close(this); return false; } // kick off the init sequence IOCreateThread(initThread, this); return true; }