aqhome-nodes: don't directly delete endpoint when connection goes down.
object should only be deleted outside the loop!
This commit is contained in:
@@ -153,7 +153,7 @@ void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
|
||||
}
|
||||
|
||||
if (_diffInSeconds(now, timeLastConnCheck)>CONNCHECK_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Write time");
|
||||
DBG_ERROR(NULL, "Check connections");
|
||||
AQH_NodeServer_CheckBrokerConnection(aqh);
|
||||
AQH_NodeServer_CheckTtyConnection(aqh);
|
||||
timeLastConnCheck=now;
|
||||
|
||||
@@ -163,6 +163,11 @@ void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
AQH_Object_List_free(xo->ipcClientList);
|
||||
xo->ipcClientList=NULL;
|
||||
}
|
||||
AQH_Object_free(xo->ipcEndpoint);
|
||||
AQH_Object_free(xo->ttyEndpoint);
|
||||
AQH_Object_free(xo->brokerEndpoint);
|
||||
|
||||
AQH_NodeDb_free(xo->nodeDb);
|
||||
free(xo->dbFile);
|
||||
free(xo->logFile);
|
||||
free(xo->pidFile);
|
||||
@@ -549,6 +554,7 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo)
|
||||
DBG_ERROR(NULL, "Error connecting to broker server %s:%d", xo->brokerAddress, xo->brokerPort);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
DBG_ERROR(NULL, "Physically connected to broker server %s:%d", xo->brokerAddress, xo->brokerPort);
|
||||
|
||||
ep=AQH_IpcClientObject_new(AQH_Object_GetEventLoop(o), fd);
|
||||
assert(ep);
|
||||
@@ -588,6 +594,9 @@ void _setupDb(AQH_NODE_SERVER *xo)
|
||||
GWEN_DB_NODE *dbNodeDb;
|
||||
int rv;
|
||||
|
||||
if (xo->nodeDb)
|
||||
AQH_NodeDb_free(xo->nodeDb);
|
||||
xo->nodeDb=AQH_NodeDb_new();
|
||||
dbNodeDb=GWEN_DB_Group_new("dbNodes");
|
||||
rv=GWEN_DB_ReadFile(dbNodeDb, xo->dbFile, GWEN_DB_FLAGS_DEFAULT|GWEN_PATH_FLAGS_CREATE_GROUP);
|
||||
if (rv==0) {
|
||||
@@ -871,7 +880,12 @@ void _publishDouble(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vM
|
||||
AQH_Endpoint_GetNextMessageId(xo->brokerEndpoint), 0,
|
||||
value, arrayToSend, 1);
|
||||
if (pubMsg) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "BROKER PUBLISH %s: %f", AQH_Value_GetName(value), v);
|
||||
DBG_ERROR(AQH_LOGDOMAIN,
|
||||
"BROKER PUBLISH %s(%s/%s): %f",
|
||||
AQH_Value_GetName(value),
|
||||
AQH_Value_GetDeviceName(value),
|
||||
AQH_Value_GetName(value),
|
||||
v);
|
||||
AQH_Endpoint_AddMsgOut(xo->brokerEndpoint, pubMsg);
|
||||
}
|
||||
AQH_Value_free(value);
|
||||
@@ -927,11 +941,20 @@ void AQH_NodeServer_CheckTtyConnection(AQH_OBJECT *o)
|
||||
AQH_NODE_SERVER *xo;
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_NODE_SERVER, o);
|
||||
if (xo && xo->dbArgs) {
|
||||
if (xo) {
|
||||
|
||||
if (xo->ttyEndpoint) {
|
||||
if (AQH_Object_GetFlags(xo->ttyEndpoint) & AQH_OBJECT_FLAGS_DELETE) {
|
||||
DBG_ERROR(NULL, "Deleting TTY connection");
|
||||
AQH_Object_Disable(xo->ttyEndpoint);
|
||||
AQH_Object_free(xo->ttyEndpoint);
|
||||
xo->ttyEndpoint=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (xo->ttyEndpoint==NULL) {
|
||||
time_t now;
|
||||
|
||||
DBG_ERROR(NULL, "TTY closed");
|
||||
now=time(NULL);
|
||||
if (_diffInSeconds(now, xo->timestampBrokerDown)>AQH_NODE_SERVER_TTY_RESTARTTIME) {
|
||||
int rv;
|
||||
@@ -1000,10 +1023,19 @@ void AQH_NodeServer_CheckBrokerConnection(AQH_OBJECT *o)
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_NODE_SERVER, o);
|
||||
if (xo && xo->dbArgs) {
|
||||
|
||||
if (xo->brokerEndpoint) {
|
||||
if (AQH_Object_GetFlags(xo->brokerEndpoint) & AQH_OBJECT_FLAGS_DELETE) {
|
||||
DBG_ERROR(NULL, "Deleting broker connection");
|
||||
AQH_Object_Disable(xo->brokerEndpoint);
|
||||
AQH_Object_free(xo->brokerEndpoint);
|
||||
xo->brokerEndpoint=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (xo->brokerEndpoint==NULL) {
|
||||
time_t now;
|
||||
|
||||
DBG_ERROR(NULL, "Broker connection down");
|
||||
now=time(NULL);
|
||||
if (_diffInSeconds(now, xo->timestampBrokerDown)>AQH_NODE_SERVER_BROKER_RESTARTTIME) {
|
||||
int rv;
|
||||
@@ -1114,9 +1146,8 @@ int _handleIpcClientDown(AQH_OBJECT *clientEndpoint)
|
||||
int _handleBrokerDown(AQH_NODE_SERVER *xo)
|
||||
{
|
||||
if (xo->brokerEndpoint) {
|
||||
AQH_Object_Disable(xo->brokerEndpoint);
|
||||
AQH_Object_free(xo->brokerEndpoint);
|
||||
xo->brokerEndpoint=NULL;
|
||||
DBG_ERROR(NULL, "Broker connection down");
|
||||
AQH_Object_AddFlags(xo->brokerEndpoint, AQH_OBJECT_FLAGS_DELETE);
|
||||
xo->timestampBrokerDown=time(NULL);
|
||||
}
|
||||
return 1;
|
||||
@@ -1127,9 +1158,8 @@ int _handleBrokerDown(AQH_NODE_SERVER *xo)
|
||||
int _handleTtyDown(AQH_NODE_SERVER *xo)
|
||||
{
|
||||
if (xo->ttyEndpoint) {
|
||||
AQH_Object_Disable(xo->ttyEndpoint);
|
||||
AQH_Object_free(xo->ttyEndpoint);
|
||||
xo->ttyEndpoint=NULL;
|
||||
DBG_ERROR(NULL, "TTY closed");
|
||||
AQH_Object_AddFlags(xo->brokerEndpoint, AQH_OBJECT_FLAGS_DELETE);
|
||||
xo->timestampTtyDown=time(NULL);
|
||||
}
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user