|
From: Peter K. <pk...@us...> - 2001-11-27 14:24:12
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bt_ipa.c 1.5 1.6=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* ipa_read() only reads one response at a time now (as it was
supposed to do).
* ipa_write() can now handle EINTR.
The diff of the modified file(s):
--- bt_ipa.c 2001/06/08 09:55:47 1.5
+++ bt_ipa.c 2001/11/27 14:24:09 1.6
@@ -60,6 +60,8 @@
=20
#define D(x) //x
=20
+#define IPA_MSG_MAXSIZE 256
+
int ipa_open(void)
{
int ipa_fd;
@@ -85,46 +87,58 @@
D(syslog(LOG_INFO, __FUNCTION__ ": Sending ipa request (type: %d) len %d=
",
msg->type, msg->len));
=20
- return write(ipa_fd, msg, msg->len + sizeof(struct ipa_msg));
+ while (1)
+ {
+ int len =3D write(ipa_fd, msg, msg->len + sizeof(struct ipa_msg));
+
+ if (len >=3D 0 || errno !=3D EINTR)
+ {
+ return len;
+ }
+ }
}
=20
/* Copies received response into msg */
=20
int ipa_read(int ipa_fd, ipa_msg *msg)
{
- char ipa_buf[256];
- int offset =3D 0, all_read =3D 0, msg_len =3D -1, c;
- ipa_msg *tmp;
+ ipa_msg *tmp =3D NULL;
+ char ipa_buf[IPA_MSG_MAXSIZE];
+ int offset =3D 0;
+ int to_read =3D sizeof *msg;
=20
D(syslog(LOG_INFO, __FUNCTION__ ": Reading response"));
=20
- while (!all_read)
+ while (offset < to_read)
{
- c =3D read(ipa_fd, &ipa_buf+offset, 256-offset);=20=20
+ int c =3D read(ipa_fd, ipa_buf + offset, to_read - offset);
=20
- D(syslog(LOG_INFO, __FUNCTION__ ": Got %d bytes", c));
+ if (c <=3D 0)
+ {
+ if (c < 0 && errno =3D=3D EINTR)
+ {
+ /* Try again */
+ continue;
+ }
=20
- if (c < 0)
return c;
+ }
=20
offset +=3D c;
=20
/* Have we got whole header ? */
- if (offset > sizeof(struct ipa_msg))
+ if (!tmp && offset >=3D sizeof *msg)
{
- tmp =3D (struct ipa_msg*)(ipa_buf);
- msg_len =3D tmp->len;
+ tmp =3D (struct ipa_msg*)ipa_buf;
+ to_read +=3D tmp->len;
}
-=20=20=20=20
- if ((msg_len > 0) && (offset =3D=3D (msg_len + sizeof(struct ipa_msg))=
))
- all_read =3D 1;
}
=20=20=20
- memcpy(msg, ipa_buf, offset);
+ D(syslog(LOG_INFO, __FUNCTION__ ": Read %d bytes", to_read));=20=20
=20
- D(syslog(LOG_INFO, __FUNCTION__ ": Got %d bytes total", offset));
+ memcpy(msg, ipa_buf, offset);
=20
- return msg_len;=20=20
+ return to_read;
}
=20
void show_ipset(struct ip_set* set, int line)
|