Hi All,
attached patch should fix the problem that in read_from_box function we
can define timeout but as we always get NULL as message we can't
differentiate whether here a error occurs or we just time outed.
Please vote!
Thanks,
Alex
Alexander Malysh schrieb:
Hi Rene,
the problem is that read_from_box function take timeout as argument
but does not respect it. I have enhanced version in my tree, will try
to post it this week.
Thanks,
Alex
Rene Kluwen schrieb:
Alex,
I agree. Do you have a better option?
Rene Kluwen
Chimit
-----------------------------------------------------------------------
alex - 03-14-06 20:29 GMT
-----------------------------------------------------------------------
Hi Rene,
your patch is more a hack as solution. -1 from me.
------------------------------------------------------------------------
Index: gw/shared.c
===================================================================
RCS file: /home/cvs/gateway/gw/shared.c,v
retrieving revision 1.38
diff -a -u -p -r1.38 shared.c
--- gw/shared.c 11 Feb 2005 15:35:48 -0000 1.38
+++ gw/shared.c 17 Mar 2006 11:15:59 -0000
@@ -189,13 +189,13 @@ void connect_to_bearerbox(Octstr *host,
void close_connection_to_bearerbox_real(Connection *conn)
{
conn_destroy(conn);
- conn = NULL;
}
void close_connection_to_bearerbox(void)
{
close_connection_to_bearerbox_real(bb_conn);
+ bb_conn = NULL;
}
@@ -242,13 +242,13 @@ int deliver_to_bearerbox(Msg *msg)
}
-Msg *read_from_bearerbox_real(Connection *conn, double seconds)
+int read_from_bearerbox_real(Connection *conn, Msg **msg, double seconds)
{
int ret;
Octstr *pack;
- Msg *msg;
pack = NULL;
+ *msg = NULL;
while (program_status != shutting_down) {
pack = conn_read_withlen(conn);
gw_claim_area(pack);
@@ -256,41 +256,43 @@ Msg *read_from_bearerbox_real(Connection
break;
if (conn_error(conn)) {
- info(0, "Error reading from bearerbox, disconnecting.");
- return NULL;
+ error(0, "Error reading from bearerbox, disconnecting.");
+ return -1;
}
if (conn_eof(conn)) {
- info(0, "Connection closed by the bearerbox.");
- return NULL;
+ error(0, "Connection closed by the bearerbox.");
+ return -1;
}
ret = conn_wait(conn, seconds);
if (ret < 0) {
error(0, "Connection to bearerbox broke.");
- return NULL;
+ return -1;
}
else if (ret == 1) {
- info(0, "Connection to bearerbox timed out after %.2f seconds.",
seconds);
- return NULL;
+ /* debug("gwlib.gwlib", 0, "Connection to bearerbox timed out after
%.2f seconds.", seconds); */
+ return 1;
}
}
-
+
if (pack == NULL)
- return NULL;
+ return -1;
- msg = msg_unpack(pack);
+ *msg = msg_unpack(pack);
octstr_destroy(pack);
- if (msg == NULL)
+ if (*msg == NULL) {
error(0, "Failed to unpack data!");
+ return -1;
+ }
- return msg;
+ return 0;
}
-Msg *read_from_bearerbox(double seconds)
+int read_from_bearerbox(Msg **msg, double seconds)
{
- return read_from_bearerbox_real(bb_conn, seconds);
+ return read_from_bearerbox_real(bb_conn, msg, seconds);
}
Index: gw/shared.h
===================================================================
RCS file: /home/cvs/gateway/gw/shared.h,v
retrieving revision 1.18
diff -a -u -p -r1.18 shared.h
--- gw/shared.h 11 Feb 2005 15:35:48 -0000 1.18
+++ gw/shared.h 17 Mar 2006 11:15:59 -0000
@@ -113,13 +113,13 @@ void close_connection_to_bearerbox(void)
/*
- * Receive Msg from bearerbox. Unblock the call when the given
- * timeout for conn_wait() is reached. Use a negative value,
- * ie. -1 for an infinite blocking, hence no timeout applies.
- * Return NULL if connection broke or timed out.
+ * Receive and store Msg from bearerbox into msg. Unblock the call when
+ * the given timeout for conn_wait() is reached. Use a negative value,
+ * ie. -1 for an infinite blocking, hence no timeout applies.
+ * Return 0 if Msg received ; -1 if error occurs; 1 if timedout.
*/
-Msg *read_from_bearerbox_real(Connection *conn, double seconds);
-Msg *read_from_bearerbox(double seconds);
+int read_from_bearerbox_real(Connection *conn, Msg **msg, double seconds);
+int read_from_bearerbox(Msg **msg, double seconds);
/*
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.260
diff -a -u -p -r1.260 smsbox.c
--- gw/smsbox.c 9 Dec 2005 02:14:31 -0000 1.260
+++ gw/smsbox.c 17 Mar 2006 11:16:01 -0000
@@ -224,14 +224,19 @@ static void read_messages_from_bearerbox
time_t start, t;
int secs;
int total = 0;
+ int ret;
Msg *msg;
start = t = time(NULL);
while (program_status != shutting_down) {
- /* block infinite for reading messages */
- msg = read_from_bearerbox(INFINITE_TIME);
- if (msg == NULL)
- break;
+ /* block infinite for reading messages */
+ ret = read_from_bearerbox(&msg, INFINITE_TIME);
+ if (ret == -1)
+ break;
+ else if (ret == 1) /* timeout */
+ continue;
+ else if (msg == NULL) /* just to be sure, may not happens */
+ break;
if (msg_type(msg) == admin) {
if (msg->admin.command == cmd_shutdown) {
Index: gw/wapbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/wapbox.c,v
retrieving revision 1.181
diff -a -u -p -r1.181 wapbox.c
--- gw/wapbox.c 9 Feb 2006 01:26:17 -0000 1.181
+++ gw/wapbox.c 17 Mar 2006 11:16:01 -0000
@@ -749,11 +749,16 @@ int main(int argc, char **argv)
while (program_status != shutting_down) {
WAPEvent *dgram;
+ int ret;
- /* block infinite for reading messages */
- msg = read_from_bearerbox(INFINITE_TIME);
- if (msg == NULL)
- break;
+ /* block infinite for reading messages */
+ ret = read_from_bearerbox(&msg, INFINITE_TIME);
+ if (ret == -1)
+ break;
+ else if (ret == 1) /* timeout */
+ continue;
+ else if (msg == NULL) /* just to be sure, may not happens */
+ break;
if (msg_type(msg) == admin) {
if (msg->admin.command == cmd_shutdown) {
info(0, "Bearerbox told us to die");
Index: utils/mtbatch.c
===================================================================
RCS file: /home/cvs/gateway/utils/mtbatch.c,v
retrieving revision 1.7
diff -a -u -p -r1.7 mtbatch.c
--- utils/mtbatch.c 11 Feb 2005 15:35:49 -0000 1.7
+++ utils/mtbatch.c 17 Mar 2006 11:16:01 -0000
@@ -141,9 +141,14 @@ static void read_messages_from_bearerbox
total_s = total_f = total_ft = total_b = 0;
start = t = time(NULL);
while (program_status != shutting_down) {
+ int ret;
/* block infinite for reading messages */
- msg = read_from_bearerbox(INFINITE_TIME);
- if (msg == NULL)
+ ret = read_from_bearerbox(&msg, INFINITE_TIME);
+ if (ret == -1)
+ break;
+ else if (ret == 1) /* timeout */
+ continue;
+ else if (msg == NULL) /* just to be sure, may not happens */
break;
if (msg_type(msg) == admin) {