Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
fc737e08
Commit
fc737e08
authored
Feb 14, 2019
by
boarchuz
Committed by
Me No Dev
Feb 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add connect timeout to WiFiClient (#2383)
* Add timeout to WiFiClient.connect() * Changed default handling
parent
e302a684
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
libraries/WiFi/src/WiFiClient.cpp
libraries/WiFi/src/WiFiClient.cpp
+22
-4
libraries/WiFi/src/WiFiClient.h
libraries/WiFi/src/WiFiClient.h
+2
-0
No files found.
libraries/WiFi/src/WiFiClient.cpp
View file @
fc737e08
...
...
@@ -202,12 +202,17 @@ void WiFiClient::stop()
}
int
WiFiClient
::
connect
(
IPAddress
ip
,
uint16_t
port
)
{
return
connect
(
ip
,
port
,
-
1
);
}
int
WiFiClient
::
connect
(
IPAddress
ip
,
uint16_t
port
,
int32_t
timeout
)
{
int
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
sockfd
<
0
)
{
log_e
(
"socket: %d"
,
errno
);
return
0
;
}
fcntl
(
sockfd
,
F_SETFL
,
fcntl
(
sockfd
,
F_GETFL
,
0
)
|
O_NONBLOCK
);
uint32_t
ip_addr
=
ip
;
struct
sockaddr_in
serveraddr
;
...
...
@@ -215,12 +220,21 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
serveraddr
.
sin_family
=
AF_INET
;
bcopy
((
const
void
*
)(
&
ip_addr
),
(
void
*
)
&
serveraddr
.
sin_addr
.
s_addr
,
4
);
serveraddr
.
sin_port
=
htons
(
port
);
int
res
=
lwip_connect_r
(
sockfd
,
(
struct
sockaddr
*
)
&
serveraddr
,
sizeof
(
serveraddr
));
if
(
res
<
0
)
{
log_e
(
"lwip_connect_r: %d"
,
errno
);
fd_set
fdset
;
struct
timeval
tv
;
FD_ZERO
(
&
fdset
);
FD_SET
(
sockfd
,
&
fdset
);
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
timeout
*
1000
;
lwip_connect_r
(
sockfd
,
(
struct
sockaddr
*
)
&
serveraddr
,
sizeof
(
serveraddr
));
int
res
=
select
(
sockfd
+
1
,
nullptr
,
&
fdset
,
nullptr
,
timeout
<
0
?
nullptr
:
&
tv
);
if
(
res
!=
1
)
{
log_e
(
"select: %d"
,
errno
);
close
(
sockfd
);
return
0
;
}
fcntl
(
sockfd
,
F_SETFL
,
fcntl
(
sockfd
,
F_GETFL
,
0
)
&
(
~
O_NONBLOCK
)
);
clientSocketHandle
.
reset
(
new
WiFiClientSocketHandle
(
sockfd
));
_rxBuffer
.
reset
(
new
WiFiClientRxBuffer
(
sockfd
));
_connected
=
true
;
...
...
@@ -228,12 +242,16 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
}
int
WiFiClient
::
connect
(
const
char
*
host
,
uint16_t
port
)
{
return
connect
(
host
,
port
,
-
1
);
}
int
WiFiClient
::
connect
(
const
char
*
host
,
uint16_t
port
,
int32_t
timeout
)
{
IPAddress
srv
((
uint32_t
)
0
);
if
(
!
WiFiGenericClass
::
hostByName
(
host
,
srv
)){
return
0
;
}
return
connect
(
srv
,
port
);
return
connect
(
srv
,
port
,
timeout
);
}
int
WiFiClient
::
setSocketOption
(
int
option
,
char
*
value
,
size_t
len
)
...
...
libraries/WiFi/src/WiFiClient.h
View file @
fc737e08
...
...
@@ -41,7 +41,9 @@ public:
WiFiClient
(
int
fd
);
~
WiFiClient
();
int
connect
(
IPAddress
ip
,
uint16_t
port
);
int
connect
(
IPAddress
ip
,
uint16_t
port
,
int32_t
timeout
);
int
connect
(
const
char
*
host
,
uint16_t
port
);
int
connect
(
const
char
*
host
,
uint16_t
port
,
int32_t
timeout
);
size_t
write
(
uint8_t
data
);
size_t
write
(
const
uint8_t
*
buf
,
size_t
size
);
size_t
write_P
(
PGM_P
buf
,
size_t
size
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment