Here is some pseudocode that I trying to implement the async io (eg. send/receive).
Event loop waits for a ready to receive event like EPOLLIN:
while (true) {
if (readyToRecv) {
onReceived(context);
}
}
The callback function of ready to receive:
void onReceived(IOContext context)
{
Buffer data; // Line 1
context.asyncRecv(data);// Line 2
process(data); // Line 3
context.asyncSend(data);// Line 4
...
}
after received some data I expect the running result go like this:
- enter
onReceived Line 1Line 2- spawn a
readjob (into a thread pool) onReceivedreturn- when
readjob is done reenter theonReceivedfunction - ignore
Line 1 & 2, jump toLine 3
I need some ideas about implementation, especially the jump action.
I guess this can be achieved by __LINE__ MACRO with exception handling or setjmp...
Aucun commentaire:
Enregistrer un commentaire