Quitting
Let's now implement the QUIT command. As always, we need to add a case in the handle_cmd() method:
#[async]
fn handle_cmd(mut self, cmd: Command) -> Result<Self> {
match cmd {
Command::Quit => self = await!(self.quit())?,
// …
}
}And here is the code of the quit() method:
#[async]
fn quit(mut self) -> Result<Self> {
if self.data_writer.is_some() {
unimplemented!();
} else {
self = await!(self.send(Answer::new(ResultCode::ServiceClosingControlConnection, "Closing connection...")))?;
self.writer.close()?;
}
Ok(self)
}So, we send a response back to the client and close() the writer.
To finish this chapter, let's implement the command to create and delete directories.