Fix reloading causing a segfault

This commit is contained in:
Nikki 2015-05-21 17:23:53 -04:00
parent a8fab5f749
commit 13082d892d
2 changed files with 20 additions and 5 deletions

View File

@ -2,10 +2,10 @@
AsyncSocketContext::AsyncSocketContext(IPluginContext* pContext) { AsyncSocketContext::AsyncSocketContext(IPluginContext* pContext) {
this->pContext = pContext; this->pContext = pContext;
connectCallback = forwards->CreateForwardEx(NULL, ET_Single, 1, NULL, Param_Cell); connectCallback = NULL;
errorCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_Cell, Param_String); errorCallback = NULL;
dataCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_String, Param_Cell); dataCallback = NULL;
} }
AsyncSocketContext::~AsyncSocketContext() { AsyncSocketContext::~AsyncSocketContext() {
@ -62,13 +62,28 @@ void AsyncSocketContext::OnData(char* data, ssize_t size) {
} }
bool AsyncSocketContext::SetConnectCallback(funcid_t function) { bool AsyncSocketContext::SetConnectCallback(funcid_t function) {
if (connectCallback) {
forwards->ReleaseForward(connectCallback);
}
connectCallback = forwards->CreateForwardEx(NULL, ET_Single, 1, NULL, Param_Cell);
return connectCallback->AddFunction(pContext, function); return connectCallback->AddFunction(pContext, function);
} }
bool AsyncSocketContext::SetErrorCallback(funcid_t function) { bool AsyncSocketContext::SetErrorCallback(funcid_t function) {
if (connectCallback) {
forwards->ReleaseForward(errorCallback);
}
errorCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_Cell, Param_String);
return errorCallback->AddFunction(pContext, function); return errorCallback->AddFunction(pContext, function);
} }
bool AsyncSocketContext::SetDataCallback(funcid_t function) { bool AsyncSocketContext::SetDataCallback(funcid_t function) {
if (dataCallback) {
forwards->ReleaseForward(dataCallback);
}
dataCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_String, Param_Cell);
return dataCallback->AddFunction(pContext, function); return dataCallback->AddFunction(pContext, function);
} }

View File

@ -72,7 +72,7 @@ AsyncSocketContext* AsyncSocket::GetSocketInstanceByHandle(Handle_t handle) {
void AsyncSocket::OnHandleDestroy(HandleType_t type, void *object) { void AsyncSocket::OnHandleDestroy(HandleType_t type, void *object) {
if(object != NULL) { if(object != NULL) {
AsyncSocketContext *ctx = (AsyncSocketContext *) object; AsyncSocketContext *ctx = (AsyncSocketContext *) object;
UV_EOF;
delete ctx; delete ctx;
} }
} }