Sorry, accidentally hit send before I was done writing. Continuing:
> + DWORD bytesSent = 0;
Not to bikeshed style, but being consistent within the same code would at least be appreciated. (And in new code we tend to avoid camel case.)
> + s = socket(AF_INET, SOCK_DGRAM, 0);
Let's explicitly use IPPROTO_UDP here, please. It's also possible to create raw or ICMP DGRAM sockets, for which sending to port zero actually does something.
> + todo_wine ok(bytesSent == sizeof(buf), "Failed to send full data(%lu) only sent(%lu)\n", (unsigned long) sizeof(buf), (unsigned long) bytesSent);
No need to cast; you can use %Iu for expressions of type size_t, and %lu for DWORD.
From patch 2/2:
> +static int is_port0( const union unix_sockaddr *uaddr)
This returns BOOL.
> +{
> + switch (uaddr->addr.sa_family)
> + {
> + case AF_INET:
> + {
> + return uaddr->in.sin_port == 0;
> + }
> +
> + case AF_INET6:
> + {
> + return uaddr->in6.sin6_port == 0;
> + }
> +
No need for these braces.
> + #ifdef HAS_IPX
> + case AF_IPX:
> + {
> + return uaddr->ipx.sipx_port == 0;
> + }
> + #endif
Is this right? Unless we can confirm it's correct I'd leave this out.
> +
> + #ifdef HAS_IRDA
> + case AF_IRDA:
> + {
> + return FALSE;
> + }
> + #endif
> +
> + case AF_UNSPEC:
> + return FALSE;
There's no need for these; the default case already covers this.
> +
> + default:
> + return FALSE;
> + }
> +}
> @@ -1018,6 +1053,7 @@ static NTSTATUS try_send( int fd, struct async_send_ioctl *async )
> hdr.msg_iov = async->iov + async->iov_cursor;
> hdr.msg_iovlen = async->count - async->iov_cursor;
>
> +
> while ((ret = sendmsg( fd, &hdr, async->unix_flags )) == -1)
> {
> if (errno == EISCONN)
Spurious whitespace change here.
> @@ -1028,7 +1064,24 @@ static NTSTATUS try_send( int fd, struct async_send_ioctl *async )
> else if (errno != EINTR)
> {
> if (errno != EWOULDBLOCK) WARN( "sendmsg: %s\n", strerror( errno ) );
> - return sock_errno_to_status( errno );
> +
> + if(errno == EINVAL && is_port0(&unix_addr)){
> +
> + /*
> + * Some Windows applications(Spellforce 3 is known to) send to port 0.
> + * This causes 'sendmsg' to throw a EINVAL error on Windows this does nothing but consume the data.
> + * This workaround says we successfully sent data even though we didnt send anything.
> + * Matching the Windows behaviour, making the program work(in theory).
> + */
Comment spacing is mangled here.
> + ret = 0;
> + for(ssize_t i = 0; i < hdr.msg_iovlen; i++){
> + ret += hdr.msg_iov[i].iov_len;
> + }
> + WARN("Attempting to send to port 0, skipping over %zd bytes\n", ret);
> + break;
> + }else{
> + return sock_errno_to_status( errno );
> + }
> }
This works, but I'm not sure it's the place we want to handle this. For one thing, I'm not sure all platforms are going to return EINVAL here.
Probably better is to either handle it in try_send() before sending, or handle it in sock_send() in about the same place. (I think it'd need to be after the server call, though I haven't properly checked whether the server needs to do anything important here.) Note that you'll also explicitly want to check the protocol here in that case, so we only catch UDP sockets with this logic.
Also, please try to match the surrounding code style wrt things like brace placement and spacing.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/2100#note_23505
The prefix of patch 1/2 should be changed to "ws2_32/tests". The subject is not quite a grammatical sentence; I'd just write "Check if sending to port 0 succeeds."
> + char buf[12] = "hello world";
No reason to specify the buffer size; you can just write "char buf[]".
> + DWORD bytesSent = 0;
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/2100#note_23489
QueryInterface should set *out to NULL on failure, as it seems to do in many different places.
This seems to be a regression from !888.
One old game started to crash on startup with this merge request.
I bisected it and it pointed to the commit 131ada052a2dbec66df695ce536ca048a2bd9174.
--
v4: wmvcore/tests: check out value for NULL in check_interface
https://gitlab.winehq.org/wine/wine/-/merge_requests/2130