[PATCH BlueZ 1/1] isotest: Add check after accepting connection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This checks for the POLLERR event on a newly accepted connection,
to determine if the connection was successful or not.

---
 tools/isotest.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/isotest.c b/tools/isotest.c
index 0eae3cdc1..c71bc6fa0 100644
--- a/tools/isotest.c
+++ b/tools/isotest.c
@@ -33,6 +33,7 @@
 #include <time.h>
 #include <inttypes.h>
 #include <sys/wait.h>
+#include <poll.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -440,6 +441,9 @@ static void do_listen(char *filename, void (*handler)(int fd, int sk),
 	socklen_t optlen;
 	int sk, nsk, fd = -1;
 	char ba[18];
+	struct pollfd fds;
+	int err, sk_err;
+	socklen_t len;
 
 	if (filename) {
 		fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
@@ -529,6 +533,28 @@ static void do_listen(char *filename, void (*handler)(int fd, int sk),
 			goto error;
 		}
 
+		/* Check if connection was successful */
+		memset(&fds, 0, sizeof(fds));
+		fds.fd = nsk;
+		fds.events = POLLERR;
+
+		if (poll(&fds, 1, 0) > 0 && (fds.revents & POLLERR)) {
+			len = sizeof(sk_err);
+
+			if (getsockopt(nsk, SOL_SOCKET, SO_ERROR,
+						&sk_err, &len) < 0)
+				err = -errno;
+			else
+				err = -sk_err;
+
+			if (err < 0)
+				syslog(LOG_ERR, "Connection failed: %s (%d)",
+						strerror(-err), -err);
+
+			close(nsk);
+			continue;
+		}
+
 		if (fork()) {
 			/* Parent */
 			close(nsk);
-- 
2.34.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux