> > > char *buffer[1000];
> > > rc = zmq_recv (s, buffer, 1000, 0);
> > >
> > > with the obvious caveat that you will get something like EMSGSIZE back
> if
> > > you gave a 1000 byte buffer, but the next-to-be-received message is
> too
> > > large to be held in that buffer. I.e. no partial recv()s.
>
> recv() returns the number of bytes it filled in the buffer, or 0 (EOF) or
> -1 (error in errno). What is there to guess?
Notice the declaration above should be "char buffer[1000];".
A rather ugly but functional idea would be to return:
* number of bytes received on success;
* 0 on EOF;
* - number of bytes required for a successful receive.
This way you could do the following, if you really wanted to be on the safe
side:
char *buffer;
int size = 0;
// can allocate some memory the first time, or leave it at 0 bytes
int rc = zmq_recv(s, buffer, size, 0);
if (rc < 0) {
size = - rc;
buffer = malloc(size);
rc = zmq_recv(s, buffer, size, 0);
}
...
if (size > 0)
free(buffer);
--
Gonzalo Diethelm
-----------------------------------------
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena.
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje.
"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law.
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message.
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev