summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Krasnyansky <maxk@qualcomm.com>2003-05-19 21:04:25 +0000
committerMax Krasnyansky <maxk@qualcomm.com>2003-05-19 21:04:25 +0000
commit893ddcab14bb2b5309ba0f181a5a9941a2d28661 (patch)
tree63a47bb64508fc21641e9a793a3aa3986a83d2fc
parentd68d01e1d2aecd2326cbc7dc0a8ec77ce30a1b02 (diff)
Call shutdown() before closing the socket and check return value.
This is used along with SO_LINGER option to check for errors during cahnel close. Minor cleanups.
-rw-r--r--test/l2test.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/test/l2test.c b/test/l2test.c
index fa8cdf5e..a502d7dc 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -71,8 +71,8 @@ long data_size = 672;
bdaddr_t bdaddr;
unsigned short psm = 10;
-/* Default number of blocks to send */
-int num_blocks = -1; // Infinite
+/* Default number of frames to send */
+int num_frames = -1; // Infinite
int master = 0;
int auth = 0;
@@ -251,7 +251,7 @@ void do_listen( void (*handler)(int sk) )
handler(s1);
- syslog(LOG_INFO, "Disconnect\n");
+ syslog(LOG_INFO, "Disconnect. %m\n");
exit(0);
}
}
@@ -342,13 +342,13 @@ void send_mode(int s)
uint32_t seq;
int i;
- syslog(LOG_INFO,"Sending ...");
+ syslog(LOG_INFO, "Sending ...");
for(i=6; i < data_size; i++)
buf[i]=0x7f;
seq = 0;
- while ((num_blocks == -1) || (num_blocks-- > 0)) {
+ while ((num_frames == -1) || (num_frames-- > 0)) {
*(uint32_t *) buf = htobl(seq++);
*(uint16_t *)(buf+4) = htobs(data_size);
@@ -357,6 +357,12 @@ void send_mode(int s)
exit(1);
}
}
+
+ syslog(LOG_INFO, "Closing channel ...");
+ if (shutdown(s, SHUT_RDWR) < 0)
+ syslog(LOG_INFO, "Close failed. %m.");
+ else
+ syslog(LOG_INFO, "Done");
}
void reconnect_mode(char *svr)
@@ -410,7 +416,7 @@ void usage(void)
printf("Options:\n"
"\t[-b bytes] [-S bdaddr] [-P psm]\n"
"\t[-I imtu] [-O omtu]\n"
- "\t[-N num] send num blocks (default = infinite)\n"
+ "\t[-N num] send num frames (default = infinite)\n"
"\t[-L seconds] enable SO_LINGER\n"
"\t[-D] use connectionless channel (datagram)\n"
"\t[-A] request authentication\n"
@@ -508,7 +514,7 @@ int main(int argc ,char *argv[])
break;
case 'N':
- num_blocks = atoi(optarg);
+ num_frames = atoi(optarg);
break;
default: