Hi,

On 14/01/2022 11:32, Arne Schwabe wrote:

+#define SocketHandleGetOverlappedResult(sh, io) (sh.is_handle ? \
+    GetOverlappedResult(sh.h, io->overlapped, io->size, FALSE) : \
+    WSAGetOverlappedResult(sh.s, io->overlapped, io->size, FALSE, io->flags))
+
+#define SocketHandleGetLastError(sh) (sh.is_handle ? \
+    GetLastError() : WSAGetLastError())
+
+#define SocketHandleSetLastError(sh, ...) (sh.is_handle ? \
+    SetLastError(__VA_ARGS__) : WSASetLastError(__VA_ARGS__))
+
+#define SocketHandleSetInvalError(sh) (sh.is_handle ? \
+    SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL))
+

I think macros are just way simpler at handling varargs, as you just use ... and __VA_ARGS__ in the code.


I would prefer small static inline functions here. With modern compilers they get inlined and are nicer than these macros.



  #else  /* ifdef _WIN32 */
  #define openvpn_close_socket(s) close(s)
@@ -1020,7 +1041,8 @@ link_socket_read_udp_win32(struct link_socket *sock,
                             struct buffer *buf,
                             struct link_socket_actual *from)
  {
-    return socket_finalize(sock->sd, &sock->reads, buf, from);
+    sockethandle_t sh = { .s = sock->sd };

It would be good to explicitly have is_handle = false here. Otherwise we rely on implicit zero initialisation, which I am not sure is guaranteed and it also is better for documentation.

I agree here - especially on the documentation bit.

Cheers,


Arne


_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


--
Antonio Quartulli


_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to