Wrong/confusing sample: Custom serializer for struct timeval
Development toolkit for Web Services and XML data bindings for C & C++
Brought to you by:
engelen
/* struct_timeval.h Custom serializer for struct timeval as xsd:dateTime Because time_t (binds to xsd:dateTime) lacks fractional seconds, struct timeval can be used to represent microseconds since 1970-01-01. #import this file into your gSOAP .h file to enable struct timeval serialization and use the serializable xsd__dateTime type. The struct timeval represents dates since 1970-01-01 with microsecond precision: struct timeval { time_t tv_sec; // seconds since Jan. 1, 1970 suseconds_t tv_usec; // and microseconds }; To automate the wsdl2h-mapping of xsd:dateTime to struct timeval, add this line to the typemap.dat file: xsd__dateTime = #import "custom/struct_timeval.h" | xsd__dateTime The typemap.dat file is used by wsdl2h to map types (wsdl2h option -t). When using soapcpp2 option -q<name> or -p<name>, you must change struct_timeval.c as follows: #include "soapH.h" -> #include "nameH.h" Compiler and link your code with struct_timeval.c ... */
Wrong:
struct timeval { time_t tv_sec; // seconds since Jan. 1, 1970 suseconds_t tv_usec; // and microseconds };
Why: https://docs.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-timeval
The timeval structure is used to specify a time interval.
So the whole sample does not make sense at all and leads developers using timeval for DateTime which is not correct, since timeval representing a "time interval" (e.g. timeout) and for this a long (32bit) is enough of course and no Y2K38 issue here!
Use time_t or tm instead! There are already custom serializers here for xsd:DateTime!
I was (a bit) wrong...
timeval taken from "winsock2.h" is wrong, timeval taken from "sys/time.h" is correct. Maybe you add that information (from sys/time.h) to the source header for the struct_timeval serializer, specially for Windows developers ;-)
Thanks
Last edit: hfrmobile 2021-09-10
Since having special requirements (precision of microseconds needed) + code must work under Windows and Linux, I added following to lib\stdsoap2.h:
My custom serializer using soaptimeval (adjusted the timeval serializer accordingly).
I think it is worth to mention that "struct_timeval serializer" can't be "Y2K38 fit" under Windows.