[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] Starting over?



On 3 Jun 2015, at 17:24, Wouter Verhelst <w@...112...> wrote:

> What I think is the main issue with nbd-server, though, is the fact that
> it uses the stack as a state machine. That is, we read out one request
> from the network (e.g., a read request), call a function to handle it
> (expread), which checks if we do copy-on-write and calls rawexpread,
> which does a seek and reads data into a buffer, and then we unwind the
> stack and eventually (in mainloop()) we send the reply to the client.
> 
> Instead, it should be refactored so that it reads a request into a
> buffer, and returns to mainloop if we block for I/O, so that we can
> handle multiple requests at the same time.

Yeah I rewrote negotiation as a state machine (the idea being to publish
it under something more liberal than GPL) and it was truly fugly.

I agree using the stack for state (as you put it) is not nice. But
if the idea is merely to handle simultaneous requests, threading
might be an alternative route. IE have one thread handling the
socket, and a bunch of workers handling the requests.

This would be trivial in golang.

-- 
Alex Bligh







Reply to: