Skip to content

Commit 4d75304

Browse files
committed
ABORT implementation successful via double fork demon
- the developed solution matches the classic double fork method to produce daemon processes. - concept standardization established. Good to go. - Note - The current implementation is only inside `RETR` command. - Next steps - Extend it to other commands using same method.
1 parent 1a3df0d commit 4d75304

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/client/commands/cmd_ABOR.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ void Client::cmd_ABOR(int controlConnectionfd) {
2828
* so,
2929
* a design decision has to be made
3030
* about how this abort implementation should be elegantly incorportated in the main branch.
31+
*
3132
*/

src/client/commands/cmd_RETR.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
// RETR - get/retrive a file from server
44

55
void Client::cmd_RETR(int controlConnectionfd, const vector<string>& args) {
6-
6+
7+
/**Data connection before fork() . why not ?
8+
*
9+
* Was not working.
10+
* Was giving error : connection reset by peer ; don't know why
11+
*
12+
*/
13+
714
string ftpResponse;
815

916
/**Create a child - As per RFC 959
@@ -93,6 +100,11 @@ void Client::cmd_RETR(int controlConnectionfd, const vector<string>& args) {
93100
int dataConnectionfd = createDataConnection(controlConnectionfd);
94101

95102
// send a signal to parent that he is safe to return now
103+
104+
// the independently developed solution
105+
// matches with the standard solution for daemon production.
106+
// ref - https://stackoverflow.com/a/10932710
107+
96108
int newp = fork();
97109
if(newp > 0){
98110
string s = executeShellCommand("ps fj");

src/server/commands/cmd_RETR.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
// RETR - get/retrive a file from server
44
void Server::cmd_RETR(int controlConnectionfd, const vector<string>& args) {
5+
6+
/**Data connection before fork() . why not ?
7+
*
8+
* Was not working.
9+
* Was giving error : connection reset by peer ; don't know why
10+
*
11+
*/
12+
513
int pid = fork();
614
if (pid < 0) { // error
715
printError();
@@ -50,6 +58,10 @@ void Server::cmd_RETR(int controlConnectionfd, const vector<string>& args) {
5058
// @abort
5159
int dataConnectionfd = createDataConnection(controlConnectionfd);
5260

61+
// the independently developed solution
62+
// matches with the standard solution for daemon production.
63+
// ref - https://stackoverflow.com/a/10932710
64+
5365
// send a signal to parent that he is safe to return now
5466
int newpid = fork();
5567
if(newpid > 0){

0 commit comments

Comments
 (0)