[RFC] gsmd multi-line response support, 2nd try
pHilipp Zabel
philipp.zabel at gmail.com
Tue Jul 31 14:19:01 CEST 2007
On 7/31/07, Harald Welte <laforge at openmoko.org> wrote:
> On Tue, Jul 31, 2007 at 11:11:58AM +0200, pHilipp Zabel wrote:
> > On 7/31/07, Harald Welte <laforge at openmoko.org> wrote:
> > > On Mon, Jun 18, 2007 at 04:16:41PM +0200, Philipp Zabel wrote:
> > > > Hi!
> > > >
> > > > This second try works much better in that every extended response causes
> > > > a flush of the previous mlbuf and starts collecting new response lines.
> > > > Also, final_cb is now really only reached for final responses and the
> > > > code for case 'A' won't overwrite the command buffer with the response
> > > > anymore. I throw in '\n' as a separator for multi-line responses, and
> > > > the callback is called for each response this way.
> > >
> > > I've now committed this patch, just changing one minor detail: the
> > > static size of 1024 for mlbuf has been replaced with a constat that's
> > > defined in the header file to 65535.
> > >
> > > I'd actually prefer to have that buffer static in bss, rather than
> > > putting it on the stack every time we enter the parser.
> >
> > Like this?
>
> thinking more about it, we should not have any global variables in order
> to have the architecture to support multiple modems or the like. Thus,
> the buffer should actually be part of struct gsmd (or rather: Something
> that is allocated and where a pointer member from struct gsmd points to)
I agree. This patch just moves mlbuf into struct gsmd, as a pointer to
talloc'ated memory. Where should the corresponding talloc_free() be put?
Index: gsm/include/gsmd/gsmd.h
===================================================================
--- gsm.orig/include/gsmd/gsmd.h 2007-07-31 14:07:47.000000000 +0200
+++ gsm/include/gsmd/gsmd.h 2007-07-31 14:09:02.000000000 +0200
@@ -74,6 +74,8 @@
struct gsmd_device_state dev_state;
struct llist_head operators; /* cached list of operator names */
+ unsigned int mlbuf_len;
+ unsigned char *mlbuf; /* ml_parse buffer */
};
struct gsmd_user {
Index: gsm/src/gsmd/atcmd.c
===================================================================
--- gsm.orig/src/gsmd/atcmd.c 2007-07-31 14:06:49.000000000 +0200
+++ gsm/src/gsmd/atcmd.c 2007-07-31 14:12:33.000000000 +0200
@@ -175,9 +175,7 @@
{
struct gsmd *g = ctx;
struct gsmd_atcmd *cmd = NULL;
- static char mlbuf[MLPARSE_BUF_SIZE];
int rc = 0, final = 0;
- int mlbuf_len;
DEBUGP("buf=`%s'(%d)\n", buf, len);
@@ -273,15 +271,15 @@
/* it might be a multiline response, so if there's a previous
response, send out mlbuf and start afresh with an empty buffer */
- if (mlbuf[0] != 0) {
+ if (g->mlbuf[0] != 0) {
if (!cmd->cb) {
gsmd_log(GSMD_NOTICE, "command without cb!!!\n");
} else {
DEBUGP("Calling cmd->cb()\n");
- cmd->resp = mlbuf;
+ cmd->resp = g->mlbuf;
rc = cmd->cb(cmd, cmd->ctx, cmd->resp);
DEBUGP("Clearing mlbuf\n");
- mlbuf[0] = 0;
+ g->mlbuf[0] = 0;
}
}
@@ -334,16 +332,16 @@
/* we reach here, if we are at an information response that needs to be
* passed on */
- if (mlbuf[0] == 0) {
+ if (g->mlbuf[0] == 0) {
DEBUGP("Filling mlbuf\n");
- strncat(mlbuf, buf, sizeof(mlbuf)-1);
+ strncat(g->mlbuf, buf, MLPARSE_BUF_SIZE-1);
} else {
DEBUGP("Appending buf to mlbuf\n");
- mlbuf_len = strlen(mlbuf);
- if (mlbuf_len+1 < sizeof(mlbuf)) {
- mlbuf[mlbuf_len] = '\n';
- mlbuf[mlbuf_len+1] = '\0';
- strncat(mlbuf, buf, sizeof(mlbuf)-mlbuf_len-2);
+ g->mlbuf_len = strlen(g->mlbuf);
+ if (mlbuf_len+1 < sizeof(g->mlbuf)) {
+ g->mlbuf[g->mlbuf_len] = '\n';
+ g->mlbuf[g->mlbuf_len+1] = '\0';
+ strncat(g->mlbuf, buf, MLPARSE_BUF_SIZE-g->mlbuf_len-2);
} else {
DEBUGP("response too big for mlbuf!!!\n");
return -EFBIG;
@@ -365,13 +363,13 @@
} else {
DEBUGP("Calling final cmd->cb()\n");
/* send final result code if there is no information response in mlbuf */
- if (mlbuf[0] == 0)
+ if (g->mlbuf[0] == 0)
cmd->resp = buf;
else
- cmd->resp = mlbuf;
+ cmd->resp = g->mlbuf;
rc = cmd->cb(cmd, cmd->ctx, cmd->resp);
DEBUGP("Clearing mlbuf\n");
- mlbuf[0] = 0;
+ g->mlbuf[0] = 0;
}
/* remove from list of currently executing cmds */
Index: gsm/src/gsmd/gsmd.c
===================================================================
--- gsm.orig/src/gsmd/gsmd.c 2007-07-31 14:06:47.000000000 +0200
+++ gsm/src/gsmd/gsmd.c 2007-07-31 14:06:50.000000000 +0200
@@ -300,6 +300,10 @@
{
INIT_LLIST_HEAD(&g->users);
+ g->mlbuf = talloc_array(gsmd_tallocs, unsigned char, MLPARSE_BUF_SIZE);
+ if (!g->mlbuf)
+ return -ENOMEM;
+
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mlbuf-in-gsmd-struct.patch
Type: text/x-patch
Size: 3068 bytes
Desc: not available
Url : http://lists.openmoko.org/pipermail/gsmd-devel/attachments/20070731/6e73aad6/mlbuf-in-gsmd-struct.bin
More information about the gsmd-devel
mailing list