Ok, I though over this and a bit updated your patch so that it only waits if there are 'partially handled HTTP request' in the air (i.e. has already sent the message onward to bearerbox but has not yet stored the http client into disctionary). Moreover, the processing time between sending the message to bb and saving the client into dictionary has been minimized..
If you (or anybody else) could test this patched (diff -u) smsbox then that would be great. I already run 'make check' etc. with it and worked fine but currently I'm a bit busy to do more testing... :/ -- &Kalle Marjola ::: Development ::: Helsinki ::: Enpocket
Index: gw/smsbox.c =================================================================== RCS file: /home/cvs/gateway/gw/smsbox.c,v retrieving revision 1.257 diff -u -r1.257 smsbox.c --- gw/smsbox.c 22 Feb 2005 16:22:03 -0000 1.257 +++ gw/smsbox.c 18 Mar 2005 08:24:06 -0000 @@ -138,6 +138,7 @@ static int immediate_sendsms_reply = 0; static Dict *client_dict = NULL; static List *sendsms_reply_hdrs = NULL; +static Counter *partway_http_requests = NULL; /*********************************************************************** * Communication with the bearerbox. @@ -172,7 +173,17 @@ uuid_unparse(msg->ack.id, id); os = octstr_create(id); debug("sms.http", 0, "Got ACK (%ld) of %s", msg->ack.nack, octstr_get_cstr(os)); + retry_remove: client = dict_remove(client_dict, os); + if (client == NULL && counter_value(partway_http_requests)) { + /* + * most probably the bearerbox answers us faster than we have added + * the new request into our dictionary. So give some extra time for + * http request thread + */ + gwthread_sleep(0.1); + goto retry_remove; + } if (client == NULL) { debug("sms.http", 0, "No client - multi-send or ACK to pull-reply"); octstr_destroy(os); @@ -3137,65 +3148,73 @@ info(0, "smsbox: Got HTTP request <%s> from <%s>", octstr_get_cstr(url), octstr_get_cstr(ip)); - /* - * determine which kind of HTTP request this is any - * call the necessary routine for it - */ - - /* sendsms */ - if (octstr_compare(url, sendsms_url) == 0) - { - /* - * decide if this is a GET or POST request and let the - * related routine handle the checking + if (partway_http_requests) + counter_increase(partway_http_requests); + + /* + * determine which kind of HTTP request this is any + * call the necessary routine for it */ - if (body == NULL) - answer = smsbox_req_sendsms(args, ip, &status, &stored_uuid); - else - answer = smsbox_sendsms_post(hdrs, body, ip, &status, &stored_uuid); - } - /* XML-RPC */ - else if (octstr_compare(url, xmlrpc_url) == 0) - { - /* - * XML-RPC request needs to have a POST body - */ - if (body == NULL) { - answer = octstr_create("Incomplete request."); - status = HTTP_BAD_REQUEST; - } else - answer = smsbox_xmlrpc_post(hdrs, body, ip, &status); - } - /* sendota */ - else if (octstr_compare(url, sendota_url) == 0) - { - if (body == NULL) - answer = smsbox_req_sendota(args, ip, &status, &stored_uuid); - else - answer = smsbox_sendota_post(hdrs, body, ip, &status, &stored_uuid); - } - /* add aditional URI compares here */ - else { - answer = octstr_create("Unknown request."); - status = HTTP_NOT_FOUND; - } - debug("sms.http", 0, "Status: %d Answer: <%s>", status, - octstr_get_cstr(answer)); + /* sendsms */ + if (octstr_compare(url, sendsms_url) == 0) + { + /* + * decide if this is a GET or POST request and let the + * related routine handle the checking + */ + if (body == NULL) + answer = smsbox_req_sendsms(args, ip, &status, &stored_uuid); + else + answer = smsbox_sendsms_post(hdrs, body, ip, &status, &stored_uuid); + } + /* XML-RPC */ + else if (octstr_compare(url, xmlrpc_url) == 0) + { + /* + * XML-RPC request needs to have a POST body + */ + if (body == NULL) { + answer = octstr_create("Incomplete request."); + status = HTTP_BAD_REQUEST; + } else + answer = smsbox_xmlrpc_post(hdrs, body, ip, &status); + } + /* sendota */ + else if (octstr_compare(url, sendota_url) == 0) + { + if (body == NULL) + answer = smsbox_req_sendota(args, ip, &status, &stored_uuid); + else + answer = smsbox_sendota_post(hdrs, body, ip, &status, &stored_uuid); + } + /* add aditional URI compares here */ + else { + answer = octstr_create("Unknown request."); + status = HTTP_NOT_FOUND; + } + + /* store client if delayed reply */ + if (immediate_sendsms_reply || status != HTTP_ACCEPTED || stored_uuid == NULL) { + debug("sms.http", 0, "Status: %d Answer: <%s>", status, + octstr_get_cstr(answer)); + http_send_reply(client, status, sendsms_reply_hdrs, answer); + } + else { + dict_put(client_dict, stored_uuid, client); + debug("sms.http", 0, "Delayed reply - wait for bearerbox"); + octstr_destroy(stored_uuid); + } + + /* client stored, decrease counter */ + if (partway_http_requests) + counter_decrease(partway_http_requests); octstr_destroy(ip); octstr_destroy(url); http_destroy_headers(hdrs); octstr_destroy(body); http_destroy_cgiargs(args); - - if (immediate_sendsms_reply || status != HTTP_ACCEPTED || stored_uuid == NULL) - http_send_reply(client, status, sendsms_reply_hdrs, answer); - else { - debug("sms.http", 0, "Delayed reply - wait for bearerbox"); - dict_put(client_dict, stored_uuid, client); - octstr_destroy(stored_uuid); - } octstr_destroy(answer); } @@ -3411,6 +3430,8 @@ /* should smsbox reply to sendsms immediate or wait for bearerbox ack */ cfg_get_bool(&immediate_sendsms_reply, grp, octstr_imm("immediate-sendsms-reply")); + if (!immediate_sendsms_reply) + partway_http_requests = counter_create(); /* determine which timezone we use for access logging */ if ((p = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { @@ -3589,7 +3610,9 @@ dict_destroy(client_dict); http_destroy_headers(sendsms_reply_hdrs); - + if (partway_http_requests) + counter_destroy(partway_http_requests); + /* * Just sleep for a while to get bearerbox chance to restart. * Otherwise we will fail while trying to connect to bearerbox!