@@ -65,7 +65,7 @@ CAMLnoreturn_start
6565static void caml_win32_sys_error (int errnum )
6666CAMLnoreturn_end ;
6767
68- static void caml_win32_sys_error (int errnum )
68+ static value caml_win32_sys_error_exn (int errnum )
6969{
7070 wchar_t buffer [512 ];
7171 value msg ;
@@ -80,32 +80,43 @@ static void caml_win32_sys_error(int errnum)
8080 } else {
8181 msg = caml_alloc_sprintf ("unknown error #%d" , errnum );
8282 }
83- caml_raise_sys_error (msg );
83+ return caml_raise_sys_error_exn (msg );
8484}
8585
86- int caml_read_fd (int fd , int flags , void * buf , int n )
86+ static void caml_win32_sys_error (int errnum )
87+ {
88+ caml_raise_if_exception (caml_win32_sys_error_exn (errnum ));
89+ }
90+
91+ int caml_read_fd_exn (int fd , int flags , void * buf , int n , value * exn )
8792{
8893 int retcode ;
8994 if ((flags & CHANNEL_FLAG_FROM_SOCKET ) == 0 ) {
90- caml_enter_blocking_section ();
95+ * exn = caml_enter_blocking_section_exn ();
96+ if (Is_exception_result (* exn )) return -1 ;
9197 retcode = read (fd , buf , n );
9298 /* Large reads from console can fail with ENOMEM. Reduce requested size
9399 and try again. */
94100 if (retcode == -1 && errno == ENOMEM && n > 16384 ) {
95101 retcode = read (fd , buf , 16384 );
96102 }
97- caml_leave_blocking_section ();
98- if (retcode == -1 ) caml_sys_io_error (NO_ARG );
103+ * exn = caml_leave_blocking_section_exn ();
104+ if (Is_exception_result (* exn )) return retcode ;
105+ if (retcode == -1 )
106+ * exn = caml_sys_io_error_exn (NO_ARG );
99107 } else {
100- caml_enter_blocking_section ();
108+ * exn = caml_enter_blocking_section ();
109+ if (Is_exception_result (* exn )) return -1 ;
101110 retcode = recv ((SOCKET ) _get_osfhandle (fd ), buf , n , 0 );
102- caml_leave_blocking_section ();
103- if (retcode == -1 ) caml_win32_sys_error (WSAGetLastError ());
111+ * exn = caml_leave_blocking_section ();
112+ if (Is_exception_result (* exn )) return retcode ;
113+ if (retcode == -1 )
114+ * exn = caml_win32_sys_error_exn (WSAGetLastError ());
104115 }
105116 return retcode ;
106117}
107118
108- int caml_write_fd (int fd , int flags , void * buf , int n )
119+ int caml_write_fd_exn (int fd , int flags , void * buf , int n , value * exn )
109120{
110121 int retcode ;
111122 if ((flags & CHANNEL_FLAG_FROM_SOCKET ) == 0 ) {
@@ -114,20 +125,25 @@ int caml_write_fd(int fd, int flags, void * buf, int n)
114125 retcode = write (fd , buf , n );
115126 } else {
116127#endif
117- caml_enter_blocking_section ();
128+ * exn = caml_enter_blocking_section_exn ();
129+ if (Is_exception_result (* exn )) return 0 ;
118130 retcode = write (fd , buf , n );
119- caml_leave_blocking_section ();
131+ * exn = caml_leave_blocking_section_exn ();
132+ if (Is_exception_result (* exn )) return retcode ;
120133#if defined(NATIVE_CODE ) && defined(WITH_SPACETIME )
121134 }
122135#endif
123- if (retcode == -1 ) caml_sys_io_error (NO_ARG );
136+ if (retcode == -1 )
137+ * exn = caml_sys_io_error_exn (NO_ARG );
124138 } else {
125- caml_enter_blocking_section ();
139+ * exn = caml_enter_blocking_section_exn ();
140+ if (Is_exception_result (* exn )) return 0 ;
126141 retcode = send ((SOCKET ) _get_osfhandle (fd ), buf , n , 0 );
127- caml_leave_blocking_section ();
128- if (retcode == -1 ) caml_win32_sys_error (WSAGetLastError ());
142+ * exn = caml_leave_blocking_section_exn ();
143+ if (Is_exception_result (* exn )) return retcode ;
144+ if (retcode == -1 )
145+ * exn = caml_win32_sys_error_exn (WSAGetLastError ());
129146 }
130- CAMLassert (retcode > 0 );
131147 return retcode ;
132148}
133149
0 commit comments