From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/4] Add option 'Y' to set socket priority for rctest
Date: Thu, 3 Nov 2011 17:15:38 +0200 [thread overview]
Message-ID: <1320333340-27112-2-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1320333340-27112-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Priority is set using SO_PRIORITY, see man 7 socket for more details.
---
test/rctest.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index 9754f52..b8acfb7 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -85,6 +85,7 @@ static int socktype = SOCK_STREAM;
static int linger = 0;
static int timestamp = 0;
static int defer_setup = 0;
+static int priority = -1;
static float tv2fl(struct timeval tv)
{
@@ -232,9 +233,22 @@ static int do_connect(const char *svr)
//goto error;
}
- syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x]",
- conn.hci_handle,
- conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);
+ if (priority > 0 && setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &priority,
+ sizeof(priority)) < 0) {
+ syslog(LOG_ERR, "Can't set socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
+ if (getsockopt(sk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) {
+ syslog(LOG_ERR, "Can't get socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
+ syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x, "
+ "priority %d]", conn.hci_handle, conn.dev_class[2],
+ conn.dev_class[1], conn.dev_class[0], opt);
return sk;
@@ -298,6 +312,13 @@ static void do_listen(void (*handler)(int sk))
goto error;
}
+ if (priority > 0 && setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &priority,
+ sizeof(priority)) < 0) {
+ syslog(LOG_ERR, "Can't set socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
/* Listen for connections */
if (listen(sk, 10)) {
syslog(LOG_ERR,"Can not listen on the socket: %s (%d)",
@@ -348,10 +369,18 @@ static void do_listen(void (*handler)(int sk))
//goto error;
}
+ optlen = sizeof(priority);
+ if (getsockopt(nsk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) {
+ syslog(LOG_ERR, "Can't get socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
ba2str(&addr.rc_bdaddr, ba);
- syslog(LOG_INFO, "Connect from %s [handle %d, class 0x%02x%02x%02x]",
- ba, conn.hci_handle,
- conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);
+ syslog(LOG_INFO, "Connect from %s [handle %d, "
+ "class 0x%02x%02x%02x, priority %d]",
+ ba, conn.hci_handle, conn.dev_class[2],
+ conn.dev_class[1], conn.dev_class[0], opt);
#if 0
/* Enable SO_TIMESTAMP */
@@ -584,6 +613,7 @@ static void usage(void)
"\t[-N num] number of frames to send\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
+ "\t[-Y priority] socket priority\n"
"\t[-A] request authentication\n"
"\t[-E] request encryption\n"
"\t[-S] secure connection\n"
@@ -598,7 +628,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -701,6 +731,10 @@ int main(int argc, char *argv[])
delay = atoi(optarg) * 1000;
break;
+ case 'Y':
+ priority = atoi(optarg);
+ break;
+
case 'T':
timestamp = 1;
break;
--
1.7.6.4
next prev parent reply other threads:[~2011-11-03 15:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
2011-11-03 15:15 ` Luiz Augusto von Dentz [this message]
2011-11-03 15:15 ` [PATCH BlueZ 3/4] btio: add BT_IO_OPT_PRIORITY option Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 4/4] Add option to set priority for btiotest Luiz Augusto von Dentz
2011-11-04 13:43 ` [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Johan Hedberg
2011-11-04 20:47 ` Marcel Holtmann
2011-11-04 21:38 ` Gustavo Padovan
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=1320333340-27112-2-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).