This weekend I've been hacking on socket- and exception- related code:
Here come some patches, I'd like to be introduced in mono (only verified on
RedHat Linux 7.2)
1. Fixed an error where TcpClient returned from
TcpListener::AcceptTcpClient() would return null from GetStream() instead of
correct NetworkStream object.
[patch1.txt]
2. Improved Win32Exception error messages a bit by scanning through source
code looking for WSASetLastError() and adding errors along with their
descriptions to Win32Exception.cs file
[patch2.txt]
3. Attempted to fix a problem where send() to a closed socket resulted in a
signal being raised. Fixed this by including MSG_NOSIGNAL flag in a call to
send(). Also fixed some diagnostics in bind() call.
[patch3.txt]
4. Attempted to fix a problem with assert() being called when an exception
was thrown in a thread (JIT-only). exc_cleanup_id TLS Entry needs to be
filled for newly created threads. I added init_tls() function that is no-op
in MINT code and sets up the required TLS entry in JIT mode.
[patch4.txt]
Hope it helps someone,
Regards,
Jarek
Index: sockets.c
===================================================================
RCS file: /mono/mono/mono/io-layer/sockets.c,v
retrieving revision 1.7
diff -r1.7 sockets.c
304a305,309
>
> case EADDRINUSE:
> WSASetLastError(WSAEADDRINUSE);
> break;
>
611a617,619
> #ifdef MSG_NOSIGNAL
> ret=send(socket_handle->fd, msg, len, send_flags | MSG_NOSIGNAL);
> #else
612a621,622
> #endif
>
Index: TcpClient.cs
===================================================================
RCS file: /mono/mcs/class/System/System.Net.Sockets/TcpClient.cs,v
retrieving revision 1.3
diff -r1.3 TcpClient.cs
95c95
< set { client = value; } //TODO: should we be able to set the
socket like this?
---
> set { client = value; }
106c106,107
< Client = s; // client or Client? They are the same at the
moment
---
> client = s;
> stream = new NetworkStream(client, true);
Index: Win32Exception.cs
===================================================================
RCS file: /mono/mcs/class/System/System.ComponentModel/Win32Exception.cs,v
retrieving revision 1.3
diff -r1.3 Win32Exception.cs
74a75,125
> w32_errors.Add(10004,
> Locale.GetText("interrupted"));
>
> w32_errors.Add(10013,
> Locale.GetText("WSAEACCES"));
> w32_errors.Add(11002,
> Locale.GetText("WSATRY_AGAIN"));
> w32_errors.Add(10022,
> Locale.GetText("Invalid arguments"));
> w32_errors.Add(10014,
> Locale.GetText("WSAEFAULT"));
> w32_errors.Add(11003,
> Locale.GetText("WSANO_RECOVERY"));
> w32_errors.Add(11004,
> Locale.GetText("WSANO_DATA"));
> w32_errors.Add(10040,
> Locale.GetText("WSAEMSGSIZE"));
> w32_errors.Add(10024,
> Locale.GetText("WSAEMFILE"));
> w32_errors.Add(10042,
> Locale.GetText("WSAENOPROTOOPT"));
> w32_errors.Add(10050,
> Locale.GetText("Network subsystem is down"));
> w32_errors.Add(10051,
> Locale.GetText("WSAENETUNREACH"));
> w32_errors.Add(10035,
> Locale.GetText("WSAEWOULDBLOCK"));
> w32_errors.Add(10036,
> Locale.GetText("WSAEINPROGRESS"));
> w32_errors.Add(10060,
> Locale.GetText("WSAETIMEDOUT"));
> w32_errors.Add(10037,
> Locale.GetText("WSAEALREADY"));
> w32_errors.Add(10061,
> Locale.GetText("Connection refused"));
> w32_errors.Add(10045,
> Locale.GetText("WSAEOPNOTSUPP"));
> w32_errors.Add(10038,
> Locale.GetText("The descriptor is not a socket"));
> w32_errors.Add(10055,
> Locale.GetText("Not enough buffer space is available"));
> w32_errors.Add(10056,
> Locale.GetText("Socket is already connected"));
> w32_errors.Add(10048,
> Locale.GetText("Address already in use"));
> w32_errors.Add(10057,
> Locale.GetText("The socket is not connected"));
> w32_errors.Add(10058,
> Locale.GetText("The socket has been shut down"));
> w32_errors.Add(10093,
> Locale.GetText("Winsock not initialized"));
? metadata/new_threads.c
? metadata/patches.txt
Index: metadata/threads.c
===================================================================
RCS file: /mono/mono/mono/metadata/threads.c,v
retrieving revision 1.18
diff -r1.18 threads.c
79a80
> init_tls();
Index: metadata/threads.h
===================================================================
RCS file: /mono/mono/mono/metadata/threads.h,v
retrieving revision 1.13
diff -r1.13 threads.h
20a21
> extern void init_tls(void);
Index: jit/jit.c
===================================================================
RCS file: /mono/mono/mono/jit/jit.c,v
retrieving revision 1.155
diff -r1.155 jit.c
3688a3689,3701
> void thread_unhandled_exception_cleanup(MonoObject *exc)
> {
> /* fixme: anything more? */
>
> ExitThread(0);
> }
>
> void
> init_tls()
> {
> /* this function is called in the context of newly-created thread */
> TlsSetValue (exc_cleanup_id, thread_unhandled_exception_cleanup);
> }
Index: interpreter/interp.c
===================================================================
RCS file: /mono/mono/mono/interpreter/interp.c,v
retrieving revision 1.172
diff -r1.172 interp.c
3986a3987,3992
> void
> init_tls()
> {
> /* this function is called in the context of newly-created thread */
> }
>