Well, I am writing a multithreaded FTP server and now I am trying to implement data transfer abortion. This is a part of my code managing data transfer abortion.
ABORCommand(); //sends message with code 226 (1st message)
pthread_join(threads, &ret); //waits for the thread processing data transfer
sprintf(buffer, "226 Transfer complete - %d bytes copied.\r\n", data_comm->num_bytes);
Send(); //this just sends the message in buffer to the client (2nd message)
WriteToLog("transfer complete", "226");
close(data_comm->clie_sock); //closes the data connection
delete data_comm; //this deletes instance of the class taking care of data transfer
- My problem is that the two clients I am testing (Nautilus and gftp client) behave differently when aborting data transfer.
- What I am trying to achieve is to be able to abort data transfer process with no errors using different clients.
- The behaviour of the clients depends on the messages I send them.
- When I abort the transfer with Nautilus, it work fine, no errors, no leaks. But with gftp client, the client recieves the first message and then closes control connection. Then the server sends the second message to the client. After that, the server is supposed to recieve something from the client, but when it happens, I get an error and a ton of mem leaks. I know that reading from closed socket gives error but it shouldn't crash the whole program.
- I tried to make the abortion work for the gftp client and the only (partial) solution was to send only the second message (well, I think it doesn't matter which one I send the point is to send just one of them). I didn't get any errors after that and no mem leaks. The only problem left was that the client still closed the control connection. The server then closed the connection on it's end, because the client apparently disconnected (even the gftp client wrote "Disconnecting from site localhost"), but after the server closes it, gftp writes "Error: Remote site localhost disconnected. Will reconnect in 30 seconds".
- The solution however had a side effect. The Nautilus client stopped working. The client recieved the message ,but was still waiting for another one (or so I think), because I sent him just one message.
- My question is how is it possible to make it work for both clients? The only idea I have is that maybe the reply code is wrong. Please, tell me where the problem lies.
Thanks