@@ -487,62 +487,74 @@ timeval_to_time_us(struct timeval tv)
487487}
488488
489489int
490- getsockopt (int sockfd , int level , int optname , void * __restrict optval ,
491- socklen_t * __restrict optlen )
490+ get_sol_socket_option (int sockfd , int optname , void * __restrict optval ,
491+ socklen_t * __restrict optlen )
492492{
493493 __wasi_errno_t error ;
494494 uint64_t timeout_us ;
495495
496+ switch (optname ) {
497+ case SO_RCVTIMEO :
498+ assert (* optlen == sizeof (struct timeval ));
499+ error = __wasi_sock_get_recv_timeout (sockfd , & timeout_us );
500+ HANDLE_ERROR (error );
501+ * (struct timeval * )optval = time_us_to_timeval (timeout_us );
502+ return error ;
503+ case SO_SNDTIMEO :
504+ assert (* optlen == sizeof (struct timeval ));
505+ error = __wasi_sock_get_send_timeout (sockfd , & timeout_us );
506+ HANDLE_ERROR (error );
507+ * (struct timeval * )optval = time_us_to_timeval (timeout_us );
508+ return error ;
509+ }
510+
511+ HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
512+ }
513+
514+ int
515+ getsockopt (int sockfd , int level , int optname , void * __restrict optval ,
516+ socklen_t * __restrict optlen )
517+ {
496518 switch (level ) {
497519 case SOL_SOCKET :
498- switch (optname ) {
499- case SO_RCVTIMEO :
500- assert (* optlen == sizeof (struct timeval ));
501- error = __wasi_sock_get_recv_timeout (sockfd , & timeout_us );
502- HANDLE_ERROR (error );
503- * (struct timeval * )optval = time_us_to_timeval (timeout_us );
504- return error ;
505- break ;
506- case SO_SNDTIMEO :
507- assert (* optlen == sizeof (struct timeval ));
508- error = __wasi_sock_get_send_timeout (sockfd , & timeout_us );
509- HANDLE_ERROR (error );
510- * (struct timeval * )optval = time_us_to_timeval (timeout_us );
511- return error ;
512- break ;
513- }
514- break ;
520+ return get_sol_socket_option (sockfd , optname , optval , optlen );
515521 }
516522
517523 HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
518524}
519525
520526int
521- setsockopt (int sockfd , int level , int optname , const void * optval ,
522- socklen_t optlen )
527+ set_sol_socket_option (int sockfd , int optname , const void * optval ,
528+ socklen_t optlen )
523529{
524530 __wasi_errno_t error ;
525531 uint64_t timeout_us ;
526532
533+ switch (optname ) {
534+ case SO_RCVTIMEO :
535+ assert (optlen == sizeof (struct timeval ));
536+ timeout_us = timeval_to_time_us (* (struct timeval * )optval );
537+ error = __wasi_sock_set_recv_timeout (sockfd , timeout_us );
538+ HANDLE_ERROR (error );
539+ return error ;
540+ case SO_SNDTIMEO :
541+ assert (optlen == sizeof (struct timeval ));
542+ timeout_us = timeval_to_time_us (* (struct timeval * )optval );
543+ error = __wasi_sock_set_send_timeout (sockfd , timeout_us );
544+ HANDLE_ERROR (error );
545+ return error ;
546+ }
547+
548+ HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
549+ }
550+
551+ int
552+ setsockopt (int sockfd , int level , int optname , const void * optval ,
553+ socklen_t optlen )
554+ {
527555 switch (level ) {
528556 case SOL_SOCKET :
529- switch (optname ) {
530- case SO_RCVTIMEO :
531- assert (optlen == sizeof (struct timeval ));
532- timeout_us = timeval_to_time_us (* (struct timeval * )optval );
533- error = __wasi_sock_set_recv_timeout (sockfd , timeout_us );
534- HANDLE_ERROR (error );
535- return error ;
536- break ;
537- case SO_SNDTIMEO :
538- assert (optlen == sizeof (struct timeval ));
539- timeout_us = timeval_to_time_us (* (struct timeval * )optval );
540- error = __wasi_sock_set_send_timeout (sockfd , timeout_us );
541- HANDLE_ERROR (error );
542- return error ;
543- break ;
544- }
545- break ;
557+ return set_sol_socket_option (sockfd , optname , optval , optlen );
546558 }
547559
548560 HANDLE_ERROR (__WASI_ERRNO_NOTSUP );
0 commit comments