minor refactoring
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 10 Nov 2017 12:05:46 +0000 (14:05 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 10 Nov 2017 12:05:46 +0000 (14:05 +0200)
src/server/include/nxsrvapi.h
src/server/libnxsrv/agent.cpp

index 5d8a8a5..82fefd9 100644 (file)
@@ -603,7 +603,7 @@ public:
    void setPort(WORD wPort) { m_wPort = wPort; }
    void setAuthData(int method, const TCHAR *secret);
    void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; }
-   bool cancelFileDownload();
+   UINT32 cancelFileDownload();
 };
 
 /**
index 82e8b51..bacbc46 100644 (file)
@@ -2112,28 +2112,32 @@ NXCPMessage *AgentConnection::customRequest(NXCPMessage *pRequest, const TCHAR *
 }
 
 /**
- * Send custom request to agent
+ * Cancel file download
  */
-bool AgentConnection::cancelFileDownload()
+UINT32 AgentConnection::cancelFileDownload()
 {
-   UINT32 dwRqId, rcc;
-   NXCPMessage msg(getProtocolVersion());
-   dwRqId = generateRequestId();
-   msg.setId(dwRqId);
-   msg.setCode(CMD_CANCEL_FILE_DOWNLOAD);
+   NXCPMessage msg(CMD_CANCEL_FILE_DOWNLOAD, generateRequestId(), getProtocolVersion());
    msg.setField(VID_REQUEST_ID, m_dwDownloadRequestId);
-   bool success = false;
 
+   UINT32 rcc;
    if (sendMessage(&msg))
    {
-      NXCPMessage *result = waitForMessage(CMD_REQUEST_COMPLETED, dwRqId, m_dwCommandTimeout);
-      if(result != NULL && result->getFieldAsUInt32(VID_RCC) == ERR_SUCCESS)
+      NXCPMessage *result = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId(), m_dwCommandTimeout);
+      if (result != NULL)
       {
-         success = true;
+         rcc = result->getFieldAsUInt32(VID_RCC);
+         delete result;
+      }
+      else
+      {
+         rcc = ERR_REQUEST_TIMEOUT;
       }
-      delete result;
    }
-   return success;
+   else
+   {
+      rcc = ERR_CONNECTION_BROKEN;
+   }
+   return rcc;
 }
 
 /**