Re: fakesmsmc.c patch
Alejandro Guerrieri <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Nikos,
The interactive mechanism allows you to type messages from the command
line (one per line). Each time enter is pressed a new message is sent.
Regards,
Alejandro Guerrieri
El 19/11/2008, a las 07:20 p.m., Nikos Balkanas escribió:
> Dear list,
>
> This patch will address the following issues in test/fakesmsc.c
>
> 1) fakesmsc will no longer hangup on conn_wait when delta == -1
> (end) and will exit as soon as messages are finished.
> 2) Rudimentary matching of messages by comparing the to: field to
> the returned text. It is very simple, but better than nothing.
> 3) Better logging. Now from: and to: fields are displayed in the
> Sent msg.
>
> If someone would care to explain me the logic behind interactive, I
> could also provide a serious multithreaded matrix tool able to grind
> the CPU to dust.
>
> Fakesmsc.c.orig is the 1 month old CVS version.
>
> BR,
> Nikos
>
> *** fakesmsc.c.orig Wed Nov 19 22:56:43 2008
> --- fakesmsc.c Wed Nov 19 18:31:12 2008
> ***************
> *** 230,236 ****
> double first_received_at, last_received_at;
> double first_sent_at, last_sent_at;
> double start_time, end_time;
> ! double delta;
> int interactive, maxfd;
> char *cptr;
> char buffer[IN_BUFSIZE];
> --- 230,236 ----
> double first_received_at, last_received_at;
> double first_sent_at, last_sent_at;
> double start_time, end_time;
> ! double delta = 0;
> int interactive, maxfd;
> char *cptr;
> char buffer[IN_BUFSIZE];
> ***************
> *** 237,242 ****
> --- 237,243 ----
> fd_set rset;
> struct timeval alarm;
> FILE *fp;
> + char *p, from[25], to[11];
>
> gwlib_init();
> setup_signal_handlers();
> ***************
> *** 245,251 ****
>
> mptr = get_and_set_debugs(argc, argv, check_args);
> num_msgs = argc - mptr;
> !
> interactive = 0;
> msgs = NULL;
> fp = NULL;
> --- 246,252 ----
>
> mptr = get_and_set_debugs(argc, argv, check_args);
> num_msgs = argc - mptr;
> !
> interactive = 0;
> msgs = NULL;
> fp = NULL;
> ***************
> *** 282,288 ****
> last_sent_at = 0;
>
> /* infinitely loop */
> ! while (1) {
> /* Are we on interactive mode? */
> if (interactive == 1) {
> /* Check if we need to clean things up beforehand */
> --- 283,289 ----
> last_sent_at = 0;
>
> /* infinitely loop */
> ! while (interactive || delta >= 0) {
> /* Are we on interactive mode? */
> if (interactive == 1) {
> /* Check if we need to clean things up beforehand */
> ***************
> *** 325,335 ****
> panic(0, "write failed");
>
> ++num_sent;
> if (num_sent == max_send)
> ! info(0, "fakesmsc: sent message %ld", num_sent);
> else
> ! debug("send", 0, "fakesmsc: sent message %ld",
> num_sent);
> !
> if (rnd > 0)
> octstr_destroy(msg);
>
> --- 326,340 ----
> panic(0, "write failed");
>
> ++num_sent;
> + strncpy(from, octstr_get_cstr(msg), 24);
> + p = strchr(from, ' ');
> + *p = '\0';
> + strncpy(to, ++p, 10);
> + if ((p = strchr(to, ' '))) *p = '\0';
> if (num_sent == max_send)
> ! info(0, "fakesmsc: Sent msg %ld <%s %s>",
> num_sent, to, from);
> else
> ! debug("send", 0, "fakesmsc: Sent msg %ld <%s %s>",
> num_sent, to, from);
> if (rnd > 0)
> octstr_destroy(msg);
>
> ***************
> *** 344,350 ****
> delta = 0;
> if (num_sent >= max_send)
> delta = -1;
> ! conn_wait(server, delta);
> if (conn_error(server) || conn_eof(server) ||
> sigint_received)
> goto over;
>
> --- 349,355 ----
> delta = 0;
> if (num_sent >= max_send)
> delta = -1;
> ! if (delta > 0) conn_wait(server, delta);
> if (conn_error(server) || conn_eof(server) ||
> sigint_received)
> goto over;
>
> ***************
> *** 353,369 ****
> last_received_at = get_current_time();
> if (first_received_at == 0)
> first_received_at = last_received_at;
> ! ++num_received;
> ! if (num_received == max_send) {
> ! info(0, "Got message %ld: <%s>", num_received,
> ! octstr_get_cstr(line));
> ! } else {
> ! debug("receive", 0, "Got message %ld: <%s>",
> num_received,
> ! octstr_get_cstr(line));
> ! }
> octstr_destroy(line);
> }
> ! } while (delta > 0 || num_sent >= max_send);
> }
>
> over:
> --- 358,378 ----
> last_received_at = get_current_time();
> if (first_received_at == 0)
> first_received_at = last_received_at;
> ! if (strstr(octstr_get_cstr(line), to))
> ! {
> ! ++num_received;
> ! if (num_received == max_send) {
> ! info(0, "Got message %ld: <%s>", num_received,
> ! octstr_get_cstr(line));
> ! break;
> ! } else {
> ! debug("receive", 0, "fakesmsc: Got msg %ld: <%s>",
> num_received,
> ! octstr_get_cstr(line));
> ! }
> ! }
> octstr_destroy(line);
> }
> ! } while (delta > 0 || num_received < num_sent);
> }
>
> over:
> ***************
> *** 394,397 ****
>
> return 0;
> }
> <fakesmsc.diff>