summaryrefslogtreecommitdiff
path: root/src/timeoutconn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeoutconn.c')
-rw-r--r--src/timeoutconn.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/timeoutconn.c b/src/timeoutconn.c
index c94f600..714faef 100644
--- a/src/timeoutconn.c
+++ b/src/timeoutconn.c
@@ -1,9 +1,10 @@
-#include "ndelay.h"
-#include "socket_if.h"
-#include "iopause.h"
-#include "error.h"
#include "timeoutconn.h"
+
+#include "error.h"
+#include "iopause.h"
#include "ip.h"
+#include "ndelay.h"
+#include "socket_if.h"
/**
@file timeoutconn.c
@@ -12,25 +13,25 @@
@brief socket read/write timeout handling; return code of iopause considered
*/
-int timeoutconn4(int s,char ip[4],uint16 port,unsigned int timeout)
+int timeoutconn4(int s, char ip[4], uint16 port, unsigned int timeout)
{
struct taia now;
struct taia deadline;
iopause_fd x;
unsigned int p = 0;
- if (socket_connect4(s,ip,port) == -1) {
+ if (socket_connect4(s, ip, port) == -1) {
if ((errno != EWOULDBLOCK) && (errno != EINPROGRESS)) return -1;
x.fd = s;
x.events = IOPAUSE_WRITE;
taia_now(&now);
- taia_uint(&deadline,timeout);
- taia_add(&deadline,&now,&deadline);
+ taia_uint(&deadline, timeout);
+ taia_add(&deadline, &now, &deadline);
for (;;) {
taia_now(&now);
- iopause(&x,1,&deadline,&now);
- if (x.revents) break; /* 's' available */
- if (taia_less(&deadline,&now)) {
+ iopause(&x, 1, &deadline, &now);
+ if (x.revents) break; /* 's' available */
+ if (taia_less(&deadline, &now)) {
errno = ETIMEDOUT; /* note that connect attempt is continuing */
return -1;
}
@@ -43,25 +44,25 @@ int timeoutconn4(int s,char ip[4],uint16 port,unsigned int timeout)
return 0;
}
-int timeoutconn6(int s,char ip[16],uint16 port,unsigned int timeout,uint32 netif)
+int timeoutconn6(int s, char ip[16], uint16 port, unsigned int timeout, uint32 netif)
{
struct taia now;
struct taia deadline;
iopause_fd x;
unsigned int p = 0;
- if (socket_connect6(s,ip,port,netif) == -1) {
+ if (socket_connect6(s, ip, port, netif) == -1) {
if ((errno != EWOULDBLOCK) && (errno != EINPROGRESS)) return -1;
x.fd = s;
x.events = IOPAUSE_WRITE;
taia_now(&now);
- taia_uint(&deadline,timeout);
- taia_add(&deadline,&now,&deadline);
+ taia_uint(&deadline, timeout);
+ taia_add(&deadline, &now, &deadline);
for (;;) {
taia_now(&now);
- iopause(&x,1,&deadline,&now);
- if (x.revents) break; /* 's' available */
- if (taia_less(&deadline,&now)) {
+ iopause(&x, 1, &deadline, &now);
+ if (x.revents) break; /* 's' available */
+ if (taia_less(&deadline, &now)) {
errno = ETIMEDOUT; /* note that connect attempt is continuing */
return -1;
}
@@ -74,7 +75,7 @@ int timeoutconn6(int s,char ip[16],uint16 port,unsigned int timeout,uint32 netif
return 0;
}
-int timeoutconn(int s,char ip[16],uint16 port,unsigned int timeout,uint32 netif)
+int timeoutconn(int s, char ip[16], uint16 port, unsigned int timeout, uint32 netif)
{
struct taia now;
struct taia deadline;
@@ -82,23 +83,23 @@ int timeoutconn(int s,char ip[16],uint16 port,unsigned int timeout,uint32 netif)
unsigned int p = 0;
int r;
- if (ip6_isv4mapped(ip))
- r = socket_connect4(s,ip + 12,port);
+ if (ip6_isv4mapped(ip))
+ r = socket_connect4(s, ip + 12, port);
else
- r = socket_connect6(s,ip,port,netif);
+ r = socket_connect6(s, ip, port, netif);
if (r == -1) {
if ((errno != EWOULDBLOCK) && (errno != EINPROGRESS)) return -1;
x.fd = s;
x.events = IOPAUSE_WRITE;
taia_now(&now);
- taia_uint(&deadline,timeout);
- taia_add(&deadline,&now,&deadline);
+ taia_uint(&deadline, timeout);
+ taia_add(&deadline, &now, &deadline);
for (;;) {
taia_now(&now);
- iopause(&x,1,&deadline,&now);
- if (x.revents) break; /* 's' available */
- if (taia_less(&deadline,&now)) {
+ iopause(&x, 1, &deadline, &now);
+ if (x.revents) break; /* 's' available */
+ if (taia_less(&deadline, &now)) {
errno = ETIMEDOUT; /* note that connect attempt is continuing */
return -1;
}