summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-05-21 19:02:05 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2013-05-21 19:02:05 +0200
commite01ae35ca5c40dd191bb4aa049698b940b54c116 (patch)
treec0d7f30f97f90621aacf0065df50c11efffe3a79 /plugins
parent6c0e2966d82588017185b2d02d17178f4743531e (diff)
downloadneard-e01ae35ca5c40dd191bb4aa049698b940b54c116.tar.gz
neard-e01ae35ca5c40dd191bb4aa049698b940b54c116.tar.bz2
neard-e01ae35ca5c40dd191bb4aa049698b940b54c116.zip
p2p: Set connection timeout
The connect() call should not block forever. The 8 seconds timeout makes it for approximately 3 times the maximum LTO and that seems to be plenty of time for a peer to reply to an LLCP connection.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/p2p.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/plugins/p2p.c b/plugins/p2p.c
index 88e0ff8..bf90ee8 100644
--- a/plugins/p2p.c
+++ b/plugins/p2p.c
@@ -344,6 +344,7 @@ static int p2p_connect(uint32_t adapter_idx, uint32_t target_idx,
near_device_io_cb cb, struct near_p2p_driver *driver)
{
int fd, err = 0;
+ struct timeval timeout;
struct sockaddr_nfc_llcp addr;
DBG("");
@@ -360,6 +361,17 @@ static int p2p_connect(uint32_t adapter_idx, uint32_t target_idx,
addr.service_name_len = strlen(driver->service_name);
strcpy(addr.service_name, driver->service_name);
+ timeout.tv_sec = 8;
+ timeout.tv_usec = 0;
+
+ if (setsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
+ sizeof(timeout)) < 0)
+ near_error("Could not set the receive timeout\n");
+
+ if (setsockopt (fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,
+ sizeof(timeout)) < 0)
+ near_error("Could not set the send timeout\n");
+
err = connect(fd, (struct sockaddr *) &addr,
sizeof(struct sockaddr_nfc_llcp));
if (err < 0) {