Message-ID: Date: Fri, 14 Jan 2022 11:32:05 +0100 MIME-Version: 1.0 Content-Language: en-GB References: <20220113190241.96-1-lstipakov@...277...> From: Arne Schwabe In-Reply-To: <20220113190241.96-1-lstipakov@...277...> Subject: Re: [Openvpn-devel] [PATCH] tun: remove tun_finalize() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit To: Lev Stipakov , "openvpn-devel@lists.sourceforge.net" > > +#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 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. Arne