Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/06/2016, 06:27
Zunri
 
Fecha de Ingreso: julio-2010
Mensajes: 216
Antigüedad: 13 años, 9 meses
Puntos: 0
mq_send, ERRNO 97. Msg too long.

Hola,

Tengo una aplicación que pide port eclado un entero y lo encola en una cola que previamente se ha abierto. Al hacer el ms_send me obtengo el error de mensaje demasiado largo y no soy capaz de descubrir el problema ya que a simple vista los tamaños parecen correctos.


Código:
#include <stdio.h> 
#include <mqueue.h>
#include <errno.h>

mqd_t queueDescriptor;
#define QUEUE_NAME "/POENK_SENDER_RECEIVER"
#define QUEUE_SIZE 100 /* bytes */

int message;
#define MSG_SIZE   4 


void openQueueForWritting()
{
     struct mq_attr attributes;
     
	 attributes.mq_flags = 0;  /* Only this can be modified at mq_open */
	 attributes.mq_maxmsg = 10;  
	 attributes.mq_msgsize = MSG_SIZE;  
	 attributes.mq_curmsgs = 0; 
        
     queueDescriptor = mq_open(QUEUE_NAME, O_CREAT |O_WRONLY, 0777, &attributes);
     
     if (queueDescriptor < 0)
     {
           printf("\n[ ERROR opening the queue! ]\nError: %d. %s\n", errno, strerror (errno));   
     }
     else
     {
           printf("\n[ Queue opened successfully! ] Descriptor: %d\n", queueDescriptor);
     }
}

void sendMessage()
{   
	 if (0 != mq_send(queueDescriptor,(char *)message, MSG_SIZE, 0)) /* Last value is the priority */
	 {
         printf("\n      [ERROR sending the message]\n      Error: %d. %s\n", errno, strerror (errno));
     }
     else
     {
         printf("\n      [Message sent to the queue]\n");    
     }
}

int main(void)
{
     printf("#########################################\n");
     printf("#                                       #\n");
     printf("#        SENDER process running ...     #\n");
     printf("#                                       #\n");
     printf("#########################################\n");
     
     openQueueForWritting();
      
     while (1)
     {
          printf("\n# Type the integer to transmit: ");
          scanf("%d", &message); 

          sendMessage();
     }
     
     return 0;    
}