/* Removes a planet from linkedlist and deallocates its memory a message will be sent to the client that created the planet with the reason of termination. */ int killPlanet(planet_type *planet, int flag) { char clientMailslotName[256], mailSlotString[18] = "\\\\.\\mailslot\\", procIDString[30]; HANDLE clientMailslot; serverMessage message; if (planetExists(planet)) { wsprintf(clientMailslotName, "\\\\.\\mailslot\\%s", planet->pid); //Generate clientMailSlotName clientMailslot = mailslotConnect(clientMailslotName); if (clientMailslot == INVALID_HANDLE_VALUE) { MessageBox(0, "Failed to get a handle to the client mailslot!!!", "", 1); return; } strcpy_s(message.name, sizeof(planet->name), planet->name); if (removeNode(planet)) { // Send Message to client: Planet removed message.error = flag; mailslotWrite(clientMailslot, (void *)&message, sizeof(serverMessage)); return 1; } //LeaveCriticalSection(&dbAccess); } else return 0; }
void sendErrorToCreator(planet_type *planet, int flag) { char clientMailslotName[256], mailSlotString[18] = "\\\\.\\mailslot\\", procIDString[30]; HANDLE clientMailslot; serverMessage message; wsprintf(clientMailslotName, "\\\\.\\mailslot\\%s", planet->pid); //Generate clientMailSlotName clientMailslot = mailslotConnect(clientMailslotName); if (clientMailslot == INVALID_HANDLE_VALUE) { MessageBox(0, "Failed to get a handle to the client mailslot!!!", "", 1); return; } strcpy_s(message.name, sizeof(planet->name), planet->name); // Send Message to client: Planet removed message.error = flag; mailslotWrite(clientMailslot, (void *)&message, sizeof(serverMessage)); }
void deletePlanet(planet_type *planetToRemove, char *deleteMessage) { planet_type *prev = database; char mailslotName[128]; sprintf(mailslotName, "\\\\.\\mailslot\\%s", planetToRemove->pid); EnterCriticalSection(&criticalSection); planet_type *traverser = database; while (traverser != planetToRemove) { prev = traverser; traverser = traverser->next; } prev->next = planetToRemove->next; //If the planet to remove is the root-planet if (traverser == database) database = traverser->next; traverser->next = NULL; free(traverser); LeaveCriticalSection(&criticalSection); HANDLE mail = mailslotConnect(mailslotName); mailslotWrite(mail, deleteMessage, 4); mailslotClose(mail); }