Commit 29851c2fa945499ec35b98338173ff37b1f6c5c8

Authored by Stéphane Raimbault
1 parent dcfac5a7

Avoid twice connect() in source code (closes #194)

Showing 1 changed file with 1 additions and 5 deletions
src/modbus-tcp.c
@@ -266,20 +266,16 @@ static int _modbus_tcp_set_ipv4_options(int s) @@ -266,20 +266,16 @@ static int _modbus_tcp_set_ipv4_options(int s)
266 static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen, 266 static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen,
267 const struct timeval *ro_tv) 267 const struct timeval *ro_tv)
268 { 268 {
269 - int rc; 269 + int rc = connect(sockfd, addr, addrlen);
270 270
271 #ifdef OS_WIN32 271 #ifdef OS_WIN32
272 int wsaError = 0; 272 int wsaError = 0;
273 -  
274 - rc = connect(sockfd, addr, addrlen);  
275 if (rc == -1) { 273 if (rc == -1) {
276 wsaError = WSAGetLastError(); 274 wsaError = WSAGetLastError();
277 } 275 }
278 276
279 if (wsaError == WSAEWOULDBLOCK || wsaError == WSAEINPROGRESS) { 277 if (wsaError == WSAEWOULDBLOCK || wsaError == WSAEINPROGRESS) {
280 #else 278 #else
281 -  
282 - rc = connect(sockfd, addr, addrlen);  
283 if (rc == -1 && errno == EINPROGRESS) { 279 if (rc == -1 && errno == EINPROGRESS) {
284 #endif 280 #endif
285 fd_set wset; 281 fd_set wset;