- MMS client: fixed problem with async connect timeout

pull/93/head
Michael Zillgith 7 years ago
parent ef076efe9f
commit 5ed474a44a

@ -640,8 +640,6 @@ IedConnection_connect(IedConnection self, IedClientError* error, const char* hos
MmsError mmsError;
MmsConnection_setConnectionLostHandler(self->connection, NULL, NULL);
MmsConnection_setConnectTimeout(self->connection, self->connectionTimeout);
if (MmsConnection_connect(self->connection, &mmsError, hostname, tcpPort)) {
@ -672,7 +670,6 @@ IedConnection_connectAsync(IedConnection self, IedClientError* error, const char
MmsError mmsError = MMS_ERROR_NONE;
MmsConnection_setConnectTimeout(self->connection, self->connectionTimeout);
MmsConnection_setConnectionLostHandler(self->connection, NULL, NULL);
MmsConnection_connectAsync(self->connection, &mmsError, hostname, tcpPort);

@ -77,7 +77,7 @@ struct sIsoClientConnection
volatile int state;
Semaphore stateMutex;
uint64_t nextReadTimeout;
uint64_t nextReadTimeout; /* timeout value for read and connect */
Socket socket;
@ -335,7 +335,20 @@ IsoClientConnection_handleConnection(IsoClientConnection self)
nextState = INT_STATE_CLOSE_ON_ERROR;
}
else {
waits = true;
/* check connect timeout */
uint64_t currentTime = Hal_getTimeInMs();
if (currentTime > self->nextReadTimeout) {
IsoClientConnection_releaseTransmitBuffer(self);
self->callback(ISO_IND_ASSOCIATION_FAILED, self->callbackParameter, NULL);
nextState = INT_STATE_CLOSE_ON_ERROR;
}
else {
waits = true;
}
}
}
@ -599,6 +612,13 @@ IsoClientConnection_handleConnection(IsoClientConnection self)
}
break;
default:
if (DEBUG_ISO_CLIENT)
printf("ISO_CLIENT_CONNECTION: Illegal state\n");
break;
}
self->callback(ISO_IND_TICK, self->callbackParameter, NULL);
@ -623,8 +643,6 @@ IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTim
self->socket = TcpSocket_create();
Socket_setConnectTimeout(self->socket, connectTimeoutInMs);
#if (CONFIG_ACTIVATE_TCP_KEEPALIVE == 1)
Socket_activateTcpKeepAlive(self->socket,
CONFIG_TCP_KEEPALIVE_IDLE,
@ -634,6 +652,9 @@ IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTim
setIntState(self, INT_STATE_TCP_CONNECTING);
/* set timeout for connect */
self->nextReadTimeout = Hal_getTimeInMs() + connectTimeoutInMs;
if (Socket_connectAsync(self->socket, self->parameters->hostname, self->parameters->tcpPort) == false) {
Socket_destroy(self->socket);

Loading…
Cancel
Save