-static int
-receive_message(mqd_t mq,
- struct msg_handler_context_hdr *handler_ctx,
- const msg_handler_t msg_handlers[],
- long mailbox_size, void *mailbox)
-{
- struct timeval now;
- struct timespec timeout;
- ssize_t bytes_received;
- struct unmount_msg_hdr *hdr;
- int ret;
-
- gettimeofday(&now, NULL);
- timeout.tv_sec = now.tv_sec + handler_ctx->timeout_seconds;
- timeout.tv_nsec = now.tv_usec * 1000;
-
- bytes_received = mq_timedreceive(mq, mailbox,
- mailbox_size, NULL, &timeout);
- hdr = mailbox;
- if (bytes_received == -1) {
- if (errno == ETIMEDOUT) {
- ret = WIMLIB_ERR_TIMEOUT;
- } else {
- ERROR_WITH_ERRNO("mq_timedreceive()");
- ret = WIMLIB_ERR_MQUEUE;
- }
- } else if (bytes_received < sizeof(*hdr) ||
- bytes_received != hdr->msg_size) {
- ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- } else if (WIMLIB_VERSION_CODE < hdr->min_version) {
- /*ERROR("Cannot understand the received message. "*/
- /*"Please upgrade wimlib to at least v%d.%d.%d",*/
- /*WIMLIB_GET_MAJOR_VERSION(hdr->min_version),*/
- /*WIMLIB_GET_MINOR_VERSION(hdr->min_version),*/
- /*WIMLIB_GET_PATCH_VERSION(hdr->min_version));*/
- ret = MSG_VERSION_TOO_HIGH;
- } else if (hdr->msg_type >= MSG_TYPE_MAX) {
- ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- } else if (msg_handlers[hdr->msg_type] == NULL) {
- ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- } else {
- ret = msg_handlers[hdr->msg_type](mailbox, handler_ctx);
- }
- return ret;