All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Radoslaw Jablonski <ext-jablonski.radoslaw@nokia.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Add support for sending small data through obex
Date: Tue, 2 Nov 2010 01:01:18 +0200	[thread overview]
Message-ID: <AANLkTinqFDsMUW=uuyMicgVMw2B3A-Pkr1H5_B3_dh25@mail.gmail.com> (raw)
In-Reply-To: <1288603499-16456-1-git-send-email-ext-jablonski.radoslaw@nokia.com>

Hi,

On Mon, Nov 1, 2010 at 11:24 AM, Radoslaw Jablonski
<ext-jablonski.radoslaw@nokia.com> wrote:
> Added handling packets smaller than mtu in obex_write_stream. Now trying
> to read from source until mtu will be filled properly and not sending
> immediately data if it is smaller than mtu.
> ---
>  src/obex.c |   48 +++++++++++++++++++++++++++++++++++++-----------
>  1 files changed, 37 insertions(+), 11 deletions(-)
>
> diff --git a/src/obex.c b/src/obex.c
> index 6d4430d..d3a6ccd 100644
> --- a/src/obex.c
> +++ b/src/obex.c
> @@ -623,6 +623,7 @@ static int obex_write_stream(struct obex_session *os,
>        obex_headerdata_t hd;
>        uint8_t *ptr;
>        ssize_t len;
> +       ssize_t r_len;

You can have len and r_len in the same line above.

>        unsigned int flags;
>        uint8_t hi;
>
> @@ -642,18 +643,37 @@ static int obex_write_stream(struct obex_session *os,
>                goto add_header;
>        }
>
> -       len = os->driver->read(os->object, os->buf, os->tx_mtu, &hi);
> -       if (len < 0) {
> -               error("read(): %s (%zd)", strerror(-len), -len);
> -               if (len == -EAGAIN)
> -                       return len;
> -               else if (len == -ENOSTR)
> -                       return 0;
> +       /* Copying data from source until we reach end of the stream. Sending
> +        * data only if MTU will be filled in 100% or we reach end of data.
> +        * Remaining data in buffer will be sent with next amount of data
> +        * from source.*/
> +       do {
> +               r_len = os->driver->read(os->object, os->buf + os->pending,
> +                                       os->tx_mtu - os->pending, &hi);

It looks like you should add one more tab in the line above it that
doesn't go over 80 columns.

> +               if (r_len < 0) {
> +                       error("read(): %s (%zd)", strerror(-r_len), -r_len);
> +
> +                       switch(r_len) {
> +                       case -EAGAIN:
> +                               return r_len;
> +                       case -EINTR:
> +                               continue;
> +                       case -ENOSTR:
> +                               return 0;
> +                       default:
> +                               g_free(os->buf);
> +                               os->buf = NULL;
> +                               return r_len;
> +                       }
> +               }

I think it is probably more efficiently to handle rlen == 0 here, like
if (rlen == 0) break; else if (rlen < 0)

> -               g_free(os->buf);
> -               os->buf = NULL;
> -               return len;
> -       }
> +               /* Saving amount of data accumulated in obex buffer */
> +               os->pending += r_len;
> +       } while (os->pending < os->tx_mtu && r_len != 0);

That simplify here too, just do while (os->pending < os->txt_mtu) if
you handle rlen == 0 like I said before.

> +
> +       len = os->pending;
> +       os->pending = 0;
>
>        ptr = os->buf;
>
> @@ -702,6 +722,12 @@ static gboolean handle_async_io(void *object, int flags, int err,
>                ret = obex_read_stream(os, os->obex, os->obj);
>
>  proceed:
> +
> +       /* Returning TRUE to not delete current watcher - it need to be active
> +        * to handle next io flag changes (more data will be available later)*/
> +       if (ret == -EAGAIN)
> +               return TRUE;
> +
>        if (ret < 0) {
>                os_set_response(os->obj, err);
>                OBEX_CancelRequest(os->obex, TRUE);
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>



-- 
Luiz Augusto von Dentz
Computer Engineer

      reply	other threads:[~2010-11-01 23:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-01  9:24 [PATCH] Add support for sending small data through obex Radoslaw Jablonski
2010-11-01 23:01 ` Luiz Augusto von Dentz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTinqFDsMUW=uuyMicgVMw2B3A-Pkr1H5_B3_dh25@mail.gmail.com' \
    --to=luiz.dentz@gmail.com \
    --cc=ext-jablonski.radoslaw@nokia.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.