Skip to content

Commit

Permalink
ABORT implementation successful via double fork demon
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
jatin69 committed Jan 8, 2020
1 parent 1a3df0d commit 4d75304
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/client/commands/cmd_ABOR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ void Client::cmd_ABOR(int controlConnectionfd) {
* so,
* a design decision has to be made
* about how this abort implementation should be elegantly incorportated in the main branch.
*
*/
14 changes: 13 additions & 1 deletion src/client/commands/cmd_RETR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
// RETR - get/retrive a file from server

void Client::cmd_RETR(int controlConnectionfd, const vector<string>& args) {


/**Data connection before fork() . why not ?
*
* Was not working.
* Was giving error : connection reset by peer ; don't know why
*
*/

string ftpResponse;

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

// send a signal to parent that he is safe to return now

// the independently developed solution
// matches with the standard solution for daemon production.
// ref - https://stackoverflow.com/a/10932710

int newp = fork();
if(newp > 0){
string s = executeShellCommand("ps fj");
Expand Down
12 changes: 12 additions & 0 deletions src/server/commands/cmd_RETR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

// RETR - get/retrive a file from server
void Server::cmd_RETR(int controlConnectionfd, const vector<string>& args) {

/**Data connection before fork() . why not ?
*
* Was not working.
* Was giving error : connection reset by peer ; don't know why
*
*/

int pid = fork();
if (pid < 0) { // error
printError();
Expand Down Expand Up @@ -50,6 +58,10 @@ void Server::cmd_RETR(int controlConnectionfd, const vector<string>& args) {
// @abort
int dataConnectionfd = createDataConnection(controlConnectionfd);

// the independently developed solution
// matches with the standard solution for daemon production.
// ref - https://stackoverflow.com/a/10932710

// send a signal to parent that he is safe to return now
int newpid = fork();
if(newpid > 0){
Expand Down

0 comments on commit 4d75304

Please sign in to comment.