@@ -299,62 +299,74 @@ timeval_to_time_us(struct timeval tv)
299299}
300300
301301int
302- getsockopt (int sockfd , int level , int optname , void * __restrict optval ,
303- socklen_t * __restrict optlen )
302+ get_sol_socket_option (int sockfd , int optname , void * __restrict optval ,
303+ socklen_t * __restrict optlen )
304304{
305305 __wasi_errno_t error ;
306306 uint64_t timeout_us ;
307307
308+ switch (optname ) {
309+ case SO_RCVTIMEO :
310+ assert (* optlen == sizeof (struct timeval ));
311+ error = __wasi_sock_get_recv_timeout (sockfd , & timeout_us );
312+ HANDLE_ERROR (error );
313+ * (struct timeval * )optval = time_us_to_timeval (timeout_us );
314+ return error ;
315+ case SO_SNDTIMEO :
316+ assert (* optlen == sizeof (struct timeval ));
317+ error = __wasi_sock_get_send_timeout (sockfd , & timeout_us );
318+ HANDLE_ERROR (error );
319+ * (struct timeval * )optval = time_us_to_timeval (timeout_us );
320+ return error ;
321+ }
322+
323+ HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
324+ }
325+
326+ int
327+ getsockopt (int sockfd , int level , int optname , void * __restrict optval ,
328+ socklen_t * __restrict optlen )
329+ {
308330 switch (level ) {
309331 case SOL_SOCKET :
310- switch (optname ) {
311- case SO_RCVTIMEO :
312- assert (* optlen == sizeof (struct timeval ));
313- error = __wasi_sock_get_recv_timeout (sockfd , & timeout_us );
314- HANDLE_ERROR (error );
315- * (struct timeval * )optval = time_us_to_timeval (timeout_us );
316- return error ;
317- break ;
318- case SO_SNDTIMEO :
319- assert (* optlen == sizeof (struct timeval ));
320- error = __wasi_sock_get_send_timeout (sockfd , & timeout_us );
321- HANDLE_ERROR (error );
322- * (struct timeval * )optval = time_us_to_timeval (timeout_us );
323- return error ;
324- break ;
325- }
326- break ;
332+ return get_sol_socket_option (sockfd , optname , optval , optlen );
327333 }
328334
329335 HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
330336}
331337
332338int
333- setsockopt (int sockfd , int level , int optname , const void * optval ,
334- socklen_t optlen )
339+ set_sol_socket_option (int sockfd , int optname , const void * optval ,
340+ socklen_t optlen )
335341{
336342 __wasi_errno_t error ;
337343 uint64_t timeout_us ;
338344
345+ switch (optname ) {
346+ case SO_RCVTIMEO :
347+ assert (optlen == sizeof (struct timeval ));
348+ timeout_us = timeval_to_time_us (* (struct timeval * )optval );
349+ error = __wasi_sock_set_recv_timeout (sockfd , timeout_us );
350+ HANDLE_ERROR (error );
351+ return error ;
352+ case SO_SNDTIMEO :
353+ assert (optlen == sizeof (struct timeval ));
354+ timeout_us = timeval_to_time_us (* (struct timeval * )optval );
355+ error = __wasi_sock_set_send_timeout (sockfd , timeout_us );
356+ HANDLE_ERROR (error );
357+ return error ;
358+ }
359+
360+ HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
361+ }
362+
363+ int
364+ setsockopt (int sockfd , int level , int optname , const void * optval ,
365+ socklen_t optlen )
366+ {
339367 switch (level ) {
340368 case SOL_SOCKET :
341- switch (optname ) {
342- case SO_RCVTIMEO :
343- assert (optlen == sizeof (struct timeval ));
344- timeout_us = timeval_to_time_us (* (struct timeval * )optval );
345- error = __wasi_sock_set_recv_timeout (sockfd , timeout_us );
346- HANDLE_ERROR (error );
347- return error ;
348- break ;
349- case SO_SNDTIMEO :
350- assert (optlen == sizeof (struct timeval ));
351- timeout_us = timeval_to_time_us (* (struct timeval * )optval );
352- error = __wasi_sock_set_send_timeout (sockfd , timeout_us );
353- HANDLE_ERROR (error );
354- return error ;
355- break ;
356- }
357- break ;
369+ return set_sol_socket_option (sockfd , optname , optval , optlen );
358370 }
359371
360372 HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
0 commit comments