73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
#include "libnazgul.h"
|
|
|
|
#define NONBLOCK -1
|
|
|
|
void *msgGet(msgSpace * space, int queueIndex, int option)
|
|
{
|
|
void *resultAddr;
|
|
msgQueueId queueId;
|
|
msgQueue *queue;
|
|
msgQueueElemId oldElemId;
|
|
msgQueueElem *oldElem;
|
|
msgPoolData *poolDataTab;
|
|
// on teste la possibilité de lecture sur la liste...
|
|
if (option == NONBLOCK) {
|
|
if (msgQueueReadTryLock(space->externId, queueIndex) < 0) {
|
|
NZG_ERROR("msgQueueReadTryLock", space->externId);
|
|
goto ERROR;
|
|
}
|
|
} else {
|
|
if (msgQueueReadLock(space->externId, queueIndex) < 0) {
|
|
NZG_ERROR("msgQueueReadLock", space->externId);
|
|
goto ERROR;
|
|
}
|
|
}
|
|
// la lecture est possible
|
|
// on essaye donc de modifier la liste
|
|
msgQueueProtLock(space->externId, queueIndex);
|
|
msgQueueIdIntern(queueId, space->externId, queueIndex);
|
|
// ouvrir la file
|
|
queue = msgQueueOpen(queueId);
|
|
if (queue == NULL) {
|
|
NZG_ERROR("msgQueueOpen", queueId);
|
|
goto ERROR;
|
|
}
|
|
// recupérer l'id de l'ancien element...
|
|
msgQueueRem(queue, oldElemId);
|
|
|
|
oldElem = msgQueueElemOpen(oldElemId);
|
|
if (oldElem == NULL) {
|
|
NZG_ERROR("msgQueueElemOpen", oldElemId);
|
|
goto ERROR;
|
|
}
|
|
/* on récupere la taille des buffer dans la pool du buffer */
|
|
poolDataTab = msgPoolDataTabOpen(space);
|
|
// mapper le buffer dans l'espace mémoire du processus
|
|
resultAddr =
|
|
msgBufferMap(poolDataTab, oldElem->poolIndex, oldElem->bufferIndex);
|
|
// attacher au buffer...
|
|
if (msgBufferAttachProc(poolDataTab,
|
|
oldElem->poolIndex,
|
|
oldElem->bufferIndex, resultAddr) < 0) {
|
|
NZG_ERROR("msgBufferAttachProc", oldElemId);
|
|
goto ERROR;
|
|
}
|
|
|
|
msgPoolDataTabClose(space, poolDataTab);
|
|
if (msgQueueElemClose(oldElem) < 0) {
|
|
NZG_ERROR("msgQueueElemClose", oldElemId);
|
|
}
|
|
|
|
shm_unlink(oldElemId);
|
|
|
|
// fermer la file
|
|
msgQueueClose(queue);
|
|
|
|
// on a fini de modifier la liste
|
|
msgQueueProtUnlock(space->externId, queueIndex);
|
|
|
|
return resultAddr;
|
|
ERROR:
|
|
return NULL;
|
|
}
|