GDICommander 54 Posting Whiz in Training

Hello everyone!

I'm having a bad time trying to find a solution to my problem:

I'm developping a client-server application. On the server side, I am calling a method, Recoit (receive), that calls internally msgrcv(), a UNIX system call for message-passing purposes. The problem is that I always receive a "Arg list too long" error message. According to this site, http://publib.boulder.ibm.com/iseries/v5r1/ic2924/index.htm?info/apis/ipcmsgrc.htm, the size of the message I passed to Recoit is too small for the real data size of the message. I really don't know how to solve this problem. This is the necessary code to understand the problem. Note that the error is one the first Recoit call in start().

/**
	\brief Cette fonction part le serveur.
*/
void start(int listenPortNb)
{
	if (listenPortNb == -1)
	{
		std::cout << "You have forget to set a listening port number." << std::endl;
		return;
	}

	int basePortNb = 90000000;
	int offsetValue = 0;

	Port connPort(listenPortNb);
	while (true)
	{
		//Réception de la demande de connexion.
		Message connRequest;
		std::cout << "Message size: " << MSG_SIZE << std::endl;
		connPort.Recoit(&connRequest, MSG_SIZE);		//Attente bloquante.

		std::cout << "The server has received " << connRequest.mtype << std::endl;

		//Traitement de la requête de connexion.
		if (connRequest.mtype == CONN_REQUEST)
		{
			//On décide du numéro du port qui sera utilisé.
			int* connPortNb = (int*) malloc(sizeof(int));
			*connPortNb = basePortNb + offsetValue;		//TODO: Ce sera le thread qui devra libérer la mémoire.
			//Incrémentation de l'offset pour la prochaine connexion.
			++offsetValue;

			//On bâtit le message à retourner au client.
			Message connAnswer;
			connAnswer.mtype = CONN_ANSWER_OK;
			sprintf(connAnswer.data, "%d", *connPortNb);

			std::cout << "The builded port number is: " << connAnswer.data << std::endl;

			//On retourne au client le nouveau numéro de port dans un message.
			connPort.Envoie(&connAnswer, MSG_SIZE);

			std::cout << "After sending the port number on the queue." << std::endl;

			//On augmente le nombre de connexions.

			//On part le thread qui va gérer les demandes de ce client.
			pthread_t connThread;
			threadVector.push_back(&connThread);		//On garde le thread dans un vector au cas où il faut tout arrêter.
			pthread_create(&connThread, 0, connectionFunc, (void*) connPortNb);
		}
	}
}
#define BASE_CONN_PORT 99887766

#define MSG_BUF_SIZE 100
#define MSG_SIZE (sizeof(Message) - sizeof(long int))		//Le message moins l'entier qui dit le type.

#define CONN_REQUEST 1
#define CONN_ANSWER_OK 2
#define CONN_ANSWER_FAIL 3
#define FILE_ADD_REQUEST 4
#define FILE_SEND 5
#define FILE_END 6

struct Message
{
        long int mtype;
		long int dataSize;
        char data[MSG_BUF_SIZE];
};

As you can see, MSG_SIZE is sizeof(Message) - sizeof(long int) to not count the type, so it seems to be ok with the documentation. I saw working examples of messages structures that have other things that a type and a byte array (type + other variables), so I'm out of ideas.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.