summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Krasnyansky <maxk@qualcomm.com>2003-05-17 00:45:58 +0000
committerMax Krasnyansky <maxk@qualcomm.com>2003-05-17 00:45:58 +0000
commit79cc4e4e2d74be3f1445203b1fdb844caa1cb009 (patch)
tree06b980cae370407285057c884a5febc4e7307c14
parent33a6d8d6bc6bf30a37a92ef40353e6426beeb59b (diff)
Add SO_LINGER support.
-rw-r--r--test/l2test.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/test/l2test.c b/test/l2test.c
index c345d06a8..fa8cdf5e6 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -78,6 +78,7 @@ int master = 0;
int auth = 0;
int encrypt = 0;
int socktype = SOCK_SEQPACKET;
+int linger = 0;
float tv2fl(struct timeval tv)
{
@@ -118,6 +119,16 @@ int do_connect(char *svr)
return -1;
}
+ /* Enable SO_LINGER */
+ if (linger) {
+ struct linger l = { .l_onoff = 1, .l_linger = linger };
+ if (setsockopt(s, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) {
+ syslog(LOG_ERR, "Can't enable SO_LINGER. %s(%d)",
+ strerror(errno), errno);
+ return -1;
+ }
+ }
+
memset(&rem_addr, 0, sizeof(rem_addr));
rem_addr.l2_family = AF_BLUETOOTH;
baswap(&rem_addr.l2_bdaddr, strtoba(svr));
@@ -228,6 +239,16 @@ void do_listen( void (*handler)(int sk) )
syslog(LOG_INFO, "Connect from %s [imtu %d, omtu %d, flush_to %d]\n",
batostr(&ba), opts.imtu, opts.omtu, opts.flush_to);
+ /* Enable SO_LINGER */
+ if (linger) {
+ struct linger l = { .l_onoff = 1, .l_linger = linger };
+ if (setsockopt(s, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) {
+ syslog(LOG_ERR, "Can't enable SO_LINGER. %s(%d)",
+ strerror(errno), errno);
+ exit(1);
+ }
+ }
+
handler(s1);
syslog(LOG_INFO, "Disconnect\n");
@@ -390,6 +411,7 @@ void usage(void)
"\t[-b bytes] [-S bdaddr] [-P psm]\n"
"\t[-I imtu] [-O omtu]\n"
"\t[-N num] send num blocks (default = infinite)\n"
+ "\t[-L seconds] enable SO_LINGER\n"
"\t[-D] use connectionless channel (datagram)\n"
"\t[-A] request authentication\n"
"\t[-E] request encryption\n"
@@ -406,7 +428,7 @@ int main(int argc ,char *argv[])
mode = RECV; need_addr = 0;
- while ((opt=getopt(argc,argv,"rdscuwmnb:P:I:O:S:N:MAED")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnb:P:I:O:S:N:MAEDL:")) != EOF) {
switch(opt) {
case 'r':
mode = RECV;
@@ -465,6 +487,10 @@ int main(int argc ,char *argv[])
omtu = atoi(optarg);
break;
+ case 'L':
+ linger = atoi(optarg);
+ break;
+
case 'M':
master = 1;
break;