Exemple #1
0
int lsQueueDequeueData_(struct lsQueue *head, char **data)
{
    struct lsQueueEntry *ent = lsQueueDequeue_(head);
    if (ent == NULL) {
	return 0;
    }
    *data = ent->data;
    free(ent);
    return 1;
} 
Exemple #2
0
int
lsMsgRcv_(int taskid, char *buffer, int len, int options)
{
    struct tid *tEnt;
    struct lsQueueEntry *qEnt;
    int rc;

    tEnt = tidFindIgnoreConn_(taskid);
    if (tEnt == NULL)
        return -1;

  Again:
    if (tEnt->isEOF) {
	lserrno = LSE_RES_INVCHILD;
	return -1;
    }

    if (lsMsgRdy_(taskid, NULL)) {
	struct lsTMsgHdr *header;

	qEnt = lsQueueDequeue_(tEnt->tMsgQ);

	if (qEnt == NULL) {
	    lserrno = LSE_MSG_SYS;
	    return -1;
	}

	header = (struct lsTMsgHdr *)qEnt->data;
	if (header->len > len) {
	    lserrno = LSE_MSG_SYS;

	    lsQueueEntryDestroy_(qEnt, tEnt->tMsgQ);
	    return -1;
	}

	if (header->type == LSTMSG_IOERR) {
	    lserrno = LSE_LOSTCON;
	    lsQueueEntryDestroy_(qEnt, tEnt->tMsgQ);
	    return -1;
	} else if (header->type == LSTMSG_EOF) {
	    tEnt->isEOF = TRUE;
	    lsQueueEntryDestroy_(qEnt, tEnt->tMsgQ);
	    return 0;
	}

	memcpy((char *)buffer, (char *)header->msgPtr, header->len);

	rc = header->len;
	lsQueueEntryDestroy_(qEnt, tEnt->tMsgQ);
	return rc;
    } else {
	int nrdy = 0;

	if (tEnt->sock < 0) {
	    lserrno = LSE_LOSTCON;
	    tid_remove(taskid);
	    return -1;
	}
	rc = lsMsgWait_(1, &taskid, &nrdy, 0, NULL, NULL, NULL, NULL, 0);
	if (rc < 0)
	    return rc;

	if (nrdy > 0)
	    goto Again;
	else
	    return -1;
    }
}