Well, I am writing a multithreaded FTP server and now I am trying to implement data transfer abortion. 好吧,我正在编写一个多线程FTP服务器,现在我正在尝试实现数据传输中止。 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. 我的问题是,中止数据传输时,我正在测试的两个客户端(Nautilus和gftp客户端)的行为不同。
- 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. 当我用Nautilus中止传输时,它工作正常,没有错误,没有泄漏。 But with gftp client, the client recieves the first message and then closes control connection. 但是对于gftp客户端,客户端会收到第一条消息,然后关闭控件连接。 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). 我试图使gftp客户端可以使用堕胎,唯一的(部分)解决方案是仅发送第二条消息(嗯,我认为发送哪一条消息并不重要,只发送其中一条即可)。 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". 然后服务器关闭了它的连接,因为客户端显然已断开连接(即使gftp客户端写了“从站点本地主机断开连接”),但是服务器关闭后,gftp则写了“错误:远程站点本地主机断开了连接。将在30秒”。
- The solution however had a side effect. 然而,该解决方案具有副作用。 The Nautilus client stopped working. Nautilus客户端停止工作。 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 谢谢