0

I am trying to use the rpc/xdr.h library to develop a simple client/server interaction. I am using the "direct connection", in which the xdr library will receive on the socket and return the translated data:

XDR xdrs_in;
FILE* fstream_in;
fstream_in=fdopen(coonnected_socket, "r");
xdrstdio_create(&xdrs_in, fstream_in, XDR_DECODE);

XDR_data_type a;
xdr_XDR_data_type(&xdrs_in, &a);

With XDR_data_type a type defined and compiled using rpcgen. Supposing that XDR_data_type is really big, and that the other part closes the connection (gracefully or not) during the xdr_XDR_data_type call, will it block waiting for the remaining data? This is a problem that using recv I solve using a SELECT() in order to set a timeout on the waiting time.

I know the most natural answer to this is "try it yourself", but in this way I can't be 100% sure about the behaviour, I can't learn how to solve it, and on the man page I haven't found anything about it.

Thank you for your attention

EDIT

This is the code generated by rpcgen for xdr_XDR_data_type

bool_t
xdr_XDR_data_type (XDR *xdrs, XDR_data_type *objp)
{
    register int32_t *buf;

     if (!xdr_enum (xdrs, (enum_t *) objp))
         return FALSE;
    return TRUE;
}

Yes, it returns a bool_t, but I suppose it depends on the translation itself (i.e. if the integer is a valid integer in the enum mapping), not on the success on receiving or not the data itself.

Tu.Ma.
  • 1,325
  • 10
  • 27
  • Could you please give use code for `xdr_XDR_data_type`? Normally, each `xdr_*type*` function returns a `bool_t` which tells you if IO was ok or not. – Jean-Baptiste Yunès Jun 24 '17 at 09:22
  • I added the code. – Tu.Ma. Jun 24 '17 at 10:04
  • 1
    then FALSE will be returned if data is missing on premature close. – Jean-Baptiste Yunès Jun 24 '17 at 11:39
  • I tested it, and yes it will. But if the client keeps the connection opened, the server will be stuck on waiting until the client closes it. Is there any equivalent to the select function in order to solve this? – Tu.Ma. Jun 24 '17 at 12:40
  • I understand well your problem now (sorry for that). Very good question. I really don't know. It your case I would use some buffering and xdr_decode by myself. I can't see how xdrstdio on non blocking socket and select would fit well (but I can be wrong). – Jean-Baptiste Yunès Jun 24 '17 at 14:17

0 Answers0