httpd_server_run(server): How to Stop the task

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

httpd_server_run(server): How to Stop the task

2,483 Views
Mike_d
Contributor IV

The TCP/IP task ends up with an "Invalid Task ID" error code when I stop the httpd server task using the code below. I also can't uninstall the tfs driver.  Can someone please tell me how I can gracefully shut down these services and bring them back up?

 

The Task:

void httpd_task(uint_32 initial_data)
{
 uint_32 error;


 HTTPD_STRUCT *server;
 extern const HTTPD_CGI_LINK_STRUCT cgi_lnk_tbl[];
 extern const HTTPD_FN_LINK_STRUCT fn_lnk_tbl[];
 extern const TFS_DIR_ENTRY tfs_data[];

 if ((error = _io_tfs_install("tfs:", tfs_data))) {
     printf("\ninstall returned: %08x\n", error);
 }

 server = httpd_server_init((HTTPD_ROOT_DIR_STRUCT*)root_dir, "\\index.html");
 HTTPD_SET_PARAM_CGI_TBL(server, (HTTPD_CGI_LINK_STRUCT*)cgi_lnk_tbl);
 //HTTPD_SET_PARAM_FN_TBL(server, (HTTPD_FN_LINK_STRUCT*)fn_lnk_tbl);

 httpd_server_run(server);
 _task_block();
 
 //This poll mode doesn't work
 //while(1)
 // httpd_server_poll(server, 1);
 
}

 

 

 

Killing the Task: 

   task_id = _task_get_id_from_name("httpd server");
   _task_abort(task_id);

   if((error = _io_tfs_uninstall("tfs:")))
       printf("\ntfs uninstall returned: %08x\n", error);
   
   task_id = _task_get_id_from_name("httpd task");
   _task_abort(task_id);

Message Edited by Mike_d on 2009-12-02 04:57 PM
Labels (1)
Tags (1)
0 Kudos
7 Replies

461 Views
eEjeremy
Contributor I
Can I ask why you are doing this?  I'm considering doing the same because i'm also using SMTP, and if I attempt to access the web server while sending an email bad things happen.
0 Kudos

461 Views
dspNeil
Contributor III

Calling httpd_server_stop() leaves a task called "httpd server" running, and the associated "httpd session" tasks. What are the proper function calls to gracefully terminate these tasks? Calling _task_abort() causes the system to crash.

0 Kudos

461 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

The httpd_release() function from the file C:\Program Files\Freescale\Freescale MQX 3.7\rtcs\source\httpd\httpd.c should be replaced with the code bellow:

 

_mqx_int httpd_release(HTTPD_STRUCT *server) {

    _mqx_int res = 0;

   

    if (server->run == 0 && server) {

        shutdown(server->sock, FLAG_ABORT_CONNECTION);

 

        memset(server->params, 0, sizeof(HTTPD_PARAMS_STRUCT));

        _task_destroy(_task_get_id_from_name("httpd server"));

    }

    else

        res = -1;

 

    return res;

}

 

After recompile all the libraries.

 

I am attaching a project for the M52259EVB that shows how to stop and restart the HTTP server.

0 Kudos

461 Views
dspNeil
Contributor III

Garabo,

I just had a look at your example, and found a problem. You are calling httpd_server_init() more than once, and using the same variable to store the result. httpd_server_init() calls httpd_init() which allocates memory that is not freed by httpd_server_stop().

 

Shouldn't httpd_release() also call HTTPD_FREE() ?

0 Kudos

461 Views
dspNeil
Contributor III

Thank you. I stumbled upon this solution myself.

However, this does not account for the situation when you have HTTPDCFG_STATIC_TASKS set to 1. If I am using dynamic tasks, than this works well.

Static task launches multiple "httpd session" tasks. How would one go about closing these sessions and terminating the associated tasks? I tried the following before destroying the "httpd server" task, with unsuccessful results:

while (( task_id = _task_get_id_from_name( "httpd session" ))!= MQX_NULL_TASK_ID ) {  _task_abort( task_id );}

 

 

 

0 Kudos

461 Views
PetrM
Senior Contributor I

Hello,

 

you should use _io_dev_uninstall ("tfs:") to uninstal TFS.

HTTPD server can be shut down using httpd_release() function.

There is also some free function for the sessions.

 

Regards,

PetrM

 

0 Kudos

461 Views
Mike_d
Contributor IV
Oh, and I also need to clean up any left over sessions.
0 Kudos